Exemplo n.º 1
0
 def is_connection_from(self, from_position: TilePosition, direction):
     to_position = from_position.get_position_in_direction(direction)
     from_tile, to_tile = self.get_tile_at(from_position), self.get_tile_at(
         to_position)
     return from_tile.is_accessible_from(direction) \
         and to_tile is not None \
         and to_tile.is_accessible_from(opposite(direction))
Exemplo n.º 2
0
 def from_config(filename, tile_repo: TileRepo):
     with open(filename) as config:
         config = json.load(config)
         board_config = config["board"]
     tile_dictionary = dict()
     for tile_config in board_config:
         pos = TilePosition(*tile_config[0:2])
         tile_id = TileID(*tile_config[2:4])
         spot_list = tile_repo.get_tile(tile_id).get_spot_list()
         tile_dictionary[tuple(pos)] = RotatedTile(tile_id, spot_list,
                                                   tile_config[4])
     return Board(tile_dictionary)
Exemplo n.º 3
0
 def get_accessible_position_tree(cls,
                                  board,
                                  root: TilePosition,
                                  max_depth: int = MAX_DEPTH,
                                  depth: int = 0,
                                  parent=None):
     if depth == max_depth:
         return cls(root, parent, dict())
     tree_by_direction = dict()
     for direction in DIRECTIONS:
         to_pos = root.get_position_in_direction(direction)
         if to_pos != parent and board.is_connection_from(root, direction):
             child_node = cls.get_accessible_position_tree(
                 board, to_pos, max_depth, depth + 1, root)
             tree_by_direction[direction] = child_node
     return cls(root, None, tree_by_direction)
Exemplo n.º 4
0
from board.tile_position import TilePosition
from spots.spot_positions import SpotPositionFactory
from players.piece_position import PiecePosition

__stp = TilePosition(1, 1)
__ssp = SpotPositionFactory.get_by_id(0)
STARTING_POSITION = PiecePosition(__stp, __ssp)


class Piece:
    def __init__(self,
                 piece_colour,
                 position: PiecePosition = STARTING_POSITION):
        self.__piece_colour = piece_colour
        self.__piece_position = position

    def get_piece_colour(self):
        return self.__piece_colour

    def __str__(self):
        return self.__piece_colour

    def get_piece_position(self):
        return self.__piece_position

    def move(self, new_position: PiecePosition):
        self.__piece_position = new_position

    def marshal(self):
        return {
            "colour": self.__piece_colour,
Exemplo n.º 5
0
 def unmarshal(cls, move_dict):
     return cls(TilePosition.unmarshal(move_dict["from"]),
                TilePosition.unmarshal(move_dict["to"]),
                move_dict["rotation"])
Exemplo n.º 6
0
 def get_tile(self, direction, pos: TilePosition) -> RotatedTile:
     pos = pos.get_position_in_direction(direction)
     return self.get_tile_at(pos)
Exemplo n.º 7
0
 def get_tile_positions(self):
     return [
         TilePosition.from_tuple(key)
         for key in self.__tile_dictionary.keys()
     ]
Exemplo n.º 8
0
 def unmarshal(cls, pos_dict):
     return cls(TilePosition.unmarshal(pos_dict["tile_position"]),
                SpotPositionFactory.get_by_id(pos_dict["spot_position"]))