Puzzles

SokobanPuzzle

class SokobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)

Bases: Puzzle

Puzzle implementation for Tessellation.SOKOBAN and SokobanTessellation.

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.

__init__(width: int = 0, height: int = 0, board: Optional[str] = None)

HexobanPuzzle

class HexobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)

Bases: Puzzle

Puzzle implementation for Tessellation.HEXOBAN and HexobanTessellation.

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.

__init__(width: int = 0, height: int = 0, board: Optional[str] = None)

TriobanPuzzle

class TriobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)

Bases: Puzzle

Puzzle implementation for Tessellation.TRIOBAN and TriobanTessellation.

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.

__init__(width: int = 0, height: int = 0, board: Optional[str] = None)

OctobanPuzzle

class OctobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)

Bases: Puzzle

Puzzle implementation for Tessellation.OCTOBAN and OctobanTessellation.

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.

__init__(width: int = 0, height: int = 0, board: Optional[str] = None)

CellOrientation

class CellOrientation(value)

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

DEFAULT = 0
OCTAGON = 2
TRIANGLE_DOWN = 1

Puzzle

class Puzzle(tessellation: Tessellation, width: int = 0, height: int = 0, board: Optional[str] = None, resizer_cls: Optional[Type[PuzzleResizer]] = None, parser_cls: Optional[Type[PuzzleParser]] = None, printer_cls: Optional[Type[PuzzlePrinter]] = 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.

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] = '-'
ALT_PUSHER1: Final[str] = 'p'
ALT_PUSHER2: Final[str] = 'm'
ALT_PUSHER_ON_GOAL1: Final[str] = 'P'
ALT_PUSHER_ON_GOAL2: Final[str] = 'M'
ALT_BOX1: Final[str] = 'b'
ALT_BOX_ON_GOAL1: Final[str] = 'B'
ALT_GOAL1: Final[str] = 'o'
ALT_VISIBLE_FLOOR1: Final[str] = '_'
classmethod is_pusher(character: str) bool
classmethod is_box(character: str) bool
classmethod is_goal(character: str) bool
classmethod is_empty_floor(character: str) bool
classmethod is_wall(character: str) bool
classmethod is_border_element(character: str) bool
classmethod is_puzzle_element(character: str) bool
classmethod is_board(line: Optional[str]) bool

Checks if line contains only characters legal in textual representation of boards.

Note

Doesn’t check if it actually contains legal board, it only checks that there are no illegal characters.

classmethod is_sokoban_plus(line: str) bool
classmethod instance_from(tessellation: Tessellation, width: int = 0, height: int = 0, board: Optional[str] = None) Puzzle

Factory method. Produces instance of one of the subclasses.

__init__(tessellation: Tessellation, width: int = 0, height: int = 0, board: Optional[str] = None, resizer_cls: Optional[Type[PuzzleResizer]] = None, parser_cls: Optional[Type[PuzzleParser]] = None, printer_cls: Optional[Type[PuzzlePrinter]] = None)
property tessellation: Tessellation
property has_sokoban_plus: bool
cell_orientation(pos: int) CellOrientation
__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.