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 {
|
||||
let config = FutureMoveConfig {
|
||||
max_depth: depth,
|
||||
min_arena_depth_sub: 4,
|
||||
top_k_children: 2,
|
||||
up_to_minus: usize::MAX, // disable pruning
|
||||
min_arena_depth_sub: 0,
|
||||
top_k_children: 5,
|
||||
up_to_minus: 4,
|
||||
max_arena_size: arena_size,
|
||||
do_not_prune: true,
|
||||
};
|
||||
let mut fut = FutureMoves::new(Piece::Black, config);
|
||||
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
|
||||
/// the arena is of that size or bigger
|
||||
pub max_arena_size: usize,
|
||||
|
||||
pub do_not_prune: bool,
|
||||
}
|
||||
|
||||
impl FutureMoves {
|
||||
@ -227,10 +229,7 @@ impl FutureMoves {
|
||||
.children
|
||||
.iter()
|
||||
.flat_map(|&child| self.arena[child].value)
|
||||
// sum values of children
|
||||
.sum::<i128>()
|
||||
// divide in order to calculate average value of all children
|
||||
.checked_div(self.arena[idx].children.len() as i128)
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
// 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -469,6 +470,7 @@ mod tests {
|
||||
top_k_children: 1,
|
||||
up_to_minus: 0,
|
||||
max_arena_size: 100,
|
||||
do_not_prune: true,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
||||
@ -77,8 +77,8 @@ impl Move {
|
||||
|
||||
/// Sort children of the [`Move`] by their self_value in `arena`
|
||||
pub fn sort_children(&mut self, arena: &[Move]) {
|
||||
// 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)
|
||||
self.children.sort_by_key(|&i| -arena[i].self_value.abs());
|
||||
self.children.sort_by(|&a, &b| {
|
||||
arena[b].value.cmp(&arena[a].value) // Descending order for agent's max nodes
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@ -14,24 +14,26 @@ fn main() {
|
||||
Piece::Black,
|
||||
FutureMoveConfig {
|
||||
max_depth: 20,
|
||||
min_arena_depth_sub: 3,
|
||||
min_arena_depth_sub: 14,
|
||||
top_k_children: 2,
|
||||
up_to_minus: usize::MAX, // disable pruning
|
||||
up_to_minus: 10,
|
||||
max_arena_size: 50_000_000,
|
||||
do_not_prune: false,
|
||||
},
|
||||
);
|
||||
// let player2 = complexagent::ComplexAgent::new(
|
||||
// Piece::White,
|
||||
// FutureMoveConfig {
|
||||
// max_depth: 20,
|
||||
// min_arena_depth_sub: 3,
|
||||
// min_arena_depth_sub: 14,
|
||||
// top_k_children: 2,
|
||||
// up_to_minus: 5,
|
||||
// max_arena_size: 2_000_000,
|
||||
// up_to_minus: 10,
|
||||
// max_arena_size: 50_000_000,
|
||||
// do_not_prune: false,
|
||||
// },
|
||||
// );
|
||||
|
||||
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));
|
||||
game.game_loop();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user