Board

BoardGraph

class BoardGraph(puzzle: Puzzle)

Board graph.

Depending on how sokoenginepy was installed, it is using either NetworkX or Boost.Graph under the hood.

Raises

ValueError – when puzzle width is greater than Config.MAX_WIDTH or or puzzle height is greater than Config.MAX_HEIGHT

__init__(puzzle: Puzzle)
__getitem__(position: int) BoardCell
Raises

IndexErrorposition is off board

__setitem__(position: int, board_cell: Union[BoardCell, str])
Raises

IndexErrorposition is off board

__contains__(position: int) bool
property tessellation: Tessellation
cell_orientation(position: int) CellOrientation
to_board_str(use_visible_floor=False, rle_encode=False) str
property size: int
property edges_count: int
property board_width: int
property board_height: int
out_edges(src: int) List[Edge]

Edges inspector, for debugging purposes.

Raises

IndexErrorsrc is off board

neighbor(src: int, direction: Direction) int

Neighbor position in direction.

Returns

Target position or Config.NO_POS

Raises

IndexErrorsrc is off board

wall_neighbors(src: int) List[int]
Raises

IndexErrorsrc off board

wall_neighbor_directions(src: int) List[Direction]
all_neighbors(src: int) List[int]
Raises

IndexErrorsrc off board

shortest_path(src: int, dst: int) List[int]

Calculates shortest path between two positions with all positions having equal weight.

Raises

IndexErrorsrc or dst 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

IndexErrorsrc or dst off board

find_jump_path(src: int, dst: int) List[int]

Finds list of positions through which pusher must pass when jumping

Raises

IndexErrorsrc or dst 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

IndexErrorsrc or dst 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 in excluded_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 in excluded_positions is off board; it simply ignores those

path_destination(src: int, directions: List[Direction]) int

Given movement path directions, calculates position at the end of tha movement.

If any direction in directions would’ve lead off board, stops the search and returns position reached up to that point.

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()
to_str(use_visible_floor: bool = False) str
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_box: bool
property has_goal: bool
property has_piece: bool

True if there is pusher, box or goal on this cell.

property has_pusher
property is_border_element: bool

True if this is either a wall or box on goal.

property is_empty_floor: bool

True if there is no pieces and no wall on this cell.

is_in_playable_area: bool
property is_wall: bool

Edge

class Edge(u: int, v: int, direction: Direction)

BoardGraph edge.

direction: Direction
u: int
v: int