Skip to content

Commit

Permalink
dot observer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Nov 28, 2024
1 parent 5108cb6 commit f91b1ef
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build-valgrind:
cargo +nightly build -r -Z build-std --target x86_64-unknown-linux-gnu

test-suite:
cargo run -r test {{DDS_HOME}}/hands/list2.txt
cargo build -r && time cargo run -r test {{DDS_HOME}}/hands/list10.txt

doc:
cargo doc
Expand Down
2 changes: 2 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ pkgs.mkShell {
watchexec just valgrind
# rust
rustup
# to visualize traces
graphviz
];
}
11 changes: 10 additions & 1 deletion src/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl Card {
self.suit().bit_index() + self.value().index()
}

fn index(self) -> usize {
pub(crate) fn index(self) -> usize {
self.suit().index() * 13 + self.value().index()
}
}
Expand Down Expand Up @@ -1150,6 +1150,15 @@ impl Deal {
let p = p.index();
self.hands[p] |= CardSet::from(card).mask;
}

pub(crate) fn format_as_bpn(&self) -> String {
format!("{} {} {} {}",
&CardSet::from(self.hands[0]).to_bpn(),
&CardSet::from(self.hands[1]).to_bpn(),
&CardSet::from(self.hands[2]).to_bpn(),
&CardSet::from(self.hands[3]).to_bpn(),
)
}
}

impl BitAnd<CardSet> for &Deal {
Expand Down
65 changes: 51 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::{fs::read_to_string, path::PathBuf};

use bridgitte::{
analyze::{analyze_all, analyze_player, analyze_strain, ByStrain, Strain}, minmax::minmax, search::{Config, InitialPosition}, trans_table::Pattern, ByPlayer, Deal, Player, Suit
analyze::{analyze_all, analyze_player, analyze_strain, ByStrain, Strain},
minmax::minmax,
search::{Config, InitialPosition, TracingConfig, TracingType},
trans_table::Pattern,
ByPlayer, Deal, Player, Suit,
};
use clap::{Args, Parser, Subcommand};
use regex::Regex;
use rayon::prelude::*;
use regex::Regex;

#[derive(Parser, Debug)]
struct Cli {
Expand All @@ -24,9 +28,7 @@ enum Command {
#[arg(short, long)]
strain: Option<Strain>,
#[arg(long)]
stats: bool,
#[arg(long)]
trace: bool,
trace: Option<TracingType>,
},
TestPattern(TestPatternArgs),
Test(TestArgs),
Expand Down Expand Up @@ -54,15 +56,19 @@ pub fn main() {
deal,
declarer,
strain,
stats,
trace,
next,
} => {
let deal = Deal::try_from_pbn(&deal).unwrap();
println!("{}", deal.format_as_table());
println!();

let config = Config { stats, trace };
let config = Config {
tracing: trace.map(|t| TracingConfig {
typ: t,
output: PathBuf::from("trace"),
}),
};

if let Some(declarer) = declarer {
if let Some(strain) = strain {
Expand Down Expand Up @@ -198,7 +204,7 @@ impl TestFile {
#[derive(Debug)]
struct Test {
deal: Deal,
table: ByPlayer<ByStrain<u8>>
table: ByPlayer<ByStrain<u8>>,
}
impl Test {
fn run(&self) {
Expand Down Expand Up @@ -231,15 +237,46 @@ fn parse(content: &str) -> TestFile {
}

if let Some(table) = line.strip_prefix("TABLE ") {
let table: Vec<_> = table.trim().split(' ').map(|i| i.parse::<u8>().unwrap()).collect();
let table: Vec<_> = table
.trim()
.split(' ')
.map(|i| i.parse::<u8>().unwrap())
.collect();
assert_eq!(table.len(), 20);
let table = ByPlayer {
n: ByStrain { c: table[12], d: table[8], h: table[4], s: table[0], n: table[16] },
e: ByStrain { c: table[13], d: table[9], h: table[5], s: table[1], n: table[17] },
s: ByStrain { c: table[14], d: table[10], h: table[6], s: table[2], n: table[18] },
w: ByStrain { c: table[15], d: table[11], h: table[7], s: table[3], n: table[19] },
n: ByStrain {
c: table[12],
d: table[8],
h: table[4],
s: table[0],
n: table[16],
},
e: ByStrain {
c: table[13],
d: table[9],
h: table[5],
s: table[1],
n: table[17],
},
s: ByStrain {
c: table[14],
d: table[10],
h: table[6],
s: table[2],
n: table[18],
},
w: ByStrain {
c: table[15],
d: table[11],
h: table[7],
s: table[3],
n: table[19],
},
};
tests.push(Test { deal: deal.unwrap(), table });
tests.push(Test {
deal: deal.unwrap(),
table,
});
deal = None;
continue;
}
Expand Down
Loading

0 comments on commit f91b1ef

Please sign in to comment.