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))
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)
def get_tile(self, direction, pos: TilePosition) -> RotatedTile: pos = pos.get_position_in_direction(direction) return self.get_tile_at(pos)