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