Skip to content

Base

patiencepilot.variants.base

Shared interfaces for Solitaire variants.

Variant

Bases: Protocol

Protocol implemented by Solitaire rule sets.

Source code in src/patiencepilot/variants/base.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Variant(Protocol):
    """Protocol implemented by Solitaire rule sets."""

    name: ClassVar[str]

    def new_game(self, seed: Seed = None) -> GameState:
        """Return a new game state."""
        ...

    def validate_state(self, state: GameState) -> None:
        """Validate that ``state`` is coherent for this variant."""
        ...

    def legal_moves(self, state: GameState) -> tuple[Move, ...]:
        """Return legal moves available from ``state``."""
        ...

    def apply_move(self, state: GameState, move: Move) -> MoveResult:
        """Apply ``move`` and return the resulting state and effects."""
        ...

    def is_won(self, state: GameState) -> bool:
        """Return whether ``state`` is a winning state."""
        ...

new_game

new_game(seed: Seed = None) -> GameState

Return a new game state.

Source code in src/patiencepilot/variants/base.py
18
19
20
def new_game(self, seed: Seed = None) -> GameState:
    """Return a new game state."""
    ...

validate_state

validate_state(state: GameState) -> None

Validate that state is coherent for this variant.

Source code in src/patiencepilot/variants/base.py
22
23
24
def validate_state(self, state: GameState) -> None:
    """Validate that ``state`` is coherent for this variant."""
    ...

legal_moves

legal_moves(state: GameState) -> tuple[Move, ...]

Return legal moves available from state.

Source code in src/patiencepilot/variants/base.py
26
27
28
def legal_moves(self, state: GameState) -> tuple[Move, ...]:
    """Return legal moves available from ``state``."""
    ...

apply_move

apply_move(state: GameState, move: Move) -> MoveResult

Apply move and return the resulting state and effects.

Source code in src/patiencepilot/variants/base.py
30
31
32
def apply_move(self, state: GameState, move: Move) -> MoveResult:
    """Apply ``move`` and return the resulting state and effects."""
    ...

is_won

is_won(state: GameState) -> bool

Return whether state is a winning state.

Source code in src/patiencepilot/variants/base.py
34
35
36
def is_won(self, state: GameState) -> bool:
    """Return whether ``state`` is a winning state."""
    ...