Skip to main content

Solver

Struct Solver 

Source
pub struct Solver(/* private fields */);
Expand description

Exclusive handle to the DDS solver

DDS functions are not reentrant, so this struct holds a lock on the global thread pool. Acquire a Solver once and call methods on it to avoid repeated locking.

The batch functions (CalcAllTables, SolveAllBoardsBin) are internally multi-threaded, so parallelism is still utilized within each call.

Implementations§

Source§

impl Solver

Source

pub fn lock() -> Self

Acquire exclusive access to the DDS solver, blocking until available

Source

pub fn try_lock() -> Option<Self>

Try to acquire exclusive access to the DDS solver without blocking

Returns None if the solver is currently in use.

Source

pub fn system_info(&self) -> SystemInfo

Get information about the underlying DDS library

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 dds_bridge::{FullDeal, Seat, Solver, Strain};

// Each player holds a 13-card straight flush in one suit.
let deal: FullDeal = "N:AKQJT98765432... .AKQJT98765432.. \
                      ..AKQJT98765432. ...AKQJT98765432".parse()?;
let tricks = Solver::lock().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 parallel for given strains

  • deals: A slice of deals to solve
  • flags: Flags of strains to solve for
§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 parallel

  • args: A slice of boards and their targets to solve
§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 in parallel with sys::AnalyseAllPlaysBin

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