Python Reference
Auto-generated from
crates/dealbreaker-py/python/dealbreaker/__init__.pyand_dealbreaker.pyi.
pip install dealbreakerModule Functions
presets() -> list[PresetInfo]
Return all built-in game presets as [{"id": ..., "name": ...}, ...].
format_step(step: Step | Mapping[str, Any] | str) -> str
Format a step dict or JSON string as human-readable text (e.g. "tableau 4 -> cell 1").
class Solver
Compiled solitaire game rules. Create once and reuse across many deals.
Long-running searches (solve, best, hint) release the Python GIL so multiple threads can search concurrently, and respond to Ctrl-C (KeyboardInterrupt) in interactive sessions and notebooks.
__init__(rules: Mapping[str, Any] | str) -> None
@classmethod from_preset(preset_id: str) -> Solver
Create a solver from a built-in preset id (see presets()).
@classmethod from_preset_with(preset_id: str, patch: Mapping[str, Any] | str) -> Solver
Create a solver from a built-in preset with an RFC 7396 JSON Merge Patch applied.
rules() -> dict[str, Any]
Return this game's rules as a dictionary.
deal(seed: int = 1) -> StateData
Deal a seeded position.
deal_microsoft(n: int) -> StateData
Deal Microsoft FreeCell deal n (for FreeCell-layout games).
deal_ordered(cards: Sequence[str]) -> StateData
Deal from an explicit list of card strings (e.g. ["AS", "2S", ...]).
validate(state: StateData | Mapping[str, Any] | str) -> None
Validate a position against this game's pack and pile capacities.
solve(state: StateData | Mapping[str, Any] | str, *, max_states: int = 2000000, strategy: Literal['auto', 'depth_first', 'depth-first', 'dfs', 'best_first', 'best-first', 'bfs'] = 'auto', timeout_ms: int | None = None, autoplay: bool = True, shorten: bool = True, cancel: CancelToken | None = None) -> SolveResult
Search for a winning line or prove unsolvability. Releases the GIL.
best(state: StateData | Mapping[str, Any] | str, *, max_states: int = 2000000, strategy: Literal['auto', 'depth_first', 'depth-first', 'dfs', 'best_first', 'best-first', 'bfs'] = 'auto', timeout_ms: int | None = None, cancel: CancelToken | None = None) -> MaxResult
Find the highest-scoring line in a points game. Releases the GIL.
hint(state: StateData | Mapping[str, Any] | str, *, samples: int = 16, seed: int = 0, max_states: int = 100000, strategy: Literal['auto', 'depth_first', 'depth-first', 'dfs', 'best_first', 'best-first', 'bfs'] = 'auto', timeout_ms: int | None = None, autoplay: bool = True, shorten: bool = True, cancel: CancelToken | None = None) -> HintResult | None
Suggest a next step without peeking at face-down cards. Releases the GIL.
hints(state: StateData | Mapping[str, Any] | str, *, samples: int = 16, seed: int = 0, max_candidates: int = 3, max_states: int = 100000, strategy: Literal['auto', 'depth_first', 'depth-first', 'dfs', 'best_first', 'best-first', 'bfs'] = 'auto', timeout_ms: int | None = None, autoplay: bool = True, shorten: bool = True, cancel: CancelToken | None = None) -> HintReport
Suggest ranked next steps without peeking at face-down cards. Releases the GIL.
grade(state: StateData | Mapping[str, Any] | str, *, options: Mapping[str, Any] | str | None = None, cancel: CancelToken | None = None) -> DealGrade
Grade a single deal's solvability and difficulty. Releases the GIL.
find_deal(*, options: Mapping[str, Any] | str | None = None, cancel: CancelToken | None = None) -> FoundDeal | None
Search sequentially for a solvable (or difficulty-targeted) deal. Releases the GIL.
safe_steps(state: StateData | Mapping[str, Any] | str) -> list[Step]
Greedily collect provably safe forced moves without searching.
autocomplete(state: StateData | Mapping[str, Any] | str) -> AutoComplete
Detect whether state can be auto-completed trivially and return the steps to play.
describe_step(state: StateData | Mapping[str, Any] | str, step: Step | Mapping[str, Any] | str) -> DescribeStepResult
Play one step and return rich details (cards, onto, flipped, text) and the next state.
describe_steps(state: StateData | Mapping[str, Any] | str, steps: Sequence[Step | Mapping[str, Any]] | str) -> list[StepDetails]
Replay a sequence of steps and return rich details for each step.
last_winnable(state: StateData | Mapping[str, Any] | str, history: Sequence[Step | Mapping[str, Any]] | str, *, max_states: int = 2000000, strategy: Literal['auto', 'depth_first', 'depth-first', 'dfs', 'best_first', 'best-first', 'bfs'] = 'auto', timeout_ms: int | None = None, autoplay: bool = True, cancel: CancelToken | None = None) -> LastWinnable
Find the most recent winnable position along history played from state. Releases the GIL.
legal_steps(state: StateData | Mapping[str, Any] | str) -> list[Step]
Return every legal single step in state.
play_step(state: StateData | Mapping[str, Any] | str, step: Step | Mapping[str, Any] | str) -> StateData
Play one step and return the resulting position (raises ValueError if illegal).
is_won(state: StateData | Mapping[str, Any] | str) -> bool
Return whether state is a won position.
score(state: StateData | Mapping[str, Any] | str) -> int | None
Return points for state, or None for non-scored games.
render(state: StateData | Mapping[str, Any] | str) -> str
Render state as a human-readable ASCII board.
class CancelToken
Cooperative cancellation token shared with solve, best, or hint.
Safe to pass to a search running on one thread and trigger via cancel() from another.
__init__() -> None
cancel() -> None
Signal cancellation to any search using this token.
reset() -> None
Reset the token so it can be reused for another search.
@property is_cancelled -> bool
Whether cancellation has been triggered.
Data Types
Step
Type alias: MoveStep | DealStep | RedealStep | RemoveStep
PresetInfo
Metadata for a built-in game preset.
| Field | Type | Required |
|---|---|---|
id | str | yes |
name | str | yes |
PileRef
Reference to a single pile by group name and 0-based index.
| Field | Type | Required |
|---|---|---|
group | str | yes |
index | int | yes |
MoveStep
| Field | Type | Required |
|---|---|---|
type | Literal['move'] | yes |
from | PileRef | yes |
to | PileRef | yes |
count | int | yes |
DealStep
| Field | Type | Required |
|---|---|---|
type | Literal['deal'] | yes |
RedealStep
| Field | Type | Required |
|---|---|---|
type | Literal['redeal'] | yes |
RemoveStep
| Field | Type | Required |
|---|---|---|
type | Literal['remove'] | yes |
piles | list[PileRef] | yes |
StateData
Serializable game position.
| Field | Type | Required |
|---|---|---|
redeals_used | int | no |
base_rank | int | no |
seed | int | no |
aux | list[int] | no |
piles | dict[str, list[list[str]]] | yes |
SolveResult
Result returned by Solver.solve.
| Field | Type | Required |
|---|---|---|
steps | list[Step] | no |
outcome | Literal['solved', 'unsolvable', 'gave-up'] | yes |
states | int | yes |
MaxResult
Result returned by Solver.best.
| Field | Type | Required |
|---|---|---|
score | int | yes |
proven | bool | yes |
states | int | yes |
steps | list[Step] | yes |
HintResult
Result returned by Solver.hint.
| Field | Type | Required |
|---|---|---|
score | float | no |
step | Step | yes |
wins | int | yes |
samples | int | yes |
HintReport
Result returned by Solver.hints.
| Field | Type | Required |
|---|---|---|
candidates | list[HintResult] | yes |
samples | int | yes |
solved_samples | int | yes |
unsolvable_samples | int | yes |
gave_up_samples | int | yes |
DealGrade
Result returned by Solver.grade.
| Field | Type | Required |
|---|---|---|
difficulty | Difficulty | no |
score | float | no |
playout_win_rate | float | no |
playout_wins | int | no |
playouts | int | no |
steps | int | no |
status | Literal['solvable', 'unsolvable', 'unknown'] | yes |
states | int | yes |
FoundDeal
Result returned by Solver.find_deal.
| Field | Type | Required |
|---|---|---|
grade | DealGrade | no |
steps | list[Step] | no |
seed | int | yes |
state | StateData | yes |
attempts | int | yes |
AutoComplete
Result returned by Solver.autocomplete.
| Field | Type | Required |
|---|---|---|
completes_game | bool | yes |
steps | list[Step] | yes |
FlippedCard
A card turned face-up as a consequence of a step.
| Field | Type | Required |
|---|---|---|
pile | PileRef | yes |
card | str | yes |
StepDetails
Rich player-visible details for a single step.
| Field | Type | Required |
|---|---|---|
cards | list[str] | no |
onto | str | no |
flipped | list[FlippedCard] | no |
step | Step | yes |
text | str | yes |
DescribeStepResult
Result returned by Solver.describe_step.
| Field | Type | Required |
|---|---|---|
details | StepDetails | yes |
state | StateData | yes |
LastWinnable
Result returned by Solver.last_winnable.
| Field | Type | Required |
|---|---|---|
index | int | no |
undo_steps | int | no |
states | int | yes |