pub struct Solver(/* private fields */);Expand description
Exclusive handle to the ddss solver
ddss (based on DDS 2.9) keeps a single persistent thread pool and is not
reentrant across threads. This struct holds a reentrant lock on that
global pool for its lifetime; acquire one with Solver::lock and call
methods on it to avoid repeated locking.
Batch entry points (Solver::solve_deals, Solver::solve_boards)
internally fan out across the ddss thread pool, so parallelism is still
utilized within each call.
Solver is !Send because ReentrantMutexGuard is !Send — the lock
must be released on the same OS thread that acquired it.
Implementations§
Source§impl Solver
impl Solver
Sourcepub fn try_lock() -> Option<Self>
pub fn try_lock() -> Option<Self>
Try to acquire exclusive access to the ddss solver without blocking
Returns None if the solver is currently in use.
Sourcepub fn solve_deal(&self, deal: FullDeal) -> TrickCountTable
pub fn solve_deal(&self, deal: FullDeal) -> TrickCountTable
Solve a single deal with sys::CalcDDtable
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
§Examples
use contract_bridge::{FullDeal, Seat, Strain};
use ddss::Solver;
// Each player holds a 13-card straight flush in one suit.
let deal: FullDeal = "N:AKQJT98765432... .AKQJT98765432.. \
..AKQJT98765432. ...AKQJT98765432".parse()?;
let solver = Solver::lock();
let tricks = solver.solve_deal(deal);
// North holds all the spades, so North or South declaring spades
// draws trumps and takes every trick.
assert_eq!(u8::from(tricks[Strain::Spades].get(Seat::North)), 13);Sourcepub fn solve_deals(
&self,
deals: &[FullDeal],
flags: NonEmptyStrainFlags,
) -> Vec<TrickCountTable>
pub fn solve_deals( &self, deals: &[FullDeal], flags: NonEmptyStrainFlags, ) -> Vec<TrickCountTable>
Solve deals in batch, fanning out across the ddss thread pool
deals: A slice of deals to solveflags: Flags of strains to solve for (must be non-empty by construction)
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
Sourcepub fn solve_board(&self, objective: &Objective) -> FoundPlays
pub fn solve_board(&self, objective: &Objective) -> FoundPlays
Solve a single board with sys::SolveBoard
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
Sourcepub fn solve_boards(&self, args: &[Objective]) -> Vec<FoundPlays>
pub fn solve_boards(&self, args: &[Objective]) -> Vec<FoundPlays>
Solve boards in batch, fanning out across the ddss thread pool
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
Sourcepub fn analyse_play(&self, trace: &PlayTrace) -> PlayAnalysis
pub fn analyse_play(&self, trace: &PlayTrace) -> PlayAnalysis
Trace DD trick counts before and after each played card with
sys::AnalysePlayBin
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
Sourcepub fn analyse_plays(&self, traces: &[PlayTrace]) -> Vec<PlayAnalysis>
pub fn analyse_plays(&self, traces: &[PlayTrace]) -> Vec<PlayAnalysis>
Trace DD trick counts for many plays, sharing the ddss thread pool
Internally loops over Solver::analyse_play; ddss’s per-call thread
pool still provides intra-call parallelism.
§Panics
Not expected — panics here are bugs. See the module-level panic policy.