Puzzles¶
SokobanPuzzle¶
- class SokobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)¶
Bases:
Puzzle
Puzzle
implementation forTessellation.SOKOBAN
andSokobanTessellation
.- 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
andheight
.
HexobanPuzzle¶
- class HexobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)¶
Bases:
Puzzle
Puzzle
implementation forTessellation.HEXOBAN
andHexobanTessellation
.- 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
andheight
.
TriobanPuzzle¶
- class TriobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)¶
Bases:
Puzzle
Puzzle
implementation forTessellation.TRIOBAN
andTriobanTessellation
.- 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
andheight
.
OctobanPuzzle¶
- class OctobanPuzzle(width: int = 0, height: int = 0, board: Optional[str] = None)¶
Bases:
Puzzle
Puzzle
implementation forTessellation.OCTOBAN
andOctobanTessellation
.- 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
andheight
.
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 ofindex_row
,index_x
index_column
andindex_y
.- 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 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¶
- cell_orientation(pos: int) CellOrientation ¶
- to_board_str(use_visible_floor=False, rle_encode=False) str ¶
Formatted output of parsed and validated board.
- 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.