Skip to content

C ABI Reference ​

Auto-generated from crates/dealbreaker-ffi/include/dealbreaker.h.

Build the shared/static library with cargo build --release -p dealbreaker-ffi, or an Apple XCFramework with ./scripts/build-xcframework.sh.

Opaque Handles ​

  • typedef struct DealbreakerSolver DealbreakerSolver; — Opaque compiled game rules handle. Thread-safe for concurrent read/search calls. Must outlive all concurrent calls using this handle; do not call dealbreaker_solver_free until every in-flight call on other threads has returned.
  • typedef struct DealbreakerCancel DealbreakerCancel; — Opaque cooperative cancellation flag. Safe to trigger from another thread. Must outlive all concurrent searches using this flag; do not call dealbreaker_cancel_free until every search referencing it has returned.

Functions ​

dealbreaker_string_free ​

c
void dealbreaker_string_free(char *s);

Free a string returned by any dealbreaker_* function. Passing NULL is a no-op.

dealbreaker_last_error ​

c
const char *dealbreaker_last_error(void);

Return the last error message on the current thread, or NULL if none. The returned pointer is owned by Dealbreaker and valid until the next FFI call on this thread. Do NOT pass it to dealbreaker_string_free.

dealbreaker_cancel_new ​

c
DealbreakerCancel *dealbreaker_cancel_new(void);

Create a new cancellation flag (initially false). Free with dealbreaker_cancel_free.

dealbreaker_cancel_trigger ​

c
void dealbreaker_cancel_trigger(const DealbreakerCancel *cancel);

Signal cancellation to any search sharing this flag. Safe to call from any thread.

dealbreaker_cancel_free ​

c
void dealbreaker_cancel_free(DealbreakerCancel *cancel);

Free a cancellation flag. Passing NULL is a no-op.

dealbreaker_presets ​

c
char *dealbreaker_presets(void);

Return built-in presets as JSON: [{"id":"...","name":"..."}, ...]. Caller frees result.

dealbreaker_solver_new ​

c
DealbreakerSolver *dealbreaker_solver_new(const char *rules_json);

Compile a solver from rules JSON. Returns NULL on error (see dealbreaker_last_error).

dealbreaker_solver_from_preset ​

c
DealbreakerSolver *dealbreaker_solver_from_preset(const char *preset_id);

Compile a solver from a built-in preset id. Returns NULL on error.

dealbreaker_solver_from_preset_with ​

c
DealbreakerSolver *dealbreaker_solver_from_preset_with( const char *preset_id, const char *patch_json );

Compile a solver from a built-in preset id with an RFC 7396 JSON Merge Patch applied.

dealbreaker_solver_free ​

c
void dealbreaker_solver_free(DealbreakerSolver *solver);

Free a solver handle. Passing NULL is a no-op.

dealbreaker_solver_rules ​

c
char *dealbreaker_solver_rules(const DealbreakerSolver *solver);

Return this game's rules as JSON. Caller frees result.

dealbreaker_solver_deal ​

c
char *dealbreaker_solver_deal(const DealbreakerSolver *solver, uint64_t seed);

Deal a seeded position as JSON. Caller frees result.

dealbreaker_solver_deal_microsoft ​

c
char *dealbreaker_solver_deal_microsoft(const DealbreakerSolver *solver, uint32_t n);

Deal Microsoft FreeCell deal n as JSON. Returns NULL on error. Caller frees result.

dealbreaker_solver_deal_ordered ​

c
char *dealbreaker_solver_deal_ordered(const DealbreakerSolver *solver, const char *cards_json);

Deal an explicit card order from a JSON array of card strings. Returns NULL on error.

dealbreaker_solver_validate ​

c
int32_t dealbreaker_solver_validate(const DealbreakerSolver *solver, const char *state_json);

Validate a position JSON. Returns 0 if valid, -1 on error (see dealbreaker_last_error).

dealbreaker_solver_solve ​

c
char *dealbreaker_solver_solve( const DealbreakerSolver *solver, const char *state_json, const char *options_json, const DealbreakerCancel *cancel );

Solve a position. options_json and cancel may be NULL. Returns JSON { "outcome", "states", "steps"? }, or NULL on error. Caller frees result.

dealbreaker_solver_best ​

c
char *dealbreaker_solver_best( const DealbreakerSolver *solver, const char *state_json, const char *options_json, const DealbreakerCancel *cancel );

Maximize score in a points game. options_json and cancel may be NULL. Returns JSON { "score", "proven", "states", "steps" }, or NULL on error. Caller frees result.

dealbreaker_solver_hint ​

c
char *dealbreaker_solver_hint( const DealbreakerSolver *solver, const char *state_json, const char *options_json, const DealbreakerCancel *cancel );

Compute a fair hint without peeking at face-down cards. options_json and cancel may be NULL. Returns JSON { "step", "wins", "samples", "score"? } or "null", or NULL on error.

dealbreaker_solver_hints ​

c
char *dealbreaker_solver_hints( const DealbreakerSolver *solver, const char *state_json, const char *options_json, const DealbreakerCancel *cancel );

Compute ranked fair-hint recommendations without peeking at face-down cards. options_json and cancel may be NULL. Returns JSON { "candidates", "samples", "solved_samples", "unsolvable_samples", "gave_up_samples" }.

dealbreaker_solver_grade ​

c
char *dealbreaker_solver_grade( const DealbreakerSolver *solver, const char *state_json, const char *options_json, const DealbreakerCancel *cancel );

Grade a single deal's solvability and difficulty. options_json and cancel may be NULL. Returns JSON { "status": "solvable"|"unsolvable"|"unknown", ... }, or NULL on error.

dealbreaker_solver_find_deal ​

c
char *dealbreaker_solver_find_deal( const DealbreakerSolver *solver, const char *options_json, const DealbreakerCancel *cancel );

Search sequentially for a solvable deal (optionally matching a target difficulty). options_json and cancel may be NULL. Returns JSON { "seed", "state", "attempts", "grade"?, "steps"? } or "null", or NULL on error.

dealbreaker_solver_safe_steps ​

c
char *dealbreaker_solver_safe_steps(const DealbreakerSolver *solver, const char *state_json);

Greedily collect provably safe forced moves as a JSON array of steps. Caller frees result.

dealbreaker_solver_autocomplete ​

c
char *dealbreaker_solver_autocomplete(const DealbreakerSolver *solver, const char *state_json);

Detect whether state_json can be auto-completed trivially. Returns JSON { "completes_game", "steps" }, or NULL on error. Caller frees result.

dealbreaker_solver_describe_step ​

c
char *dealbreaker_solver_describe_step( const DealbreakerSolver *solver, const char *state_json, const char *step_json );

Play one step and return JSON { "details", "state" } with cards moved, destination card, flipped cards, and human-readable text. Caller frees result.

dealbreaker_solver_describe_steps ​

c
char *dealbreaker_solver_describe_steps( const DealbreakerSolver *solver, const char *state_json, const char *steps_json );

Replay a JSON array of steps from state_json and return a JSON array of StepDetails. Caller frees result.

dealbreaker_solver_last_winnable ​

c
char *dealbreaker_solver_last_winnable( const DealbreakerSolver *solver, const char *state_json, const char *history_json, const char *options_json, const DealbreakerCancel *cancel );

Find the most recent winnable position along history_json played from state_json. options_json and cancel may be NULL. Returns JSON { "index"?, "undo_steps"?, "states" }, or NULL on error. Caller frees result.

c
char *dealbreaker_solver_legal_steps(const DealbreakerSolver *solver, const char *state_json);

Return all legal steps as a JSON array, or NULL on error. Caller frees result.

dealbreaker_solver_play_step ​

c
char *dealbreaker_solver_play_step( const DealbreakerSolver *solver, const char *state_json, const char *step_json );

Play one step (JSON) and return the new position JSON, or NULL on error. Caller frees result.

dealbreaker_solver_is_won ​

c
int32_t dealbreaker_solver_is_won(const DealbreakerSolver *solver, const char *state_json);

Return 1 if won, 0 if not won, -1 on error (see dealbreaker_last_error).

dealbreaker_solver_score ​

c
int64_t dealbreaker_solver_score(const DealbreakerSolver *solver, const char *state_json);

Return score (>= 0), -1 if game is not scored, or -2 on error (see dealbreaker_last_error).

Dual-licensed under MIT or Apache-2.0.