derivation tests
This commit is contained in:
parent
f6312a9fef
commit
6958df9df4
@ -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 {
|
if let Some(root) = self.current_root {
|
||||||
let mut hist = Vec::new();
|
let mut hist = Vec::new();
|
||||||
|
|
||||||
@ -307,11 +307,24 @@ impl FutureMoves {
|
|||||||
hist.push((n.coord, n.color));
|
hist.push((n.coord, n.color));
|
||||||
current = n.parent;
|
current = n.parent;
|
||||||
}
|
}
|
||||||
|
hist.reverse();
|
||||||
|
|
||||||
let mut board = self.arena[root].board;
|
if current != self.current_root {
|
||||||
for (m, c) in hist.into_iter().rev() {
|
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 {
|
if let Some(m) = m {
|
||||||
let _ = board.place(m, c);
|
board.place(m, c).expect("move would not propegate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(board)
|
Some(board)
|
||||||
@ -792,14 +805,45 @@ mod tests {
|
|||||||
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
|
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
|
||||||
|
|
||||||
let mut b = Board::new().starting_pos();
|
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(
|
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,
|
b,
|
||||||
Piece::Black,
|
Piece::Black,
|
||||||
Piece::White,
|
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
|
// I can't actually reproduce the issue I got, this is my best attempt
|
||||||
|
|||||||
@ -12,8 +12,8 @@ pub mod repr;
|
|||||||
|
|
||||||
// TODO! make this agent configuration a config option via `clap-rs`
|
// TODO! make this agent configuration a config option via `clap-rs`
|
||||||
fn main() {
|
fn main() {
|
||||||
elo::run();
|
// elo::run();
|
||||||
return;
|
// return;
|
||||||
let player1 = complexagent::ComplexAgent::new(
|
let player1 = complexagent::ComplexAgent::new(
|
||||||
Piece::Black,
|
Piece::Black,
|
||||||
FutureMoveConfig {
|
FutureMoveConfig {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user