logic improvements
This commit is contained in:
parent
ff1ded0a74
commit
19b5b856db
@ -7,10 +7,11 @@ use othello::{
|
|||||||
fn extend_layers_no_pruning(depth: usize, arena_size: usize) -> usize {
|
fn extend_layers_no_pruning(depth: usize, arena_size: usize) -> usize {
|
||||||
let config = FutureMoveConfig {
|
let config = FutureMoveConfig {
|
||||||
max_depth: depth,
|
max_depth: depth,
|
||||||
min_arena_depth_sub: 4,
|
min_arena_depth_sub: 0,
|
||||||
top_k_children: 2,
|
top_k_children: 5,
|
||||||
up_to_minus: usize::MAX, // disable pruning
|
up_to_minus: 4,
|
||||||
max_arena_size: arena_size,
|
max_arena_size: arena_size,
|
||||||
|
do_not_prune: true,
|
||||||
};
|
};
|
||||||
let mut fut = FutureMoves::new(Piece::Black, config);
|
let mut fut = FutureMoves::new(Piece::Black, config);
|
||||||
fut.set_root_from_board(Board::new().starting_pos());
|
fut.set_root_from_board(Board::new().starting_pos());
|
||||||
|
|||||||
@ -41,6 +41,8 @@ pub struct FutureMoveConfig {
|
|||||||
/// Max size of the arena, will not generate more if
|
/// Max size of the arena, will not generate more if
|
||||||
/// the arena is of that size or bigger
|
/// the arena is of that size or bigger
|
||||||
pub max_arena_size: usize,
|
pub max_arena_size: usize,
|
||||||
|
|
||||||
|
pub do_not_prune: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FutureMoves {
|
impl FutureMoves {
|
||||||
@ -227,10 +229,7 @@ impl FutureMoves {
|
|||||||
.children
|
.children
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|&child| self.arena[child].value)
|
.flat_map(|&child| self.arena[child].value)
|
||||||
// sum values of children
|
.max()
|
||||||
.sum::<i128>()
|
|
||||||
// divide in order to calculate average value of all children
|
|
||||||
.checked_div(self.arena[idx].children.len() as i128)
|
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
// we use `depth` and divided `self_value` by it, idk if this is worth it
|
// we use `depth` and divided `self_value` by it, idk if this is worth it
|
||||||
@ -358,7 +357,9 @@ impl FutureMoves {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prune_bad_children(&mut self) {
|
fn prune_bad_children(&mut self) {
|
||||||
if self.config.max_depth > self.current_depth + self.config.min_arena_depth_sub {
|
if self.config.max_depth > (self.current_depth + self.config.min_arena_depth_sub)
|
||||||
|
|| self.config.do_not_prune
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,6 +470,7 @@ mod tests {
|
|||||||
top_k_children: 1,
|
top_k_children: 1,
|
||||||
up_to_minus: 0,
|
up_to_minus: 0,
|
||||||
max_arena_size: 100,
|
max_arena_size: 100,
|
||||||
|
do_not_prune: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -77,8 +77,8 @@ impl Move {
|
|||||||
|
|
||||||
/// Sort children of the [`Move`] by their self_value in `arena`
|
/// Sort children of the [`Move`] by their self_value in `arena`
|
||||||
pub fn sort_children(&mut self, arena: &[Move]) {
|
pub fn sort_children(&mut self, arena: &[Move]) {
|
||||||
// negative, because we want the max value to be at the first index
|
self.children.sort_by(|&a, &b| {
|
||||||
// abs because we want the most EXTREME possible outcome (win or lose for example)
|
arena[b].value.cmp(&arena[a].value) // Descending order for agent's max nodes
|
||||||
self.children.sort_by_key(|&i| -arena[i].self_value.abs());
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@ -14,24 +14,26 @@ fn main() {
|
|||||||
Piece::Black,
|
Piece::Black,
|
||||||
FutureMoveConfig {
|
FutureMoveConfig {
|
||||||
max_depth: 20,
|
max_depth: 20,
|
||||||
min_arena_depth_sub: 3,
|
min_arena_depth_sub: 14,
|
||||||
top_k_children: 2,
|
top_k_children: 2,
|
||||||
up_to_minus: usize::MAX, // disable pruning
|
up_to_minus: 10,
|
||||||
max_arena_size: 50_000_000,
|
max_arena_size: 50_000_000,
|
||||||
|
do_not_prune: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// let player2 = complexagent::ComplexAgent::new(
|
// let player2 = complexagent::ComplexAgent::new(
|
||||||
// Piece::White,
|
// Piece::White,
|
||||||
// FutureMoveConfig {
|
// FutureMoveConfig {
|
||||||
// max_depth: 20,
|
// max_depth: 20,
|
||||||
// min_arena_depth_sub: 3,
|
// min_arena_depth_sub: 14,
|
||||||
// top_k_children: 2,
|
// top_k_children: 2,
|
||||||
// up_to_minus: 5,
|
// up_to_minus: 10,
|
||||||
// max_arena_size: 2_000_000,
|
// max_arena_size: 50_000_000,
|
||||||
|
// do_not_prune: false,
|
||||||
// },
|
// },
|
||||||
// );
|
// );
|
||||||
|
|
||||||
let player2 = agent::ManualAgent::new(Piece::White);
|
let player2 = agent::ManualAgent::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