Game utilities

class core.game.Bug(color: PlayerColor, bug_type: BugType, bug_id: int = 0)[source]

Bases: object

Bug piece.

COLORS: Final[dict[str, PlayerColor]] = {'b': PlayerColor.BLACK, 'w': PlayerColor.WHITE}

Color code map.

REGEX: Final[str] = '(w|b)(Q|S|B|G|A|M|L|P)(1|2|3)?'

Regex to validate BugStrings.

classmethod parse(bug: str)[source]

Parses a BugString.

Parameters:

bug (str) – BugString.

Raises:

ValueError – If it’s not a valid BugString.

Returns:

Bug piece.

Return type:

Bug

class core.game.Move(bug: Bug, origin: Position | None, destination: Position)[source]

Bases: object

Move.

PASS: Final[str] = 'pass'

Pass move.

REGEX = '((w|b)(Q|S|B|G|A|M|L|P)(1|2|3)?)( ?(\\\\|\\-|\\/)?((w|b)(Q|S|B|G|A|M|L|P)(1|2|3)?)(\\-|\\/|\\\\)?)?'

MoveString regex.

classmethod stringify(moved: Bug, relative: Bug | None = None, direction: Direction | None = None) str[source]

Converts the data for a move to the corresponding MoveString.

Parameters:
  • moved (Bug) – Bug piece moved.

  • relative (Optional[Bug], optional) – Bug piece relative to which the other bug piece is moved, defaults to None.

  • direction (Optional[Direction], optional) – Direction of the destination tile with respect to the relative bug piece, defaults to None.

Returns:

MoveString.

Return type:

str

class core.game.Position(q: int, r: int)[source]

Bases: object

Tile position.

anticlockwise()[source]

Rotate the position 60 degrees anticlockwise.

Returns:

New rotated position.

Return type:

Position

clockwise()[source]

Rotate the position 60 degrees clockwise.

Returns:

New rotated position.

Return type:

Position