changes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::{agent::Agent, board::Board, piece::Piece};
|
||||
use rayon::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Move {
|
||||
@@ -33,7 +32,7 @@ struct Move {
|
||||
|
||||
impl Move {
|
||||
fn compute_self_value(&self, agent_color: Piece, depth: usize) -> i64 {
|
||||
let mut self_value = self.captured as i64;
|
||||
let mut self_value = self.board.count(agent_color) as i64;
|
||||
|
||||
if self.winner == Some(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
@@ -43,8 +42,6 @@ impl Move {
|
||||
} else if self.winner == Some(agent_color) {
|
||||
// results in a win for the agent
|
||||
self_value = i64::MAX;
|
||||
} else if self.color != agent_color {
|
||||
self_value = -self_value;
|
||||
}
|
||||
|
||||
self_value / depth as i64
|
||||
@@ -87,24 +84,24 @@ impl FutureMoves {
|
||||
color: Piece,
|
||||
remaining_depth: usize,
|
||||
) {
|
||||
if remaining_depth == 0 {
|
||||
return;
|
||||
self.current_depth += remaining_depth;
|
||||
let mut next_nodes: Vec<usize> = nodes.collect();
|
||||
|
||||
let mut next_color = !color;
|
||||
|
||||
for _ in 0..remaining_depth {
|
||||
next_nodes = next_nodes
|
||||
.into_iter()
|
||||
.flat_map(|node_idx| {
|
||||
self.generate_children(
|
||||
Some(node_idx),
|
||||
&self.arena[node_idx].board.clone(),
|
||||
next_color,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
next_color = !next_color;
|
||||
}
|
||||
|
||||
let next_color = !color;
|
||||
|
||||
let next_nodes: Vec<usize> = nodes
|
||||
.flat_map(|node_idx| {
|
||||
self.generate_children(
|
||||
Some(node_idx),
|
||||
&self.arena[node_idx].board.clone(),
|
||||
next_color,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
self.current_depth += 1;
|
||||
self.extend_layers(next_nodes.into_iter(), next_color, remaining_depth - 1);
|
||||
}
|
||||
|
||||
fn generate_children(
|
||||
@@ -225,9 +222,9 @@ impl FutureMoves {
|
||||
let mut index_map = vec![None; self.arena.len()];
|
||||
|
||||
// PERF: reverse iterator to avoid unneeded `memcpy`s when deconstructing the Arena
|
||||
for (old_idx, keep) in retain.iter().enumerate().rev() {
|
||||
for (old_idx, keep) in retain.into_iter().enumerate().rev() {
|
||||
let mut node = self.arena.remove(old_idx);
|
||||
if *keep {
|
||||
if keep {
|
||||
index_map[old_idx] = Some(new_arena.len());
|
||||
|
||||
node.parent = node.parent.and_then(|p| index_map[p]);
|
||||
|
||||
Reference in New Issue
Block a user