split off Move
This commit is contained in:
parent
c7aeb98026
commit
47faa2af75
@ -3,70 +3,9 @@ use indicatif::{ProgressIterator, ProgressStyle};
|
||||
use crate::{
|
||||
board::{Board, Winner},
|
||||
piece::Piece,
|
||||
r#move::Move,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Move {
|
||||
/// `i` position of move
|
||||
i: usize,
|
||||
|
||||
/// `j` position of move
|
||||
j: usize,
|
||||
|
||||
/// [`Board`] state after move is made
|
||||
board: Board,
|
||||
|
||||
/// Current winner of the match
|
||||
winner: Winner,
|
||||
|
||||
/// Index of this move's parent
|
||||
parent: Option<usize>,
|
||||
|
||||
/// Indices of this Move's Children
|
||||
children: Vec<usize>,
|
||||
|
||||
/// Value of this move
|
||||
value: i64,
|
||||
|
||||
color: Piece,
|
||||
|
||||
lazy_children: bool,
|
||||
}
|
||||
|
||||
impl Move {
|
||||
pub const fn coords(&self) -> (usize, usize) {
|
||||
(self.i, self.j)
|
||||
}
|
||||
|
||||
fn compute_self_value(&self, agent_color: Piece) -> i64 {
|
||||
if self.winner == Winner::Player(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
// NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move.
|
||||
// We shouldn't prune branches because we still need to always react to the opponent's moves
|
||||
return i64::MIN;
|
||||
} else if self.winner == Winner::Player(agent_color) {
|
||||
// results in a win for the agent
|
||||
return i64::MAX;
|
||||
} else if self.winner == Winner::Tie {
|
||||
// idk what a Tie should be valued?
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut self_value = self.board.net_score(agent_color) as i64;
|
||||
let corner_v_agent = Board::sides()
|
||||
.filter(|&(i, j)| self.board.get_piece(i, j, agent_color))
|
||||
.count() as i64;
|
||||
let corner_v_not_agent = Board::sides()
|
||||
.filter(|&(i, j)| self.board.get_piece(i, j, !agent_color))
|
||||
.count() as i64;
|
||||
|
||||
// make net-corner capture important
|
||||
self_value += (corner_v_agent - corner_v_not_agent) * 4;
|
||||
|
||||
self_value
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FutureMoves {
|
||||
/// Arena containing all [`Move`]
|
||||
arena: Vec<Move>,
|
||||
|
||||
@ -5,4 +5,5 @@ mod complexagent;
|
||||
pub mod future_moves;
|
||||
mod game;
|
||||
mod misc;
|
||||
mod r#move;
|
||||
pub mod piece;
|
||||
|
||||
@ -8,6 +8,7 @@ mod complexagent;
|
||||
pub mod future_moves;
|
||||
mod game;
|
||||
mod misc;
|
||||
mod r#move;
|
||||
mod piece;
|
||||
|
||||
fn main() {
|
||||
|
||||
66
src/move.rs
Normal file
66
src/move.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use crate::{
|
||||
board::{Board, Winner},
|
||||
piece::Piece,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Move {
|
||||
/// `i` position of move
|
||||
pub i: usize,
|
||||
|
||||
/// `j` position of move
|
||||
pub j: usize,
|
||||
|
||||
/// [`Board`] state after move is made
|
||||
pub board: Board,
|
||||
|
||||
/// Current winner of the match
|
||||
pub winner: Winner,
|
||||
|
||||
/// Index of this move's parent
|
||||
pub parent: Option<usize>,
|
||||
|
||||
/// Indices of this Move's Children
|
||||
pub children: Vec<usize>,
|
||||
|
||||
/// Value of this move
|
||||
pub value: i64,
|
||||
|
||||
pub color: Piece,
|
||||
|
||||
pub lazy_children: bool,
|
||||
}
|
||||
|
||||
impl Move {
|
||||
pub const fn coords(&self) -> (usize, usize) {
|
||||
(self.i, self.j)
|
||||
}
|
||||
|
||||
pub fn compute_self_value(&self, agent_color: Piece) -> i64 {
|
||||
if self.winner == Winner::Player(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
// NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move.
|
||||
// We shouldn't prune branches because we still need to always react to the opponent's moves
|
||||
return i64::MIN;
|
||||
} else if self.winner == Winner::Player(agent_color) {
|
||||
// results in a win for the agent
|
||||
return i64::MAX;
|
||||
} else if self.winner == Winner::Tie {
|
||||
// idk what a Tie should be valued?
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut self_value = self.board.net_score(agent_color) as i64;
|
||||
let corner_v_agent = Board::sides()
|
||||
.filter(|&(i, j)| self.board.get_piece(i, j, agent_color))
|
||||
.count() as i64;
|
||||
let corner_v_not_agent = Board::sides()
|
||||
.filter(|&(i, j)| self.board.get_piece(i, j, !agent_color))
|
||||
.count() as i64;
|
||||
|
||||
// make net-corner capture important
|
||||
self_value += (corner_v_agent - corner_v_not_agent) * 4;
|
||||
|
||||
self_value
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user