reduce size of ints that represent value
This commit is contained in:
parent
38ada710d9
commit
945ec934f5
@ -1,9 +1,9 @@
|
|||||||
use crate::repr::{Board, Piece, PosMap};
|
use crate::repr::{Board, Piece, PosMap};
|
||||||
|
|
||||||
pub struct BoardValueMap(PosMap<i64>);
|
pub struct BoardValueMap(PosMap<i16>);
|
||||||
|
|
||||||
impl BoardValueMap {
|
impl BoardValueMap {
|
||||||
pub fn board_value(&self, board: &Board, color: Piece) -> i64 {
|
pub fn board_value(&self, board: &Board, color: Piece) -> i16 {
|
||||||
Board::all_positions()
|
Board::all_positions()
|
||||||
.filter_map(|coord| board.get(coord).map(|p| (coord, p)))
|
.filter_map(|coord| board.get(coord).map(|p| (coord, p)))
|
||||||
.map(|(coord, pos_p)| (*self.0.get(coord), pos_p))
|
.map(|(coord, pos_p)| (*self.0.get(coord), pos_p))
|
||||||
@ -20,7 +20,7 @@ impl BoardValueMap {
|
|||||||
|
|
||||||
/// Weights from: https://repub.eur.nl/pub/7142/ei2005-47.pdf
|
/// Weights from: https://repub.eur.nl/pub/7142/ei2005-47.pdf
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
const POSITION_VALUES: [[i64; 8]; 8] = [
|
const POSITION_VALUES: [[i16; 8]; 8] = [
|
||||||
[100, -20, 10, 5, 5, 10, -20, 100],
|
[100, -20, 10, 5, 5, 10, -20, 100],
|
||||||
[-20, -50, -2, -2, -2, -2, -50, -20],
|
[-20, -50, -2, -2, -2, -2, -50, -20],
|
||||||
[10, -2, -1, -1, -1, -1, -2, 10],
|
[10, -2, -1, -1, -1, -1, -2, 10],
|
||||||
|
|||||||
@ -277,8 +277,8 @@ impl FutureMoves {
|
|||||||
let children_value = match self.config.children_eval_method {
|
let children_value = match self.config.children_eval_method {
|
||||||
ChildrenEvalMethod::Average => children_values
|
ChildrenEvalMethod::Average => children_values
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.sum::<i128>()
|
.sum::<i32>()
|
||||||
.checked_div(self.arena[idx].children.len() as i128),
|
.checked_div(self.arena[idx].children.len() as i32),
|
||||||
ChildrenEvalMethod::Max => children_values.into_iter().max(),
|
ChildrenEvalMethod::Max => children_values.into_iter().max(),
|
||||||
ChildrenEvalMethod::Min => children_values.into_iter().min(),
|
ChildrenEvalMethod::Min => children_values.into_iter().min(),
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ impl FutureMoves {
|
|||||||
// we should really setup some sort of ELO rating for each commit, playing them against
|
// we should really setup some sort of ELO rating for each commit, playing them against
|
||||||
// each other or something, could be cool to benchmark these more subjective things, not
|
// each other or something, could be cool to benchmark these more subjective things, not
|
||||||
// just performance (cycles/time wise)
|
// just performance (cycles/time wise)
|
||||||
self.arena[idx].value = Some(self.arena[idx].self_value as i128 + children_value);
|
self.arena[idx].value = Some(self.arena[idx].self_value as i32 + children_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,10 @@ pub struct Move {
|
|||||||
pub tried_children: bool,
|
pub tried_children: bool,
|
||||||
|
|
||||||
/// Value of this move (including children)
|
/// Value of this move (including children)
|
||||||
pub value: Option<i128>,
|
pub value: Option<i32>,
|
||||||
|
|
||||||
/// What is the inherit value of this move (not including children)
|
/// What is the inherit value of this move (not including children)
|
||||||
pub self_value: i64,
|
pub self_value: i16,
|
||||||
|
|
||||||
/// Which color made a move on this move?
|
/// Which color made a move on this move?
|
||||||
pub color: Piece,
|
pub color: Piece,
|
||||||
@ -55,15 +55,15 @@ impl Move {
|
|||||||
m
|
m
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_self_value(&self, agent_color: Piece) -> i64 {
|
fn compute_self_value(&self, agent_color: Piece) -> i16 {
|
||||||
if self.winner == Winner::Player(!agent_color) {
|
if self.winner == Winner::Player(!agent_color) {
|
||||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
// 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.
|
// 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
|
// We shouldn't prune branches because we still need to always react to the opponent's moves
|
||||||
return i64::MIN + 1;
|
return i16::MIN + 1;
|
||||||
} else if self.winner == Winner::Player(agent_color) {
|
} else if self.winner == Winner::Player(agent_color) {
|
||||||
// results in a win for the agent
|
// results in a win for the agent
|
||||||
return i64::MAX - 1;
|
return i16::MAX - 1;
|
||||||
}
|
}
|
||||||
// else if self.winner == Winner::Tie {
|
// else if self.winner == Winner::Tie {
|
||||||
// // idk what a Tie should be valued?
|
// // idk what a Tie should be valued?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user