Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Nov 4, 2024
1 parent 677c896 commit 6da70e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Suit {
pub const ALL: [Suit; 4] = [Suit::C, Suit::D, Suit::H, Suit::S];

#[must_use]
pub fn symbol(&self) -> &str {
pub fn symbol(self) -> &'static str {
match self {
Suit::C => "\u{2663}",
Suit::D => "\u{2666}",
Expand Down
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ impl Player {
fn index(self) -> usize {
(self as u8) as usize
}

fn symbol(self) -> &'static str {
match self {
Self::W => "W",
Self::N => "N",
Self::E => "E",
Self::S => "S",
}

}
}

impl std::fmt::Debug for Player {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::W => write!(f, "W"),
Self::N => write!(f, "N"),
Self::E => write!(f, "E"),
Self::S => write!(f, "S"),
}
f.write_str(self.symbol())
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl Lattice<u8> for Min {
}
}

#[derive(Debug, Clone)]
pub struct InitialPosition {
pub deal: Deal,
pub trumps: Option<Suit>,
Expand All @@ -58,6 +59,7 @@ where
TT: TransTable<PoC>,
ST: Stats,
{
init: InitialPosition,
state: PlayState<PoC>,
table: TT,
stats: ST,
Expand All @@ -82,6 +84,7 @@ impl<PoC: PlayOfCards, TT: TransTable<PoC>, ST: Stats> SearchImpl<PoC, TT, ST> {
let deal = deal.promote_all(&mut cards);

Self {
init: init.clone(),
state: PlayState::<PoC>::new(&deal, next),
table,
stats,
Expand Down Expand Up @@ -281,7 +284,7 @@ impl<PoC: PlayOfCards, TT: TransTable<PoC>, ST: Stats> Search for SearchImpl<PoC
guess = upper;
}
}
self.stats.search_finished();
self.stats.search_finished(&self.init);

guess
}
Expand Down
15 changes: 9 additions & 6 deletions src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::time::{Duration, Instant};

use crate::search::InitialPosition;

pub trait Stats {
fn guess_iter(&mut self);
fn max_tricks_cutoff(&mut self);
fn node_visit(&mut self);
fn quick_tricks_cutoff(&mut self);
fn search_cutoff(&mut self);
fn search_finished(&mut self);
fn search_finished(&mut self, init: &InitialPosition);
fn search_started(&mut self);
fn tt_hit(&mut self);
fn tt_lower_cutoff(&mut self);
Expand All @@ -31,7 +33,7 @@ impl Stats for EmptyStats {

fn search_cutoff(&mut self) {}

fn search_finished(&mut self) {}
fn search_finished(&mut self, _init: &InitialPosition) {}

fn search_started(&mut self) {}

Expand All @@ -53,10 +55,11 @@ pub struct UnsyncStats {
tt_upper_cutoff: usize,
}
impl UnsyncStats {
fn print(&self) {
fn print(&self, init: &InitialPosition) {
let duration = self.elapsed.unwrap().as_millis() as usize;
println!("Search Statistics:");
println!(" duration: {duration:12} ms",);
println!(" contract: {}{}", init.declarer.symbol(), init.trumps.map_or("N", |s| s.symbol()));
println!(" duration: {duration:12} ms");
println!(" searches: {:12}", self.search);
println!(" guesses: {:12}", self.guess_iter);
println!(" nodes: {:12} {}/ms", self.nodes, self.nodes / duration);
Expand Down Expand Up @@ -98,9 +101,9 @@ impl Stats for UnsyncStats {
self.search_cutoff += 1;
}

fn search_finished(&mut self) {
fn search_finished(&mut self, init: &InitialPosition) {
self.elapsed = Some(self.start.unwrap().elapsed());
self.print();
self.print(init);
}

fn search_started(&mut self) {
Expand Down

0 comments on commit 6da70e6

Please sign in to comment.