Skip to main content

Solver

Struct Solver 

Source
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

Source

pub fn lock() -> Self

Acquire exclusive access to the ddss solver, blocking until available

Source

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.

Source

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);
Source

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 solve
  • flags: 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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Solver

§

impl !RefUnwindSafe for Solver

§

impl !Send for Solver

§

impl Sync for Solver

§

impl Unpin for Solver

§

impl UnsafeUnpin for Solver

§

impl !UnwindSafe for Solver

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.