derivation tests

This commit is contained in:
Simon Gardling 2025-03-06 16:13:17 -05:00
parent f6312a9fef
commit 6958df9df4
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 52 additions and 8 deletions

View File

@ -293,7 +293,7 @@ impl FutureMoves {
}
}
fn get_board_from_idx(&self, idx: usize) -> Option<Board> {
fn move_history(&self, idx: usize) -> Option<Vec<(Option<CoordPair>, Piece)>> {
if let Some(root) = self.current_root {
let mut hist = Vec::new();
@ -307,11 +307,24 @@ impl FutureMoves {
hist.push((n.coord, n.color));
current = n.parent;
}
hist.reverse();
let mut board = self.arena[root].board;
for (m, c) in hist.into_iter().rev() {
if current != self.current_root {
return None;
}
Some(hist)
} else {
None
}
}
fn get_board_from_idx(&self, idx: usize) -> Option<Board> {
if let Some(hist) = self.move_history(idx) {
let mut board = self.arena[self.current_root.unwrap()].board;
for (m, c) in hist {
if let Some(m) = m {
let _ = board.place(m, c);
board.place(m, c).expect("move would not propegate");
}
}
Some(board)
@ -792,14 +805,45 @@ mod tests {
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
let mut b = Board::new().starting_pos();
let _ = b.place((2, 3).into(), Piece::Black);
futm.arena
.push(Move::new(None, b, Piece::Black, Piece::White));
futm.update_root_idx_raw(0);
b.place((4, 2).into(), Piece::White).unwrap();
futm.arena.push(Move::new(
Some((2, 3).into()),
Some((4, 2).into()),
b,
Piece::White,
Piece::White,
));
futm.set_parent_child(0, 1);
assert_eq!(
futm.move_history(1),
Some(vec![(Some((4, 2).into()), Piece::White)]),
);
assert_eq!(futm.get_board_from_idx(1), Some(b));
b.place((5, 4).into(), Piece::Black).unwrap();
futm.arena.push(Move::new(
Some((5, 4).into()),
b,
Piece::Black,
Piece::White,
));
futm.set_parent_child(1, 2);
assert_eq!(
futm.move_history(2),
Some(vec![
(Some((4, 2).into()), Piece::White),
(Some((5, 4).into()), Piece::Black)
]),
);
assert_eq!(futm.get_board_from_idx(2), Some(b));
}
// I can't actually reproduce the issue I got, this is my best attempt

View File

@ -12,8 +12,8 @@ pub mod repr;
// TODO! make this agent configuration a config option via `clap-rs`
fn main() {
elo::run();
return;
// elo::run();
// return;
let player1 = complexagent::ComplexAgent::new(
Piece::Black,
FutureMoveConfig {