fiddling with the algo
This commit is contained in:
parent
4407af62ab
commit
366bba8426
@ -1,3 +1,5 @@
|
|||||||
|
use num::CheckedDiv;
|
||||||
|
|
||||||
use crate::{agent::Agent, board::Board, piece::Piece};
|
use crate::{agent::Agent, board::Board, piece::Piece};
|
||||||
|
|
||||||
pub struct ComplexAgent {
|
pub struct ComplexAgent {
|
||||||
@ -29,22 +31,31 @@ impl Move {
|
|||||||
.for_each(|x| x.populate_next_moves(i - 1));
|
.for_each(|x| x.populate_next_moves(i - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value(&self, from_perspective_of: Piece) -> i64 {
|
fn value(&self, agent_color: Piece, depth: usize) -> i64 {
|
||||||
let mut captured_value = self.captured as i64;
|
let mut captured_value = self.captured as i64;
|
||||||
|
|
||||||
if from_perspective_of != self.color {
|
if agent_color != self.color {
|
||||||
captured_value = -captured_value;
|
captured_value = -captured_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = captured_value
|
// Reduce value of capture based on depth of prediction
|
||||||
+ self
|
captured_value /= depth as i64;
|
||||||
|
|
||||||
|
let avg_next_move_value = (self
|
||||||
.next_move
|
.next_move
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.value(from_perspective_of))
|
.map(|x| x.value(agent_color, depth + 1))
|
||||||
.max()
|
.sum::<i64>()
|
||||||
|
.checked_div(self.next_move.len() as i64))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
value
|
captured_value + avg_next_move_value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn best_move(&self, agent_color: Piece) -> Option<&Move> {
|
||||||
|
self.next_move
|
||||||
|
.iter()
|
||||||
|
.max_by_key(|m| m.value(agent_color, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> u32 {
|
pub fn len(&self) -> u32 {
|
||||||
@ -111,10 +122,7 @@ impl Agent for ComplexAgent {
|
|||||||
other_player_move.populate_next_moves(LOOPS);
|
other_player_move.populate_next_moves(LOOPS);
|
||||||
println!("depth: {}", other_player_move.len());
|
println!("depth: {}", other_player_move.len());
|
||||||
|
|
||||||
self.curr_move = other_player_move
|
self.curr_move = other_player_move.best_move(self.color).cloned();
|
||||||
.next_move
|
|
||||||
.into_iter()
|
|
||||||
.max_by_key(|m| m.value(self.color));
|
|
||||||
|
|
||||||
self.curr_move.as_ref().map(Move::coords)
|
self.curr_move.as_ref().map(Move::coords)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user