Expand description
§dds-bridge
A Rusty API for DDS, the double-dummy solver for the game of bridge.
This crate aims to be the building block of computer bridge in Rust.
It links to dds-bridge/dds, the fundamental C++ double dummy
solver, via our system crate.
§Installation
cargo add dds-bridgeA C++ toolchain is required to build the underlying dds-bridge-sys
crate. On most Linux distributions the default g++ and make are
enough; macOS needs the Xcode Command Line Tools; Windows builds via
MSVC.
§Quick start
Parse a PBN-formatted deal, solve it for all strains and seats, and score a specific contract:
use contract_bridge::{Contract, FullDeal, Penalty, Strain, Seat};
use dds_bridge::Solver;
// Each player holds a 13-card straight flush in one suit.
let deal: FullDeal = "N:AKQJT98765432... .AKQJT98765432.. \
..AKQJT98765432. ...AKQJT98765432".parse()?;
let mut solver = Solver::default();
let tricks = solver.solve_deal(deal);
// 4♠ by North, scored as if 10 tricks taken, not vulnerable.
let contract = Contract::new(4, Strain::Spades, Penalty::Undoubled);
assert_eq!(contract.score(10, false), 420);§Features
serde(optional) —Serialize/Deserializefor all public types. Human-readable formats (JSON, YAML, TOML) round-trip through theDisplay/FromStrtext form; binary formats use a compact derived representation.
§License
Licensed under the Apache License, Version 2.0.
§Panic policy
The solver entry points in this crate — calculate_par,
calculate_pars, Solver::solve_deal, Solver::solve_board,
solve_deals, solve_boards, analyse_play, and analyse_plays
— are not expected to panic. They map DDS status codes through an
internal helper that panics on error, but reaching that panic means
either invalid input slipped past a safe constructor or DDS itself
misbehaved. Either case is a bug — please report it.
This policy does not cover validator panics from safe constructors
(e.g. TrickCountRow::new), which panic by design on out-of-range
inputs and have try_* counterparts for fallible construction.
Structs§
- Board
- A snapshot of a board
- Current
Trick - Trick-in-progress — 0 to 3 cards played, in playing order
- Found
Plays - Solved plays for a board
- Invalid
Trick Count - Error returned when a trick count is outside
0..=13 - NonEmpty
Strain Flags - A guaranteed non-empty
StrainFlags - Objective
- A board and its solving target
- Par
- Par score and contracts
- ParContract
- Par contract
- Parse
Vulnerability Error - Error returned when parsing a
Vulnerabilityfails - Play
- A play and its consequences
- Play
Analysis - Double-dummy trick counts before and after each played card in a trace
- Play
Trace - A starting board and a sequence of cards played from it
- Play
Trace Bin - Thin wrapper over
sys::PlayTraceBinso we can impl conversions for it - Solver
- Owned handle to a DDS solver context
- Solver
Config - Configuration for a
Solver - Strain
Flags - Flags for the solver to solve for a strain
- System
Info - Information about the DDS library and how it was built
- Trick
Count - A number of tricks in
0..=13 - Trick
Count Row - Tricks that each seat can take as declarer for a strain
- Trick
Count RowHex - Hexadecimal view of a
TrickCountRowfrom a seat’s perspective - Trick
Count Table - Tricks that each seat can take as declarer for all strains
- Trick
Count Table Hex - Hexadecimal view of a
TrickCountTablefrom a seat’s perspective - Vulnerability
- Vulnerability of pairs
Enums§
- Board
Error - Error returned when constructing a
Boardwith invalid invariants - Compiler
- C++ compiler used to build the DDS library
- Current
Trick Error - Error returned when pushing cards to a
CurrentTrick - Platform
- OS platform reported by the DDS library
- Revoke
Position - Position of the revoking card within the current trick
- Target
- Target tricks and number of solutions to find
- Threading
- Threading model used by the DDS library
- TtKind
- Kind of transposition table to allocate inside a
Solver
Functions§
- analyse_
play - Trace DD trick counts before and after each played card with
sys::AnalysePlayBin - analyse_
plays - Trace DD trick counts for many plays in parallel
- calculate_
par - Calculate par score and contracts for a deal
- calculate_
pars - Calculate par scores for both pairs
- dd_
table_ deal_ from - Convert a validated deal (either
FullDealorPartialDeal) into a DDSDdTableDeal. - dd_
table_ deal_ from_ builder - Convert a
Builderinto the DDSDdTableDeal. - solve_
boards - Solve a slice of boards in parallel
- solve_
deals - Solve a slice of deals in parallel
- system_
info - Get information about the underlying DDS library