Skip to content

Commit f5cf928

Browse files
committed
chore: add support for openbench
1 parent 9d0e0a9 commit f5cf928

File tree

12 files changed

+45
-52
lines changed

12 files changed

+45
-52
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "chess"]
2-
path = chess
3-
url = git@github.com:funnsam/chess

Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2024"
99
[dependencies]
1010
arrayvec = "0.7"
1111
bytemuck = { version = "1.20.0", features = ["derive"] }
12-
chess = { version = "4.0.0", path = "chess" }
12+
chess = { version = "4.0.0", git = "https://github.com/funnsam/chess.git" }
1313
fastrand = "2.3.0"
1414
fxhash = "0.2.1"
1515
parking_lot = "0.12.3"

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
cd dysprosium-uci && cargo b -r
3+
cp target/release/dysprosium-uci $(EXE)

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
cd dysprosium-uci && cargo b -r && cd .. && cp target/release/dysprosium-uci "engines/$1"
3+
make EXE="engines/$1"

chess

-1
This file was deleted.

dysprosium-lichess/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
chess = { version = "4.0.0", path = "../chess" }
7+
chess = { version = "4.0.0", git = "https://github.com/funnsam/chess.git" }
88
dysprosium = { version = "0.1.0", path = ".." }
99
serde = { version = "1.0.217", features = ["derive"] }
1010
serde_json = "1.0.134"

dysprosium-uci/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
chess = { version = "4.0.0", path = "../chess" }
7+
chess = { version = "4.0.0", git = "https://github.com/funnsam/chess.git" }
88
dysprosium = { version = "0.1.0", path = ".." }

dysprosium-uci/src/client.rs

+16-40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use crate::*;
24

35
use dysprosium::Engine;
@@ -70,14 +72,15 @@ impl State {
7072
} else if let Some(tc) = tc {
7173
self.engine.time_control(movestogo, tc);
7274
} else {
73-
self.engine.allow_for(std::time::Duration::MAX);
75+
self.engine.allow_for(Duration::MAX);
7476
}
7577

7678
let mov = self.best_move(target_depth);
7779
if self.debug_mode {
78-
// NOTE: getting the amount of tt used can be expensive, so it is only counted
79-
// if in debug mode
80-
println!("info hashfull {}", 1000 * self.engine.tt_used() / self.engine.tt_size());
80+
let full = 1000 * self.engine.tt_used() / self.engine.tt_size();
81+
82+
println!("info hashfull {full}");
83+
self.engine.dump_debug();
8184
}
8285
println!("bestmove {mov}");
8386
},
@@ -87,44 +90,17 @@ impl State {
8790
self.engine.game.read(),
8891
evaluate_static(self.engine.game.read().board()),
8992
),
90-
Some(uci::UciCommand::Bench) => self.benchmark(),
91-
None => {},
92-
}
93-
}
94-
95-
fn benchmark(&mut self) {
96-
let mut results = [0; 8];
97-
98-
*self.engine.game.write() = Game::from_str("r5k1/5pp1/P1p1P2p/2R5/3r4/6PP/1P2R1K1/8 b - - 0 34").unwrap();
99-
100-
for (i, rec) in results.iter_mut().enumerate() {
101-
const ITERS: usize = 4;
102-
103-
self.engine.kill_smp();
104-
self.engine.start_smp(i);
93+
Some(uci::UciCommand::Bench) => {
94+
self.engine.allow_for(Duration::MAX);
95+
self.engine.best_move(|_, (_, _, depth)| depth < 16);
10596

106-
let mut nodes = 0;
107-
for _ in 0..ITERS {
108-
self.engine.clear_hash();
97+
let nodes = self.engine.nodes();
98+
let elapsed = self.engine.elapsed();
99+
let nps = (nodes as f64 / elapsed.as_secs_f64()).round();
109100

110-
self.engine.allow_for(std::time::Duration::from_secs(1));
111-
self.engine.best_move(|_, (_, _, depth)| {
112-
println!("{}t {depth}", i + 1);
113-
true
114-
});
115-
116-
nodes += self.engine.nodes();
117-
}
118-
119-
*rec = nodes / ITERS;
120-
}
121-
122-
println!("{results:?}");
123-
124-
let m = results[1] as f32 - results[0] as f32;
125-
126-
for (i, r) in results.into_iter().enumerate() {
127-
println!("{}t: {r} nps (linear: {}, {} × 1t)", i + 1, m * i as f32 + results[0] as f32, r as f32 / results[0] as f32);
101+
println!("{nodes} nodes {nps} nps");
102+
},
103+
None => {},
128104
}
129105
}
130106

dysprosium-uci/src/main.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(str_split_whitespace_remainder)]
22

3-
use std::{io::BufRead, str::FromStr};
3+
use std::io::BufRead;
44
use dysprosium::*;
55

66
mod client;
@@ -15,8 +15,22 @@ fn main() {
1515

1616
let mut client = client::State::new();
1717

18+
let mut args = std::env::args().skip(1);
19+
if let Some(a) = args.next() {
20+
let mut a = Some(a);
21+
22+
while let Some(l) = a {
23+
let tokens = l.split_whitespace();
24+
client.handle_command(uci::parse_command(tokens));
25+
26+
a = args.next();
27+
}
28+
29+
std::process::exit(0);
30+
}
31+
1832
let stdin = std::io::stdin().lock().lines();
19-
for l in std::env::args().skip(1).map(Ok).chain(stdin) {
33+
for l in stdin {
2034
if let Ok(l) = l {
2135
let tokens = l.split_whitespace();
2236
client.handle_command(uci::parse_command(tokens));

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ impl Engine {
182182
pub fn clear_hash(&mut self) {
183183
self.trans_table.clear();
184184
}
185+
186+
pub fn dump_debug(&self) {
187+
println!("{:#?}", self.debug);
188+
}
185189
}
186190

187191
impl Drop for Engine {

src/search.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl Engine {
3737
}
3838

3939
self.smp_abort.initiate();
40-
println!("{:#?}", self.debug);
4140
prev
4241
}
4342
}

0 commit comments

Comments
 (0)