Skip to main content

Solver

Struct Solver 

Source
pub struct Solver { /* private fields */ }
Expand description

Per-strain solver.

Bound to a single strain (set at Self::new, retargetable via Self::set_strain) and owns a search engine and a transposition table, mirroring the per-strain Engine. Self::solve runs all 4 declarers of the configured strain for a deal; for a full 5 × 4 table across every strain use the free solve_deal / solve_deals.

The engine and TT are reused across calls so the TT can warm up. Solving a deal resets the TT — the cached entries from a previous deal (or strain) use a stale per-deal lookup table / trump and would produce incorrect hits.

Solver is Send but intentionally not Sync: the transposition table is per-search-context and not safe for concurrent reads or writes. Use the free solve_deals function to drive multiple solvers in parallel.

Implementations§

Source§

impl Solver

Source

pub fn new(strain: Strain) -> Self

Create a fresh solver for strain with the default transposition-table memory budget. Retarget the strain later with Self::set_strain.

Source

pub fn with_memory(strain: Strain, default_mb: u32, max_mb: u32) -> Self

Create a solver for strain with an explicit transposition-table memory budget, in MiB: default_mb is the size the table shrinks back to on reset (per solve), max_mb the ceiling before a full reset is forced. Self::new uses the built-in defaults (DEFAULT_MEMORY_MB / MAX_MEMORY_MB).

Bigger is better up to a plateau: a starved table full-resets and re-searches, so undersizing it explodes the node count (16/32 MiB is ~3.5× slower than the default). Correctness is unaffected at any size — a full table just resets and rebuilds. Mainly useful for capping per-thread memory in highly parallel runs.

Source

pub fn set_strain(&mut self, strain: Strain)

Retarget the solver to a different strain. The next Self::solve resets the transposition table, so no stale-trump entries survive the change.

Source

pub fn solve(&mut self, deal: FullDeal) -> [u8; 4]

Solve the configured strain (all 4 declarers) of deal, returning the per-seat trick row in seat order (North, East, South, West).

Resets the transposition table for the strain’s trump, then reuses it across the 4 declarer searches: the bounds are framed relative to seat 0’s side, so they stay valid as the declarer — hence the MAX side — rotates within a strain. This per-strain unit is the grain of parallelism in solve_deals; keeping the 4 declarers on one unit preserves that intra-strain TT reuse.

Source§

impl Solver

Source

pub const fn bisection_stats(&self) -> (u64, u64)

Diagnostic: total (search_target_calls, bisection_iters) accumulated by this solver’s engine since it was created or Self::reset_bisection_stats was last called.

bisection_iters / search_target_calls is the average number of alpha-beta probes per bisection driver call — a value close to 1 means the TT carries bounds between probes; ≈ 4 means each probe re-traverses the tree from scratch.

Source

pub const fn reset_bisection_stats(&mut self)

Zero the bisection diagnostic counters.

Source

pub const fn bisection_timing(&self) -> (u128, u128)

Cumulative (iter1_nanos, later_nanos) — wall-clock time spent in the first bisection iteration of each search_target call vs in subsequent iterations. The ratio answers whether TT-cached internal subtrees make later iters cheap.

Source

pub const fn search_stats(&self) -> SearchStats

Cumulative per-node search instrumentation (TT hit rate, move-ordering cutoff index, node-0 early-exit funnel).

All fields are zero unless the crate is built with --features profiling.

Source

pub fn reset_search_stats(&mut self)

Zero the per-node search instrumentation counters.

Trait Implementations§

Source§

impl Default for Solver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.