patiencepilot¶
patiencepilot ¶
Public patiencepilot API.
PatiencePilotApp
dataclass
¶
Small application service for UI and adapter workflows.
Source code in src/patiencepilot/app.py
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 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
select_variant ¶
select_variant(
name: str, options: VariantOptions | None = None
) -> Variant
Select the variant used for newly created sessions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered variant name. |
required |
options
|
VariantOptions | None
|
Variant-specific option values. |
None
|
Source code in src/patiencepilot/app.py
72 73 74 75 76 77 78 79 80 81 82 | |
select_solver ¶
select_solver(name: str = 'dummy') -> AdviceProvider
Select the advice provider used for future advice requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered solver name or alias. |
'dummy'
|
Source code in src/patiencepilot/app.py
84 85 86 87 88 89 90 91 | |
new_session ¶
new_session(
*,
seed: Seed = None,
metadata: Mapping[str, object] | None = None,
ui_state: Mapping[str, object] | None = None,
) -> GameSession
Create, store, and return a new session for the selected variant.
Source code in src/patiencepilot/app.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
use_session ¶
use_session(session: GameSession) -> GameSession
Store an existing session and sync selected variant metadata.
Source code in src/patiencepilot/app.py
110 111 112 113 114 115 116 | |
validate ¶
validate(
state: GameState | None = None,
) -> ValidationReport
Validate a state or the active session state without raising.
Source code in src/patiencepilot/app.py
118 119 120 121 122 123 124 125 126 127 | |
apply_move ¶
apply_move(move: Move) -> MoveResult
Apply move to the active session.
Source code in src/patiencepilot/app.py
129 130 131 | |
undo ¶
undo() -> GameSession
Undo the active session's most recent move and return the session.
Source code in src/patiencepilot/app.py
133 134 135 136 137 | |
redo ¶
redo() -> MoveResult
Redo the active session's most recently undone move.
Source code in src/patiencepilot/app.py
139 140 141 | |
export_session ¶
export_session(
session: GameSession | None = None,
*,
seen_cards: Iterable[Card] | None = None,
) -> SerializedSession
Return a serialized payload for session or the active session.
Source code in src/patiencepilot/app.py
143 144 145 146 147 148 149 150 | |
import_session ¶
import_session(data: Mapping[str, object]) -> GameSession
Import, store, and return a session payload.
Source code in src/patiencepilot/app.py
152 153 154 155 156 | |
request_advice ¶
request_advice(
*,
provider: AdviceProvider | None = None,
limit: SearchLimit | None = None,
seen_cards: Iterable[Card] | None = None,
) -> Advice
Request advice for the active session from an advice provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
AdviceProvider | None
|
Optional provider to use for this request. When omitted,
the configured |
None
|
limit
|
SearchLimit | None
|
Optional solver search limits. |
None
|
seen_cards
|
Iterable[Card] | None
|
Optional cards known from earlier observation history. |
None
|
Source code in src/patiencepilot/app.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
SerializedSession ¶
Bases: TypedDict
JSON-compatible game-session payload.
Source code in src/patiencepilot/app.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
ValidationReport
dataclass
¶
Validation result suitable for UI display.
Source code in src/patiencepilot/app.py
53 54 55 56 57 58 59 60 | |
Card
dataclass
¶
A standard playing card.
Source code in src/patiencepilot/cards.py
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 | |
from_code
classmethod
¶
from_code(code: str) -> Card
Return the card represented by a compact code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
A rank code followed by a suit code, such as |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/patiencepilot/cards.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
__str__ ¶
__str__() -> str
Return the compact card code.
Source code in src/patiencepilot/cards.py
137 138 139 | |
Color ¶
Bases: Enum
A playing card color.
Source code in src/patiencepilot/cards.py
9 10 11 12 13 | |
Rank ¶
Bases: IntEnum
A playing card rank from ace through king.
Source code in src/patiencepilot/cards.py
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 | |
from_code
classmethod
¶
from_code(code: str) -> Rank
Return the rank represented by a compact code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
One of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/patiencepilot/cards.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
Suit ¶
Bases: Enum
A French-suited playing card suit.
Source code in src/patiencepilot/cards.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
from_code
classmethod
¶
from_code(code: str) -> Suit
Return the suit represented by a compact one-letter code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
One of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/patiencepilot/cards.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
InvalidMoveError ¶
Bases: PatiencePilotError
Raised when a move is not legal from the current state.
Source code in src/patiencepilot/exceptions.py
12 13 | |
InvalidStateError ¶
Bases: PatiencePilotError
Raised when a game state is malformed or inconsistent.
Source code in src/patiencepilot/exceptions.py
8 9 | |
NotationError ¶
Bases: PatiencePilotError
Raised when state notation cannot be parsed or serialized.
Source code in src/patiencepilot/exceptions.py
28 29 | |
PatiencePilotError ¶
Bases: Exception
Base class for patiencepilot errors.
Source code in src/patiencepilot/exceptions.py
4 5 | |
SolverLimitError ¶
Bases: PatiencePilotError
Raised when a solver cannot continue within configured limits.
Source code in src/patiencepilot/exceptions.py
24 25 | |
UnsupportedSolverError ¶
Bases: PatiencePilotError
Raised when a solver is not supported.
Source code in src/patiencepilot/exceptions.py
20 21 | |
UnsupportedVariantError ¶
Bases: PatiencePilotError
Raised when a Solitaire variant is not supported.
Source code in src/patiencepilot/exceptions.py
16 17 | |
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 | |
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 | |
DrawFromStock
dataclass
¶
Draw one or more cards from stock to waste.
Source code in src/patiencepilot/moves.py
40 41 42 | |
DrewStockCards
dataclass
¶
Effect describing cards drawn from stock to waste.
Source code in src/patiencepilot/moves.py
72 73 74 75 76 | |
MovedCards
dataclass
¶
Effect describing cards moved between locations.
Source code in src/patiencepilot/moves.py
55 56 57 58 59 60 61 | |
MoveResult
dataclass
¶
The result of applying a legal move.
Source code in src/patiencepilot/moves.py
89 90 91 92 93 94 95 | |
RecycledWaste
dataclass
¶
Effect describing waste cards recycled into stock.
Source code in src/patiencepilot/moves.py
79 80 81 82 83 | |
RecycleWaste
dataclass
¶
Recycle the waste pile into stock when the rules allow it.
Source code in src/patiencepilot/moves.py
45 46 47 | |
RevealedTableauCard
dataclass
¶
Effect describing a tableau card automatically revealed by the engine.
Source code in src/patiencepilot/moves.py
64 65 66 67 68 69 | |
TableauToFoundation
dataclass
¶
Move the top visible card from a tableau column to its foundation.
Source code in src/patiencepilot/moves.py
21 22 23 24 25 | |
TableauToTableau
dataclass
¶
Move one or more visible cards between tableau columns.
Source code in src/patiencepilot/moves.py
12 13 14 15 16 17 18 | |
WasteToFoundation
dataclass
¶
Move the top waste card to its foundation.
Source code in src/patiencepilot/moves.py
35 36 37 | |
WasteToTableau
dataclass
¶
Move the top waste card to a tableau column.
Source code in src/patiencepilot/moves.py
28 29 30 31 32 | |
SerializedGameState ¶
Bases: TypedDict
JSON-compatible authoritative game-state payload.
Source code in src/patiencepilot/notation.py
47 48 49 50 51 52 53 54 55 56 57 | |
SerializedMove ¶
Bases: TypedDict
JSON-compatible serialized move payload.
Source code in src/patiencepilot/notation.py
33 34 35 36 37 | |
SerializedPlayerStackCard ¶
Bases: TypedDict
JSON-compatible player-view tableau card payload.
Source code in src/patiencepilot/notation.py
60 61 62 63 64 | |
SerializedPlayerView ¶
Bases: TypedDict
JSON-compatible player-known state payload.
Source code in src/patiencepilot/notation.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
SerializedStackCard ¶
Bases: TypedDict
JSON-compatible authoritative tableau card payload.
Source code in src/patiencepilot/notation.py
40 41 42 43 44 | |
SerializedUnknownCardConstraints ¶
Bases: TypedDict
JSON-compatible unknown-card constraint payload.
Source code in src/patiencepilot/notation.py
67 68 69 70 71 72 | |
ValidationDiagnostic
dataclass
¶
A validation diagnostic suitable for UI display.
Source code in src/patiencepilot/notation.py
89 90 91 92 93 94 95 | |
ValidationResult
dataclass
¶
Structured validation result for notation and payload checks.
Source code in src/patiencepilot/notation.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Advice
dataclass
¶
Solver advice containing zero or more ranked move alternatives.
Source code in src/patiencepilot/solvers/base.py
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 | |
alternatives
property
¶
alternatives: tuple[RankedMove, ...]
Return recommendations after the best move.
__post_init__ ¶
__post_init__() -> None
Sort and validate advice metadata.
Source code in src/patiencepilot/solvers/base.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
from_move
classmethod
¶
from_move(
move: Move,
*,
solver_name: str | None = None,
limit: SearchLimit | None = None,
score: float | None = None,
confidence: float | None = None,
reason: str | None = None,
) -> Advice
Return advice with a single recommended move.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
move
|
Move
|
Recommended move. |
required |
solver_name
|
str | None
|
Optional solver identifier. |
None
|
limit
|
SearchLimit | None
|
Optional search limits used for the recommendation. |
None
|
score
|
float | None
|
Optional solver-specific move score. |
None
|
confidence
|
float | None
|
Optional confidence from 0 to 1. |
None
|
reason
|
str | None
|
Optional human-readable reason. |
None
|
Source code in src/patiencepilot/solvers/base.py
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 | |
AdviceProvider ¶
Bases: Protocol
Protocol for components that produce advice from player-known state.
Source code in src/patiencepilot/solvers/base.py
128 129 130 131 132 133 | |
suggest ¶
suggest(
view: PlayerView, *, limit: SearchLimit | None = None
) -> Advice
Return move advice using only the supplied player-known view.
Source code in src/patiencepilot/solvers/base.py
131 132 133 | |
DummySolver
dataclass
¶
Deterministic solver that recommends the first visible legal move.
Source code in src/patiencepilot/solvers/dummy.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
suggest ¶
suggest(
view: PlayerView, *, limit: SearchLimit | None = None
) -> Advice
Return the first legal move available in view.
The solver derives legal moves only from player-visible information: foundations, waste, visible tableau cards, stock count, and redeal metadata. It does not reconstruct or inspect hidden card identities.
Source code in src/patiencepilot/solvers/dummy.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
RankedMove
dataclass
¶
One ranked solver move recommendation.
Source code in src/patiencepilot/solvers/base.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__post_init__ ¶
__post_init__() -> None
Validate ranked-move metadata.
Source code in src/patiencepilot/solvers/base.py
45 46 47 48 49 50 51 52 | |
SearchLimit
dataclass
¶
Optional limits for bounded solver work.
Source code in src/patiencepilot/solvers/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
__post_init__ ¶
__post_init__() -> None
Validate search-limit values.
Source code in src/patiencepilot/solvers/base.py
21 22 23 24 25 26 27 28 29 30 31 | |
Solver ¶
Bases: AdviceProvider, Protocol
Protocol for pluggable Solitaire solvers.
Source code in src/patiencepilot/solvers/base.py
136 137 138 139 | |
SolverDefinition
dataclass
¶
Registered solver metadata and factory.
Source code in src/patiencepilot/solvers/registry.py
21 22 23 24 25 26 27 28 29 30 31 32 | |
create ¶
create() -> AdviceProvider
Return a new advice provider instance.
Source code in src/patiencepilot/solvers/registry.py
30 31 32 | |
SolverFactory ¶
Bases: Protocol
Callable that creates an advice provider.
Source code in src/patiencepilot/solvers/registry.py
13 14 15 16 17 18 | |
__call__ ¶
__call__() -> AdviceProvider
Return an advice provider instance.
Source code in src/patiencepilot/solvers/registry.py
16 17 18 | |
SolverRegistry
dataclass
¶
Small immutable registry of supported solvers.
Source code in src/patiencepilot/solvers/registry.py
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 | |
__post_init__ ¶
__post_init__() -> None
Validate registry keys.
Source code in src/patiencepilot/solvers/registry.py
41 42 43 44 45 46 47 48 49 50 | |
register ¶
register(definition: SolverDefinition) -> SolverRegistry
Return a new registry that also contains definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
SolverDefinition
|
Solver definition to add. |
required |
Source code in src/patiencepilot/solvers/registry.py
57 58 59 60 61 62 63 | |
definition_for ¶
definition_for(name: str) -> SolverDefinition
Return the registered definition for name or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Solver name or alias. |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedSolverError
|
If no solver is registered for |
Source code in src/patiencepilot/solvers/registry.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
create ¶
create(name: str) -> AdviceProvider
Return a new advice provider by solver name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Solver name or alias. |
required |
Source code in src/patiencepilot/solvers/registry.py
84 85 86 87 88 89 90 | |
GameState
dataclass
¶
A complete immutable Solitaire game snapshot.
Source code in src/patiencepilot/state.py
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 | |
empty
classmethod
¶
empty(
*,
variant: str = "klondike",
draw_count: int = 1,
redeals_allowed: int | None = None,
) -> GameState
Return an empty state for constructing focused tests or fixtures.
Source code in src/patiencepilot/state.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
foundation ¶
foundation(suit: Suit) -> tuple[Card, ...]
Return the foundation stack for suit.
Source code in src/patiencepilot/state.py
80 81 82 | |
iter_known_cards ¶
iter_known_cards() -> Iterator[Card]
Yield every exact card identity present in the state.
Source code in src/patiencepilot/state.py
91 92 93 94 95 96 97 98 99 | |
StackCard
dataclass
¶
A card in a tableau stack with visibility metadata.
Source code in src/patiencepilot/state.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
visible_card
property
¶
visible_card: Card | None
Return the card when it is both known and face up.
visible
classmethod
¶
visible(card: Card) -> StackCard
Return a face-up tableau card.
Source code in src/patiencepilot/state.py
21 22 23 24 | |
hidden
classmethod
¶
hidden(card: Card) -> StackCard
Return a face-down tableau card.
Source code in src/patiencepilot/state.py
26 27 28 29 | |
KlondikeRules
dataclass
¶
Rules and options for Klondike Solitaire.
Source code in src/patiencepilot/variants/klondike.py
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
__post_init__ ¶
__post_init__() -> None
Validate immutable rule options.
Source code in src/patiencepilot/variants/klondike.py
41 42 43 44 45 46 47 48 | |
new_game ¶
new_game(seed: Seed = None) -> GameState
Return a new shuffled Klondike game state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Seed
|
Optional deterministic random seed. |
None
|
Source code in src/patiencepilot/variants/klondike.py
50 51 52 53 54 55 56 57 58 59 | |
deal ¶
deal(deck: Sequence[Card]) -> GameState
Deal deck into a Klondike starting state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deck
|
Sequence[Card]
|
A complete 52-card deck. The end of the sequence is treated as the top of the deck. |
required |
Raises:
| Type | Description |
|---|---|
InvalidStateError
|
If |
Source code in src/patiencepilot/variants/klondike.py
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 | |
validate_state ¶
validate_state(state: GameState) -> None
Validate that state is coherent for Klondike.
Raises:
| Type | Description |
|---|---|
InvalidStateError
|
If the state is malformed. |
UnsupportedVariantError
|
If the state belongs to another variant. |
Source code in src/patiencepilot/variants/klondike.py
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 | |
legal_moves ¶
legal_moves(state: GameState) -> tuple[Move, ...]
Return legal Klondike moves available from state.
Source code in src/patiencepilot/variants/klondike.py
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 | |
apply_move ¶
apply_move(state: GameState, move: Move) -> MoveResult
Apply a legal Klondike move and return the result.
Raises:
| Type | Description |
|---|---|
InvalidMoveError
|
If |
InvalidStateError
|
If |
Source code in src/patiencepilot/variants/klondike.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
is_won ¶
is_won(state: GameState) -> bool
Return whether all cards have been moved to the foundations.
Source code in src/patiencepilot/variants/klondike.py
203 204 205 206 | |
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 | |
new_game ¶
new_game(seed: Seed = None) -> GameState
Return a new game state.
Source code in src/patiencepilot/variants/base.py
18 19 20 | |
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 | |
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 | |
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 | |
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 | |
VariantDefinition
dataclass
¶
Registered Solitaire variant plus its option conversion functions.
Source code in src/patiencepilot/variants/registry.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
resolve ¶
resolve(options: VariantOptions | None = None) -> Variant
Return a rules object for this variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
Source code in src/patiencepilot/variants/registry.py
42 43 44 45 46 47 48 | |
VariantRegistry
dataclass
¶
Small immutable registry of supported Solitaire variants.
Source code in src/patiencepilot/variants/registry.py
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 | |
__post_init__ ¶
__post_init__() -> None
Validate registry keys.
Source code in src/patiencepilot/variants/registry.py
57 58 59 60 61 62 63 64 65 66 | |
register ¶
register(definition: VariantDefinition) -> VariantRegistry
Return a new registry that also contains definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
VariantDefinition
|
Variant definition to add. |
required |
Source code in src/patiencepilot/variants/registry.py
73 74 75 76 77 78 79 | |
definition_for ¶
definition_for(name: str) -> VariantDefinition
Return the registered definition for name or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedVariantError
|
If no variant is registered for |
Source code in src/patiencepilot/variants/registry.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
resolve ¶
resolve(
name: str, options: VariantOptions | None = None
) -> Variant
Return a rules object by variant name and options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. |
required |
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
Source code in src/patiencepilot/variants/registry.py
100 101 102 103 104 105 106 107 | |
options_from_state ¶
options_from_state(state: GameState) -> dict[str, object]
Return registry options that reproduce state rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State whose variant metadata should be converted. |
required |
Source code in src/patiencepilot/variants/registry.py
109 110 111 112 113 114 115 | |
resolve_state ¶
resolve_state(state: GameState) -> Variant
Return rules for the variant metadata stored in state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
Source code in src/patiencepilot/variants/registry.py
117 118 119 120 121 122 123 | |
PlayerStackCard
dataclass
¶
A tableau card as known to a player.
Source code in src/patiencepilot/view.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 37 38 39 40 41 42 | |
__post_init__ ¶
__post_init__() -> None
Validate player-view visibility invariants.
Source code in src/patiencepilot/view.py
20 21 22 23 24 25 26 27 | |
visible
classmethod
¶
visible(card: Card) -> PlayerStackCard
Return a face-up player-visible tableau card.
Source code in src/patiencepilot/view.py
29 30 31 32 | |
hidden
classmethod
¶
hidden() -> PlayerStackCard
Return a face-down player-hidden tableau card.
Source code in src/patiencepilot/view.py
34 35 36 37 | |
PlayerView
dataclass
¶
A state projection containing only what a perfect human player may know.
Source code in src/patiencepilot/view.py
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 | |
from_state
classmethod
¶
from_state(
state: GameState, *, seen_cards: Iterable[Card] = ()
) -> PlayerView
Project an authoritative game state into a player-known view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
Authoritative state to project. |
required |
seen_cards
|
Iterable[Card]
|
Cards observed earlier in the game, even if they are no longer visible. |
()
|
Source code in src/patiencepilot/view.py
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 | |
foundation ¶
foundation(suit: Suit) -> tuple[Card, ...]
Return the visible foundation stack for suit.
Source code in src/patiencepilot/view.py
128 129 130 | |
iter_visible_cards ¶
iter_visible_cards() -> Iterator[Card]
Yield cards currently visible to the player.
Source code in src/patiencepilot/view.py
137 138 139 | |
UnknownCardConstraints
dataclass
¶
Constraints for cards not currently identified in the player view.
Source code in src/patiencepilot/view.py
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 | |
hidden_tableau_count
property
¶
hidden_tableau_count: int
Return the total number of face-down tableau cards.
hidden_position_count
property
¶
hidden_position_count: int
Return the number of hidden positions in stock and tableau.
__post_init__ ¶
__post_init__() -> None
Validate unknown-card constraint counts.
Source code in src/patiencepilot/view.py
53 54 55 56 57 58 59 60 61 62 63 | |
export_session ¶
export_session(
session: GameSession,
*,
seen_cards: Iterable[Card] | None = None,
) -> SerializedSession
Return a JSON-compatible session payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
GameSession
|
Session to export. |
required |
seen_cards
|
Iterable[Card] | None
|
Cards known to the player from earlier observation history.
When omitted, |
None
|
Source code in src/patiencepilot/app.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
import_session ¶
import_session(data: Mapping[str, object]) -> GameSession
Return a session from a serialized payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, object]
|
Session payload created by :func: |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the payload cannot be imported. |
Source code in src/patiencepilot/app.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
migrate_session_payload ¶
migrate_session_payload(
data: Mapping[str, object],
) -> dict[str, object]
Return a best-effort alpha migration to session schema version 1.
Source code in src/patiencepilot/app.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
validate_session_payload ¶
validate_session_payload(
data: Mapping[str, object],
) -> ValidationReport
Validate a serialized session payload without raising.
Source code in src/patiencepilot/app.py
298 299 300 301 302 303 304 | |
validate_state_payload ¶
validate_state_payload(
data: Mapping[str, object],
) -> ValidationReport
Validate a serialized state payload without raising.
Source code in src/patiencepilot/app.py
307 308 309 310 311 312 313 314 315 316 317 318 | |
standard_deck ¶
standard_deck() -> tuple[Card, ...]
Return a standard 52-card deck in deterministic order.
Source code in src/patiencepilot/cards.py
142 143 144 | |
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 | |
deserialize_move ¶
deserialize_move(data: Mapping[str, object]) -> Move
Return a move from a JSON-compatible serialized payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, object]
|
Mapping with an |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the payload is missing or has an invalid |
Source code in src/patiencepilot/notation.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
deserialize_player_view ¶
deserialize_player_view(
data: Mapping[str, object],
) -> PlayerView
Return a player-known view from a JSON-compatible payload.
Source code in src/patiencepilot/notation.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
deserialize_state ¶
deserialize_state(data: Mapping[str, object]) -> GameState
Return a state from a JSON-compatible payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, object]
|
State payload created by :func: |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the payload cannot be parsed or validated. |
Source code in src/patiencepilot/notation.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
migrate_state_payload ¶
migrate_state_payload(
data: Mapping[str, object],
) -> dict[str, object]
Return a best-effort alpha migration to schema version 1.
Source code in src/patiencepilot/notation.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
move_from_id ¶
move_from_id(move_id: str) -> Move
Parse a canonical compact move identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
move_id
|
str
|
Identifier such as |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the identifier cannot be parsed. |
Source code in src/patiencepilot/notation.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
move_to_id ¶
move_to_id(move: Move) -> str
Return the canonical compact identifier for move.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
move
|
Move
|
Structured move to identify. |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the move contains invalid notation values. |
Source code in src/patiencepilot/notation.py
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 | |
serialize_move ¶
serialize_move(move: Move) -> SerializedMove
Return a JSON-compatible serialized move payload.
Source code in src/patiencepilot/notation.py
194 195 196 | |
serialize_player_view ¶
serialize_player_view(
view: PlayerView,
) -> SerializedPlayerView
Return a JSON-compatible player-known state payload.
Source code in src/patiencepilot/notation.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
serialize_state ¶
serialize_state(state: GameState) -> SerializedGameState
Return a JSON-compatible authoritative state payload.
Source code in src/patiencepilot/notation.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
state_from_text ¶
state_from_text(text: str) -> GameState
Return a state parsed from canonical text notation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
State notation produced by :func: |
required |
Raises:
| Type | Description |
|---|---|
NotationError
|
If the notation cannot be parsed or validated. |
Source code in src/patiencepilot/notation.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
state_to_text ¶
state_to_text(state: GameState) -> str
Return canonical text notation for an authoritative state.
Source code in src/patiencepilot/notation.py
219 220 221 222 223 224 225 226 227 228 229 230 231 | |
validate_move_id ¶
validate_move_id(move_id: str) -> ValidationResult
Validate a move identifier without raising.
Source code in src/patiencepilot/notation.py
386 387 388 389 390 391 392 | |
validate_serialized_move ¶
validate_serialized_move(
data: Mapping[str, object],
) -> ValidationResult
Validate a serialized move payload without raising.
Source code in src/patiencepilot/notation.py
395 396 397 398 399 400 401 | |
validate_serialized_state ¶
validate_serialized_state(
data: Mapping[str, object],
) -> ValidationResult
Validate a serialized state payload without raising.
Source code in src/patiencepilot/notation.py
404 405 406 407 408 409 410 | |
validate_state_text ¶
validate_state_text(text: str) -> ValidationResult
Validate state text notation without raising.
Source code in src/patiencepilot/notation.py
413 414 415 416 417 418 419 | |
resolve_solver ¶
resolve_solver(
name: str = "dummy",
*,
registry: SolverRegistry | None = None,
) -> AdviceProvider
Return an advice provider for a registered solver name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Solver name or alias. Defaults to |
'dummy'
|
registry
|
SolverRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/solvers/registry.py
93 94 95 96 97 98 99 100 | |
solver_names ¶
solver_names(
*, registry: SolverRegistry | None = None
) -> tuple[str, ...]
Return canonical names of registered solvers.
Source code in src/patiencepilot/solvers/registry.py
103 104 105 | |
visible_klondike_moves ¶
visible_klondike_moves(
view: PlayerView,
) -> tuple[Move, ...]
Return Klondike moves legal from player-visible state.
Source code in src/patiencepilot/solvers/dummy.py
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 | |
resolve_state_variant ¶
resolve_state_variant(
state: GameState,
*,
registry: VariantRegistry | None = None,
) -> Variant
Return rules for the variant metadata stored in state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
142 143 144 145 146 147 148 149 | |
resolve_variant ¶
resolve_variant(
name: str = KlondikeRules.name,
options: VariantOptions | None = None,
*,
registry: VariantRegistry | None = None,
) -> Variant
Return rules for a registered variant name and options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. Defaults to |
name
|
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
variant_names ¶
variant_names(
*, registry: VariantRegistry | None = None
) -> tuple[str, ...]
Return canonical names of registered variants.
Source code in src/patiencepilot/variants/registry.py
162 163 164 | |
variant_options_from_state ¶
variant_options_from_state(
state: GameState,
*,
registry: VariantRegistry | None = None,
) -> dict[str, object]
Return registry options that reproduce state rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
152 153 154 155 156 157 158 159 | |