Skip to content

Python Reference ​

Auto-generated from crates/dealbreaker-py/python/dealbreaker/__init__.py and _dealbreaker.pyi.

sh
pip install dealbreaker

Module 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.

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.

FieldTypeRequired
idstryes
namestryes

PileRef ​

Reference to a single pile by group name and 0-based index.

FieldTypeRequired
groupstryes
indexintyes

MoveStep ​

FieldTypeRequired
typeLiteral['move']yes
fromPileRefyes
toPileRefyes
countintyes

DealStep ​

FieldTypeRequired
typeLiteral['deal']yes

RedealStep ​

FieldTypeRequired
typeLiteral['redeal']yes

RemoveStep ​

FieldTypeRequired
typeLiteral['remove']yes
pileslist[PileRef]yes

StateData ​

Serializable game position.

FieldTypeRequired
redeals_usedintno
base_rankintno
seedintno
auxlist[int]no
pilesdict[str, list[list[str]]]yes

SolveResult ​

Result returned by Solver.solve.

FieldTypeRequired
stepslist[Step]no
outcomeLiteral['solved', 'unsolvable', 'gave-up']yes
statesintyes

MaxResult ​

Result returned by Solver.best.

FieldTypeRequired
scoreintyes
provenboolyes
statesintyes
stepslist[Step]yes

HintResult ​

Result returned by Solver.hint.

FieldTypeRequired
scorefloatno
stepStepyes
winsintyes
samplesintyes

HintReport ​

Result returned by Solver.hints.

FieldTypeRequired
candidateslist[HintResult]yes
samplesintyes
solved_samplesintyes
unsolvable_samplesintyes
gave_up_samplesintyes

DealGrade ​

Result returned by Solver.grade.

FieldTypeRequired
difficultyDifficultyno
scorefloatno
playout_win_ratefloatno
playout_winsintno
playoutsintno
stepsintno
statusLiteral['solvable', 'unsolvable', 'unknown']yes
statesintyes

FoundDeal ​

Result returned by Solver.find_deal.

FieldTypeRequired
gradeDealGradeno
stepslist[Step]no
seedintyes
stateStateDatayes
attemptsintyes

AutoComplete ​

Result returned by Solver.autocomplete.

FieldTypeRequired
completes_gameboolyes
stepslist[Step]yes

FlippedCard ​

A card turned face-up as a consequence of a step.

FieldTypeRequired
pilePileRefyes
cardstryes

StepDetails ​

Rich player-visible details for a single step.

FieldTypeRequired
cardslist[str]no
ontostrno
flippedlist[FlippedCard]no
stepStepyes
textstryes

DescribeStepResult ​

Result returned by Solver.describe_step.

FieldTypeRequired
detailsStepDetailsyes
stateStateDatayes

LastWinnable ​

Result returned by Solver.last_winnable.

FieldTypeRequired
indexintno
undo_stepsintno
statesintyes

Dual-licensed under MIT or Apache-2.0.