Skip to content

Commit a78944b

Browse files
committed
stronger threefold repetition prevention
1 parent c05e48b commit a78944b

File tree

7 files changed

+10
-7
lines changed

7 files changed

+10
-7
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn evaluate(pos: &Position, out_of_moves: bool) -> Value {
5050
// encourage it to keep playing instead
5151
value -= material(&pos.chessboard, stm, (0.0, 0.0, 1.0));
5252
value += material(&pos.chessboard, stm.not(), (0.0, 0.0, 1.0));
53-
value
53+
2 * value
5454
} else {
5555
// Side to move is checkmated
5656
optlog!(eval;debug;"eval checkmate");

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)