Puzzle#

class TileShape(value)#

Dynamic board cell property that depends on cell position in some tessellations. ie. in Trioban, origin of coordinate system is triangle pointing upwards. Shape of all other triangles depends on orientation of origin.

DEFAULT = 0#
OCTAGON = 2#
TRIANGLE_DOWN = 1#
class Puzzle(tessellation: Tessellation, width: int = 0, height: int = 0, board: Optional[str] = None)#

Base class for game puzzles.

Game puzzle is representation of game board together with all of its meta data and snapshots. It implements:

  • parsing board data from text

  • editing board: setting individual cells, resizing, trimming, …

All positions used are 1D array indexes.

To convert 2D board coordinates into 1D array indexes, use index_1d. To convert 1D array indexes into board 2D coordinates, use one of index_row, index_x index_column and index_y.

Parameters
  • width – number of columns

  • height – number of rows

  • board – If not blank, it will be parsed and board will be created from it, ignoring width and height.

WALL: Final[str] = '#'#
PUSHER: Final[str] = '@'#
PUSHER_ON_GOAL: Final[str] = '+'#
BOX: Final[str] = '$'#
BOX_ON_GOAL: Final[str] = '*'#
GOAL: Final[str] = '.'#
FLOOR: Final[str] = ' '#
VISIBLE_FLOOR: Final[str] = '-'#
__init__(tessellation: Tessellation, width: int = 0, height: int = 0, board: Optional[str] = None)#
property tessellation: Tessellation#
property has_sokoban_plus: bool#
tile_shape(pos: int) TileShape#
__getitem__(position: int) str#
__setitem__(position: int, c: str)#
__contains__(position: int)#
to_board_str(use_visible_floor=False, rle_encode=False) str#

Formatted output of parsed and validated board.

property board: str#

Original, unparsed board.

property internal_board: str#

Internal, parsed board. For debugging purposes.

property width: int#
property height: int#
property size: int#
property pushers_count: int#
property boxes_count: int#
property goals_count: int#
add_row_top()#
add_row_bottom()#
add_column_left()#
add_column_right()#
remove_row_top()#
remove_row_bottom()#
remove_column_left()#
remove_column_right()#
trim_left()#
trim_right()#
trim_top()#
trim_bottom()#
reverse_rows()#
reverse_columns()#
resize(new_width: int, new_height: int)#

In-place resizing of board.

Adds or removes rows and columns.

resize_and_center(new_width: int, new_height: int)#

In-place resizing of board.

Adds or removes rows and columns keeping existing board centered inside of new one.

trim()#

In-place resizing of board.

Removes outer, blank rows and columns.