pub struct Solver { /* private fields */ }Expand description
Owned handle to a DDS solver context
One Solver owns one DDS SolverContext (private solver state:
thread-local memory, transposition table, search state) and is the
upstream-recommended way to drive DDS in parallel: one Solver per OS
thread, never shared.
The handle is Send (work-stealing pools may move it between threads
as long as no two threads access it at once) but not Sync — upstream
forbids concurrent access from multiple threads to a single context.
The transposition table is preserved across calls on the same Solver,
so reusing one over a batch of related queries amortizes setup cost.
For batches of unrelated queries the free helpers solve_deals and
solve_boards hand the whole batch to a per-worker-context pool inside
dds-bridge-sys.
Drop calls dds_solver_context_free.
Implementations§
Source§impl Solver
impl Solver
Sourcepub fn new(config: SolverConfig) -> Self
pub fn new(config: SolverConfig) -> Self
Construct a new solver with the given configuration
§Panics
If the C++ allocator returns a null pointer.
Sourcepub fn solve_deal(&mut self, deal: FullDeal) -> TrickCountTable
pub fn solve_deal(&mut self, deal: FullDeal) -> TrickCountTable
Solve a single deal for all strains and all declarers
Resets internal search state before solving so the result does not
depend on previous solves on this Solver (the transposition table
is preserved across calls).
§Panics
Not expected — panics here are bugs. See the module-level panic policy.
§Examples
use contract_bridge::{FullDeal, Seat, Strain};
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);
// 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_board(&mut self, objective: &Objective) -> FoundPlays
pub fn solve_board(&mut self, objective: &Objective) -> FoundPlays
Trait Implementations§
Source§impl Default for Solver
impl Default for Solver
Source§fn default() -> Self
fn default() -> Self
Construct a new solver with the SolverConfig::default configuration.
impl Send for Solver
Auto Trait Implementations§
impl !Sync for Solver
impl Freeze for Solver
impl RefUnwindSafe for Solver
impl Unpin for Solver
impl UnsafeUnpin for Solver
impl UnwindSafe for Solver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more