small tweaks
This commit is contained in:
parent
ed101f8968
commit
563726ffd5
@ -12,8 +12,8 @@ pub struct ComplexAgent {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl ComplexAgent {
|
impl ComplexAgent {
|
||||||
pub const fn new(color: Piece) -> Self {
|
pub const fn new(color: Piece) -> Self {
|
||||||
const MAX_DEPTH: usize = 14;
|
const MAX_DEPTH: usize = 9;
|
||||||
const NON_LAZY_DEPTH: usize = 8;
|
const NON_LAZY_DEPTH: usize = 9;
|
||||||
Self {
|
Self {
|
||||||
color,
|
color,
|
||||||
future_moves: FutureMoves::new(color, MAX_DEPTH, NON_LAZY_DEPTH),
|
future_moves: FutureMoves::new(color, MAX_DEPTH, NON_LAZY_DEPTH),
|
||||||
|
|||||||
@ -110,21 +110,37 @@ impl FutureMoves {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let new_color = !parent.color;
|
let new_color = !parent.color;
|
||||||
let mut new: Vec<Move> =
|
|
||||||
// use [`Board::all_positions`] here instead of [`Board::possible_moves`]
|
// 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`]
|
// because we use [`Board::what_if`] later and we want to reduce calls to [`Board::propegate_from_dry`]
|
||||||
Board::all_positions()
|
let mut new: Vec<Move> = Board::all_positions()
|
||||||
.flat_map(|(i, j)| parent.board.what_if(i, j, new_color).map(move |x| (i, j, x)))
|
.flat_map(|(i, j)| {
|
||||||
.map(|(i, j, new_board)| Move::new(i, j, new_board, new_color, lazy_children, self.agent_color, Some(parent_idx))).collect();
|
parent
|
||||||
|
.board
|
||||||
|
.what_if(i, j, new_color)
|
||||||
|
.map(move |x| (i, j, x))
|
||||||
|
})
|
||||||
|
.map(|(i, j, new_board)| {
|
||||||
|
Move::new(
|
||||||
|
i,
|
||||||
|
j,
|
||||||
|
new_board,
|
||||||
|
new_color,
|
||||||
|
lazy_children,
|
||||||
|
self.agent_color,
|
||||||
|
Some(parent_idx),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
// negative, because we want the max value to be at the first index
|
// negative, because we want the max value to be at the first index
|
||||||
// abs because we want the most EXTREME possible outcome (win or lose for example)
|
// abs because we want the most EXTREME possible outcome (win or lose for example)
|
||||||
new.sort_by_key(|x| -x.self_value.abs());
|
new.sort_by_key(|x| -x.self_value.abs());
|
||||||
|
|
||||||
// keep the TOP_K children `self.agent_color`-color moves
|
// keep the TOP_K children of their magnitude
|
||||||
const TOP_K_CHILDREN: usize = 2;
|
const TOP_K_CHILDREN: usize = 2;
|
||||||
|
|
||||||
// we want to keep only the best move of the agent
|
// we want to keep only the greatest magnitude moves
|
||||||
if lazy_children && new.len() > TOP_K_CHILDREN {
|
if lazy_children && new.len() > TOP_K_CHILDREN {
|
||||||
new.drain(TOP_K_CHILDREN..);
|
new.drain(TOP_K_CHILDREN..);
|
||||||
}
|
}
|
||||||
@ -204,8 +220,7 @@ impl FutureMoves {
|
|||||||
.map(|(i, &child)| self.arena[child].value * ((i + 1) as i128))
|
.map(|(i, &child)| self.arena[child].value * ((i + 1) as i128))
|
||||||
.sum::<i128>();
|
.sum::<i128>();
|
||||||
|
|
||||||
self.arena[idx].value =
|
self.arena[idx].value = self.arena[idx].self_value as i128 + children_value;
|
||||||
(self.arena[idx].self_value / (depth as i64)) as i128 + children_value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,8 @@ pub mod repr;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let player1 = complexagent::ComplexAgent::new(Piece::Black);
|
let player1 = complexagent::ComplexAgent::new(Piece::Black);
|
||||||
// let player2 = complexagent::ComplexAgent::new(Piece::White);
|
// let player2 = complexagent::ComplexAgent::new(Piece::White);
|
||||||
// let player2 = agent::ManualAgent::new(Piece::White);
|
let player2 = agent::ManualAgent::new(Piece::White);
|
||||||
let player2 = agent::RandomAgent::new(Piece::White);
|
// let player2 = agent::RandomAgent::new(Piece::White);
|
||||||
let mut game = Game::new(Box::new(player1), Box::new(player2));
|
let mut game = Game::new(Box::new(player1), Box::new(player2));
|
||||||
game.game_loop();
|
game.game_loop();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user