DataTree - the core Class

In the interoperable process between a game and players, information transits. Games send what players can perceive and players send action description in return.

That information is structured as DataTree to be serialized, transmitted and rebuilt. a DataTree includes contents (sequence of characters, intergers, floating points values) and cand be a part of a tree structure of information.

Implementation:

The example here is presented accordingly to the Python implementation (hackapy).

DataTree Components

DataTree is composed of 4 elements of almost fixed type:

  • label: a string descrition.
  • digits: a vector of integer values.
  • values: a vector of floating points values.
  • children: a vector of other DataTree elements, sub-part of the DataTree.

Accessor methods permit to get string elements as list : aDataTree.label() and list elements: aDataTree.digits(), aDataTree.values(), aDataTree.children(). It is also possible to get a specific element is the lists with: aDataTree.digit(anInteger), aDataTree.value(anInteger), aDataTree.child(anInteger). To notice that, in HackaGames conventions element in list are indexed starting from 1. The first element is accessed with index 1: (aDataTree.digit(1) for instance).

Tree Structure

Children componnents of a DataTree permits to defines complexe information structured as trees. For more information about tree data structure, Wikipedia is a good entrance point. Trees are very famous in Web technoligies for instance through formats: HTML, XML, Json, Yaml, ...

In HackaGames most of the game states perceived by players (one DataTree) are composed by several elements each one modeled by child DataTree. For instance, a Board would be composed with Cells and Cells would welcome Pieces. The pieces would be the childrens of a Cell, Cells the children of a Board etc.

Interface versus Inheritance

HackaGames conventions prefer a separation of game elements in the implementations from DataTree. A DataTree imposes specific structuration of elements (flags, values, ...). This structuration is not always efficient in the game mechanisms and not even readable in its implementations.

That for, we discourage developers from using inheritance of DataTree in game and player implementations and we propose interface mechanisms to generate DataTrees from the game elements and vice versa, when it is pertinent to do it. Game elements should include DataTree interface methods:

    # DataTree interface:
    def asDataTree(self):
        # Should return a DataTree describing self.
        # ...
        pass

    def fromDataTree(self, aDataTree):
        # Should regenerate self form a DataTree description
        # HackaGames conventions aim to return self at the end of the method.
        # ...
        pass