Skip to content

Commit b9dec81

Browse files
committed
uci changes
Signed-off-by: Andreas Tsatsanis <[email protected]>
1 parent 37aea09 commit b9dec81

File tree

5 files changed

+40
-27
lines changed

5 files changed

+40
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ everything under [`./src/sandy/`](src/sandy/) is part of the frontend (almost)
8787
- [`./src/sandy/uci/search_controls.rs`](src/sandy/uci/search_controls.rs) does the same for search controls (eg `go depth 4`)
8888

8989
## Changelog
90-
- `v0.6.3` one more attempt at fixing 3fold repetition avoidance
90+
- `v0.6.3` quiescence search, breaking changes on `Opts`, one more attempt at fixing 3fold repetition avoidance
9191
- `v0.6.2` inline move ordering: switch from an allocated `Vec<ChessMove>` to an iterator that only generates moves as needed, performing all move ordering operations on the construction of the iterator.
9292
- `v0.6.1` variable search depth: when a node has <= 3 children, increase search depth by 1, just for this case. this massively helps lookahead in positions with a lot of checks
9393
- lost versions: i did not actually keep a changelog until `v0.6.1`. i do not remember the details here

src/engine/evaluation/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ pub fn evaluate(pos: &Position, out_of_moves: bool) -> Value {
4848
optlog!(eval;debug;"eval stalemate");
4949
// in stalemate, give a negative score to the side that's winning to
5050
// encourage it to keep playing instead
51-
value += material(&pos.chessboard, stm, (0.0, 0.0, 1.0));
52-
value -= material(&pos.chessboard, stm.not(), (0.0, 0.0, 1.0));
53-
value += piece_position_benefit_for_side(&pos.chessboard, stm, (0.0, 0.0, 1.0));
54-
value -= piece_position_benefit_for_side(&pos.chessboard, stm.not(), (0.0, 0.0, 1.0));
55-
-2 * value
51+
let interp = interpolate(&pos.chessboard);
52+
value += material(&pos.chessboard, stm, interp);
53+
value -= material(&pos.chessboard, stm.not(), interp);
54+
value += piece_position_benefit_for_side(&pos.chessboard, stm, interp);
55+
value -= piece_position_benefit_for_side(&pos.chessboard, stm.not(), interp);
56+
-2 * (value + TEMPO + TEMPO)
5657
} else {
5758
// Side to move is checkmated
5859
optlog!(eval;trace;"eval checkmate");

src/engine/opts.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ use crate::optlog;
1212
use crate::search::SEARCH_THREADS;
1313
use crate::transposition_table::DEFAULT_TABLE_SIZE;
1414

15+
/// limit transposition table size to 64gb.
16+
/// this limit depends on the currenly used implementation for the hash table,
17+
/// as unfortunately bigger isn't always better.
18+
const MAX_HASH_SIZE: i64 = 65536;
19+
1520
/// Read the global options for the engine, attempting to go through the
1621
/// [`RwLock`] of [`OPTS`] to do so
1722
#[inline(always)]
@@ -217,7 +222,7 @@ impl Opts {
217222
name: "hash".to_string(),
218223
default: Some((DEFAULT_TABLE_SIZE / (1024 * 1024)).max(1) as i64),
219224
min: Some(0),
220-
max: Some(4096),
225+
max: Some(MAX_HASH_SIZE),
221226
},
222227
UciOptionConfig::Spin {
223228
name: "threads".to_string(),
@@ -270,7 +275,7 @@ impl Opts {
270275
// hash input is in megabytes, according to UCI specification
271276
"hash" => {
272277
self.engine_opts.hash_size =
273-
1024 * 1024 * parse_spin("hash", 0, 1024, value)? as usize
278+
1024 * 1024 * parse_spin("hash", 0, MAX_HASH_SIZE, value)? as usize
274279
}
275280
"threads" => self.engine_opts.threads = parse_spin("threads", 0, 1024, value)? as usize,
276281
unknown => bail!("unknown option: {:?}", unknown),

src/engine/search/negamax.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,27 @@ pub fn negamax(
123123

124124
/* source: https://en.wikipedia.org/wiki/Negamax */
125125
let alpha_orig = alpha;
126-
if opts.use_tt {
127-
if let Ok(Some(tt_entry)) = table.read().map(|l| l.get(current_hash)) {
128-
if tt_entry.is_valid() {
129-
if tt_entry.depth() >= to_depth {
130-
match tt_entry.bound() {
131-
EvalBound::Exact => return tt_entry.search_result(),
132-
EvalBound::LowerBound => {
133-
alpha = alpha.max(tt_entry.search_result().next_position_value)
134-
}
135-
EvalBound::UpperBound => {
136-
beta = beta.min(tt_entry.search_result().next_position_value)
137-
}
126+
if opts.use_tt
127+
&& let Ok(Some(tt_entry)) = table.read().map(|l| l.get(current_hash))
128+
{
129+
if tt_entry.is_valid() {
130+
if tt_entry.depth() >= to_depth {
131+
match tt_entry.bound() {
132+
EvalBound::Exact => return tt_entry.search_result(),
133+
EvalBound::LowerBound => {
134+
alpha = alpha.max(tt_entry.search_result().next_position_value)
135+
}
136+
EvalBound::UpperBound => {
137+
beta = beta.min(tt_entry.search_result().next_position_value)
138138
}
139139
}
140-
if alpha >= beta {
141-
return tt_entry.search_result();
142-
}
143140
}
144-
pre_generated[0] = Some(tt_entry.mv());
145-
base_gen.remove_move(tt_entry.mv());
141+
if alpha >= beta {
142+
return tt_entry.search_result();
143+
}
146144
}
145+
pre_generated[0] = Some(tt_entry.mv());
146+
base_gen.remove_move(tt_entry.mv());
147147
}
148148

149149
if to_depth == Depth::ZERO {

src/sandy/uci/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,15 @@ pub fn uci_loop(mut engine: Engine) -> Result<()> {
7272
Ok(opt) => {
7373
setopts(opt)?;
7474
engine.eng_opts = opt.engine_opts;
75-
let entry_count = engine.resize_table(engine.eng_opts.hash_size)?;
76-
println!("info string table resized to {entry_count} entries.");
75+
if name == "hash" {
76+
println!("info string resizing table...");
77+
let start_alloc_time = Instant::now();
78+
let entry_count = engine.resize_table(engine.eng_opts.hash_size)?;
79+
println!(
80+
"info string table resized to {entry_count} entries in {}s",
81+
start_alloc_time.elapsed().as_secs_f32()
82+
);
83+
}
7784

7885
optlog!(uci;info;
7986
"option {name} set to {}.",

0 commit comments

Comments
 (0)