Skip to content

Commit 05b950d

Browse files
committed
stronger threefold repetition prevention
1 parent c05e48b commit 05b950d

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
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` TBD, TODO
90+
- `v0.6.3` 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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ pub fn evaluate(pos: &Position, out_of_moves: bool) -> Value {
4646
if out_of_moves {
4747
return if pos.chessboard.checkers().eq(&EMPTY) {
4848
optlog!(eval;debug;"eval stalemate");
49-
// in stalemate, give a slightly negative score to the side that's winning to
49+
// 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
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
5456
} else {
5557
// Side to move is checkmated
56-
optlog!(eval;debug;"eval checkmate");
57-
-Value::MATE // Large negative value
58+
optlog!(eval;trace;"eval checkmate");
59+
-Value::MATE
5860
};
5961
}
6062

src/engine/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Engine {
7171
/// positions to detect threefold repetition.
7272
pub fn log_position(&mut self, pos: Position) {
7373
self.history.push_front(pos);
74-
self.history.truncate(6);
74+
self.history.truncate(7);
7575
}
7676

7777
/// set the global [`SEARCHING`]

src/engine/search/main_search.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ impl Engine {
8787
*engine_history.get(3).unwrap_or(&0),
8888
*engine_history.get(4).unwrap_or(&0),
8989
*engine_history.get(5).unwrap_or(&0),
90+
*engine_history.get(6).unwrap_or(&0),
9091
],
9192
};
9293

94+
optlog!(search;warn;"history:{:?}", initial_options.history);
95+
9396
// SAFETY: if it fails it's due to poison,
9497
// and that means another thread panicked,
9598
// so we should panic as well anyway

src/engine/search/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct SearchOptions {
111111
pub extensions: Depth,
112112

113113
/// previously played position that would cause draw by threefold repetition
114-
pub history: [u64; 6],
114+
pub history: [u64; 7],
115115
}
116116

117117
/// wrapper around [`SEARCH_UNTIL`]

src/engine/search/negamax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ pub fn negamax(
179179
// if theres 3 moves or less, search +1 level deeper
180180
};
181181

182-
search_options.history.rotate_left(1);
183-
search_options.history[5] = current_hash;
182+
search_options.history.rotate_right(1);
183+
search_options.history[0] = current_hash;
184184
search_options = SearchOptions {
185185
extensions: search_options
186186
.extensions

src/sandy/player/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn terminal_loop(mut engine: Engine) -> Result<()> {
7474
engine.best_move(search_depth, search_time)?
7575
};
7676
let capture = engine.board.chessboard.piece_on(mv.get_dest()).is_some();
77-
engine.board = engine.board.make_move(mv);
77+
engine.make_move(mv);
7878

7979
info!("{}", engine.board.print_move(mv, capture));
8080

0 commit comments

Comments
 (0)