From 4407af62abf74d3d216268ad0302e699a0f96df0 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 6 Feb 2025 23:11:28 -0500 Subject: [PATCH] pathfinding test --- src/complexagent.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/complexagent.rs b/src/complexagent.rs index 74086df..46b0f77 100644 --- a/src/complexagent.rs +++ b/src/complexagent.rs @@ -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::() + } + 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 + 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