FutureMoves: initial move to not storing board
This commit is contained in:
@@ -19,6 +19,8 @@ pub struct FutureMoves {
|
||||
agent_color: Piece,
|
||||
|
||||
config: FutureMoveConfig,
|
||||
|
||||
board: Board,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@@ -87,6 +89,7 @@ impl FutureMoves {
|
||||
current_depth: 0,
|
||||
agent_color,
|
||||
config,
|
||||
board: Board::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,13 +199,15 @@ impl FutureMoves {
|
||||
let parent = &self.arena[parent_idx];
|
||||
|
||||
let new_color = !parent.color;
|
||||
let parent_board = self
|
||||
.get_board_from_idx(parent_idx)
|
||||
.expect("unable to get board");
|
||||
|
||||
// use [`Board::all_positions`] here instead of [`Board::possible_moves`]
|
||||
// because we use [`Board::what_if`] later and we want to reduce calls to [`Board::propegate_from_dry`]
|
||||
let mut new: Vec<Move> = Board::all_positions()
|
||||
.flat_map(|coord| {
|
||||
parent
|
||||
.board
|
||||
parent_board
|
||||
.what_if(coord, new_color)
|
||||
.map(move |x| (coord, x))
|
||||
})
|
||||
@@ -212,7 +217,7 @@ impl FutureMoves {
|
||||
.collect();
|
||||
|
||||
if new.is_empty() {
|
||||
new.push(Move::new(None, parent.board, new_color, self.agent_color));
|
||||
new.push(Move::new(None, parent_board, new_color, self.agent_color));
|
||||
}
|
||||
|
||||
let start_idx = self.arena.len();
|
||||
@@ -321,7 +326,7 @@ impl FutureMoves {
|
||||
|
||||
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;
|
||||
let mut board = self.board;
|
||||
for (m, c) in hist {
|
||||
if let Some(m) = m {
|
||||
board.place(m, c).expect("move would not propegate");
|
||||
@@ -361,7 +366,8 @@ impl FutureMoves {
|
||||
// match the agent_color usually root or great-grand child
|
||||
.filter(|&idx| self.depth_of(idx) % 2 == 0)
|
||||
.find(|&idx| {
|
||||
&self.arena[idx].board == board && self.arena[idx].color == !self.agent_color
|
||||
self.get_board_from_idx(idx).as_ref() == Some(board)
|
||||
&& self.arena[idx].color == !self.agent_color
|
||||
});
|
||||
|
||||
if let Some(curr_board_idx) = curr_board {
|
||||
@@ -577,7 +583,6 @@ mod tests {
|
||||
|
||||
futm.arena.push(Move {
|
||||
coord: None,
|
||||
board: Board::new(),
|
||||
winner: Winner::None,
|
||||
parent: None,
|
||||
children: Vec::new(),
|
||||
@@ -664,7 +669,6 @@ mod tests {
|
||||
|
||||
futm.arena.push(Move {
|
||||
coord: None,
|
||||
board: Board::new(),
|
||||
winner: Winner::None,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
@@ -705,7 +709,6 @@ mod tests {
|
||||
|
||||
futm.arena.push(Move {
|
||||
coord: None,
|
||||
board: Board::new(),
|
||||
winner: Winner::None,
|
||||
parent: None,
|
||||
children: vec![1],
|
||||
|
||||
Reference in New Issue
Block a user