Game¶
patiencepilot.game ¶
Session wrapper and convenience functions for Solitaire games.
SessionStep
dataclass
¶
One move applied within a game session.
Source code in src/patiencepilot/game.py
17 18 19 20 21 22 23 24 25 26 27 28 | |
GameSession
dataclass
¶
Thin mutable wrapper around pure engine state transitions.
Source code in src/patiencepilot/game.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
redo_history
property
¶
redo_history: tuple[SessionStep, ...]
Return undone session steps available for redo, oldest first.
result_history
property
¶
result_history: tuple[MoveResult, ...]
Return move results applied in this session.
__post_init__ ¶
__post_init__() -> None
Validate the starting state.
Source code in src/patiencepilot/game.py
43 44 45 | |
new
classmethod
¶
new(
variant: Variant | str | None = None,
*,
seed: Seed = None,
options: VariantOptions | None = None,
metadata: Mapping[str, object] | None = None,
ui_state: Mapping[str, object] | None = None,
) -> GameSession
Return a session around a newly dealt game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
Variant | str | None
|
Rule set or registered variant name to use. Defaults to Klondike draw-one with unlimited redeals. |
None
|
seed
|
Seed
|
Optional deterministic random seed. |
None
|
options
|
VariantOptions | None
|
Variant options when |
None
|
metadata
|
Mapping[str, object] | None
|
Optional session metadata for callers or persistence. |
None
|
ui_state
|
Mapping[str, object] | None
|
Optional UI-only state for adapters. |
None
|
Source code in src/patiencepilot/game.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
legal_moves ¶
legal_moves() -> tuple[Move, ...]
Return legal moves from the current state.
Source code in src/patiencepilot/game.py
113 114 115 | |
validate_state ¶
validate_state() -> None
Validate the current state.
Source code in src/patiencepilot/game.py
117 118 119 | |
is_won ¶
is_won() -> bool
Return whether the current state is won.
Source code in src/patiencepilot/game.py
121 122 123 | |
apply_move ¶
apply_move(move: Move) -> MoveResult
Apply move to the current state and record history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
move
|
Move
|
Move to apply. |
required |
Source code in src/patiencepilot/game.py
125 126 127 128 129 130 131 132 133 134 135 136 | |
undo ¶
undo() -> SessionStep
Undo the most recent move.
Raises:
| Type | Description |
|---|---|
InvalidMoveError
|
If there is no move to undo. |
Source code in src/patiencepilot/game.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
redo ¶
redo() -> MoveResult
Redo the most recently undone move.
Raises:
| Type | Description |
|---|---|
InvalidMoveError
|
If there is no move to redo. |
Source code in src/patiencepilot/game.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
clear_history ¶
clear_history() -> None
Clear undo and redo history without changing the current state.
Source code in src/patiencepilot/game.py
170 171 172 173 | |
apply_move ¶
apply_move(
state: GameState,
move: Move,
variant: Variant | str | None = None,
) -> MoveResult
Apply move to state and return the resulting state and effects.
Source code in src/patiencepilot/engine.py
45 46 47 | |
is_won ¶
is_won(
state: GameState, variant: Variant | str | None = None
) -> bool
Return whether state is won.
Source code in src/patiencepilot/engine.py
50 51 52 | |
legal_moves ¶
legal_moves(
state: GameState, variant: Variant | str | None = None
) -> tuple[Move, ...]
Return legal moves available from state.
Source code in src/patiencepilot/engine.py
40 41 42 | |
new_game ¶
new_game(
variant: Variant | str | None = None,
seed: Seed = None,
options: VariantOptions | None = None,
) -> GameState
Return a new game state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
Variant | str | None
|
Rule set or registered variant name to use. Defaults to Klondike draw-one with unlimited redeals. |
None
|
seed
|
Seed
|
Optional deterministic random seed. |
None
|
options
|
VariantOptions | None
|
Variant options when |
None
|
Source code in src/patiencepilot/engine.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
validate_state ¶
validate_state(
state: GameState, variant: Variant | str | None = None
) -> None
Validate that state is coherent for its variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State to validate. |
required |
variant
|
Variant | str | None
|
Optional explicit rule set or registered variant name. When omitted, rules are resolved from state metadata. |
None
|
Source code in src/patiencepilot/engine.py
29 30 31 32 33 34 35 36 37 | |
new_klondike_game ¶
new_klondike_game(
*,
seed: Seed = None,
draw_count: int = 1,
redeals: int | None = None,
) -> GameState
Return a new Klondike game state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Seed
|
Optional deterministic random seed. |
None
|
draw_count
|
int
|
Number of cards drawn from stock at once. |
1
|
redeals
|
int | None
|
Number of waste-to-stock redeals allowed, or |
None
|
Source code in src/patiencepilot/game.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |