Board¶
BoardGraph¶
- class BoardGraph(puzzle: Puzzle)¶
Board graph.
Depending on how
sokoenginepy
was installed, it is using eitherNetworkX
orBoost.Graph
under the hood.- Raises
ValueError – when
puzzle
width is greater thanConfig.MAX_WIDTH
or orpuzzle
height is greater thanConfig.MAX_HEIGHT
- __getitem__(position: int) BoardCell ¶
- Raises
IndexError –
position
is off board
- __setitem__(position: int, board_cell: Union[BoardCell, str])¶
- Raises
IndexError –
position
is off board
- property tessellation: Tessellation¶
- cell_orientation(position: int) CellOrientation ¶
- out_edges(src: int) List[Edge] ¶
Edges inspector, for debugging purposes.
- Raises
IndexError –
src
is off board
- neighbor(src: int, direction: Direction) int ¶
Neighbor position in
direction
.- Returns
Target position or Config.NO_POS
- Raises
IndexError –
src
is off board
- wall_neighbors(src: int) List[int] ¶
- Raises
IndexError –
src
off board
- all_neighbors(src: int) List[int] ¶
- Raises
IndexError –
src
off board
- shortest_path(src: int, dst: int) List[int] ¶
Calculates shortest path between two positions with all positions having equal weight.
- Raises
IndexError –
src
ordst
off board
- dijkstra_path(src: int, dst: int) List[int] ¶
Calculates shortest path between two positions not passing through board obstacles (walls, boxes, other pushers, etc…).
- Raises
IndexError –
src
ordst
off board
- find_jump_path(src: int, dst: int) List[int] ¶
Finds list of positions through which pusher must pass when jumping
- Raises
IndexError –
src
ordst
off board
- find_move_path(src: int, dst: int) List[int] ¶
Finds list of positions through which pusher must pass when moving without pushing boxes
- Raises
IndexError –
src
ordst
off board
- positions_path_to_directions_path(positions: List[int]) List[Direction] ¶
Converts path expressed as positions to one expressed as
Direction
.- Raises
IndexError – Any of positions in
positions
off board
- mark_play_area()¶
Sets flag on all
BoardCell
in graph that are playable: reachable by any box or any pusher.
- positions_reachable_by_pusher(pusher_position: int, excluded_positions: Optional[List[int]] = None) List[int] ¶
Finds all positions that are reachable by pusher standing on
pusher_position
.Doesn’t require that
pusher_position
actually has pusher.- Raises
IndexError – when
pusher_position
is off board. Doesn’t raise if any position inexcluded_positions
is off board; it simply ignores those
- normalized_pusher_position(pusher_position: int, excluded_positions: Optional[List[int]] = None) int ¶
Finds top-left position reachable by pusher without pushing any boxes.
Doesn’t require that
pusher_position
actually has pusher.- Raises
IndexError – when
pusher_position
is off board. Doesn’t raise if any position inexcluded_positions
is off board; it simply ignores those
GraphType¶
- class GraphType(value)¶
Types of
BoardGraph
.- DIRECTED = 0¶
Directed graphs
- DIRECTED_MULTI = 1¶
Directed graphs with self loops and parallel edges
BoardCell¶
- class BoardCell(character: str = ' ')¶
Stores properties of one cell in board layout.
Note
There is no game logic encoded in this class. It is perfectly fine to put pusher on wall cell (in which case wall will be replaced by pusher). This is by design:
BoardCell
is a value class, not game logic class.- clear()¶
Clears cell, converting it to empty floor.
- put_box()¶
- put_goal()¶
- put_pusher()¶
- remove_box()¶
- remove_goal()¶
- remove_pusher()¶
- property can_put_pusher_or_box: bool¶
True if this cell allows putting box or pusher on self.
Note
This method is not used by BoardCell modifiers (ie.
put_box
,put_pusher
, etc…). As far as BoardCell is concerned, nothing prevents clients from putting box on wall (which replaces that wall with box). This method is used by higher game logic that implement pusher movement in which case putting ie. pusher onto same cell where box is makes no sense.
- property has_pusher¶