pathfinding test
This commit is contained in:
parent
6143473c1d
commit
4407af62ab
@ -30,11 +30,11 @@ impl Move {
|
||||
}
|
||||
|
||||
fn value(&self, from_perspective_of: Piece) -> i64 {
|
||||
let captured_value = if from_perspective_of != self.color {
|
||||
-(self.captured as i64)
|
||||
} else {
|
||||
self.captured as i64
|
||||
};
|
||||
let mut captured_value = self.captured as i64;
|
||||
|
||||
if from_perspective_of != self.color {
|
||||
captured_value = -captured_value;
|
||||
}
|
||||
|
||||
let value = captured_value
|
||||
+ self
|
||||
@ -47,13 +47,17 @@ impl Move {
|
||||
value
|
||||
}
|
||||
|
||||
pub fn len(&self) -> u32 {
|
||||
self.next_move.len() as u32 + self.next_move.iter().map(Move::len).sum::<u32>()
|
||||
}
|
||||
|
||||
pub const fn coords(&self) -> (usize, usize) {
|
||||
(self.i, self.j)
|
||||
}
|
||||
|
||||
/// Cursed function to create a dummy move type from a color and board
|
||||
/// Used to bootstrap [`ComplexAgent`]
|
||||
pub fn from_board_color(color: Piece, board: &Board) -> Self {
|
||||
pub fn bootstrap(color: Piece, board: &Board) -> Self {
|
||||
Move {
|
||||
i: 0,
|
||||
j: 0,
|
||||
@ -90,12 +94,12 @@ fn problem_space(board: &Board, color: Piece) -> Box<dyn Iterator<Item = Move> +
|
||||
|
||||
impl Agent for ComplexAgent {
|
||||
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
|
||||
const LOOPS: usize = 5;
|
||||
const LOOPS: usize = 6;
|
||||
|
||||
let curr_move: Move = self
|
||||
.curr_move
|
||||
.take()
|
||||
.unwrap_or_else(|| Move::from_board_color(self.color, board));
|
||||
.unwrap_or_else(|| Move::bootstrap(self.color, board));
|
||||
|
||||
let mut other_player_move = curr_move
|
||||
.next_move
|
||||
@ -105,6 +109,7 @@ impl Agent for ComplexAgent {
|
||||
.expect("other player made an invalid move?");
|
||||
|
||||
other_player_move.populate_next_moves(LOOPS);
|
||||
println!("depth: {}", other_player_move.len());
|
||||
|
||||
self.curr_move = other_player_move
|
||||
.next_move
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user