Compare commits

...

3 Commits

Author SHA1 Message Date
Drake 4ad9875c01 deez
1 year ago
Drake a81bcb4689 deez nuts
1 year ago
Drake 0790e688ef Rewrite the entirety of board eval or something idk
1 year ago

1
.gitignore vendored

@ -1 +1,2 @@
/target
inkwell-regression-testing

137
Cargo.lock generated

@ -132,6 +132,49 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -241,8 +284,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
@ -251,6 +296,15 @@ version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec"
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "iana-time-zone"
version = "0.1.53"
@ -281,10 +335,23 @@ version = "0.1.0"
dependencies = [
"chess",
"itertools",
"minimax",
"rand 0.8.5",
"vampirc-uci",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "itertools"
version = "0.10.5"
@ -333,6 +400,28 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
dependencies = [
"autocfg",
]
[[package]]
name = "minimax"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e180da8406d20280b2b52d84d963cc3b89d67c36003ed09c4be7e99f0ba08009"
dependencies = [
"getrandom",
"instant",
"num_cpus",
"rand 0.8.5",
"rayon",
]
[[package]]
name = "miniz_oxide"
version = "0.6.2"
@ -367,6 +456,16 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "object"
version = "0.30.3"
@ -526,12 +625,40 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rayon"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"num_cpus",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.3"
@ -726,6 +853,16 @@ version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
[[package]]
name = "web-sys"
version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.9"

@ -14,5 +14,6 @@ codegen-units = 1
[dependencies]
chess = "3.2.0"
itertools = "0.10.5"
minimax = "0.5.1"
rand = "0.8.5"
vampirc-uci = { version = "0.11.1", features = ["chess"] }

@ -1,5 +1,5 @@
# 1.666.0-rc
- [ ] Ability to evaluate game state (whether it's early/mid/end-game)
- [ ] Piece tables
- [x] Ability to evaluate game state (whether it's early/mid/end-game)
- [x] Piece tables
- [ ] Draw prevention (via `chess`'s Game struct?)
- [ ] Basic king safety (ie castling when appropriate, not always playing the double triple decker bongcloud)

Binary file not shown.

Binary file not shown.

@ -20,4 +20,4 @@ pub const INFO: Info = Info {
};
// FIXME: this needs to be configurable via UCI
pub const depth: u8 = 6;
pub const DEPTH: u8 = 8;

@ -1,47 +1,139 @@
use rand::prelude::*;
use std::f64::{INFINITY, NEG_INFINITY};
use chess::{Board, BoardStatus, ChessMove, Color, MoveGen, Piece};
fn static_board_eval(
mov: ChessMove,
board: Board,
playing_as: Color,
move_history: Vec<(ChessMove, Board)>,
) -> f64 {
if move_history.len() > 6 {
if move_history[move_history.len() - 1].0 == mov
&& move_history[move_history.len() - 2].0 == mov
{
return -666.0;
use chess::{
Board as ChessBoard, BoardStatus, ChessMove, Color, File, MoveGen, Piece, Rank, Square,
};
use crate::piece_tables;
use crate::piece_values::get_piece_value;
fn square_to_index(square: Square, playing_as: Color) -> usize {
let mut idx = 0;
if playing_as == Color::White {
match square.get_rank() {
Rank::First => idx += 0,
Rank::Second => idx += 8,
Rank::Third => idx += 16,
Rank::Fourth => idx += 24,
Rank::Fifth => idx += 32,
Rank::Sixth => idx += 40,
Rank::Seventh => idx += 48,
Rank::Eighth => idx += 56,
};
match square.get_file() {
File::A => idx += 0,
File::B => idx += 1,
File::C => idx += 2,
File::D => idx += 3,
File::E => idx += 4,
File::F => idx += 5,
File::G => idx += 6,
File::H => idx += 7,
};
} else {
match square.get_rank() {
Rank::Eighth => idx += 0,
Rank::Seventh => idx += 8,
Rank::Sixth => idx += 16,
Rank::Fifth => idx += 24,
Rank::Fourth => idx += 32,
Rank::Third => idx += 40,
Rank::Second => idx += 48,
Rank::First => idx += 56,
};
match square.get_file() {
File::H => idx += 0,
File::G => idx += 1,
File::F => idx += 2,
File::E => idx += 3,
File::D => idx += 4,
File::C => idx += 5,
File::B => idx += 6,
File::A => idx += 7,
}
}
idx
}
let mut current_eval = 0.0;
fn evaluate_piece_square(board: ChessBoard, square: Square, playing_as: Color) -> (f64, f64, f64) {
let mut mg_value: f64 = 0.0;
let mut eg_value: f64 = 0.0;
let mut gamephase: f64 = 0.0;
// basic material counting
board.color_combined(playing_as).for_each(|square| {
match board.piece_on(square) {
Some(Piece::Pawn) => current_eval += 1.0,
Some(Piece::Knight) => current_eval += 3.0,
Some(Piece::Bishop) => current_eval += 5.0,
Some(Piece::Rook) => current_eval += 5.0,
Some(Piece::Queen) => current_eval += 8.0,
_ => { /* do nothing */ }
let piece = board.piece_on(square);
match piece {
Some(Piece::Pawn) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_PAWNS[square_to_index(square, playing_as)] / 10.0);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_PAWNS[square_to_index(square, playing_as)] / 10.0);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece).floor() as usize];
}
Some(Piece::Knight) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_HORSEYS[square_to_index(square, playing_as)] / 10.0);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_HORSEYS[square_to_index(square, playing_as)] / 10.0);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece).floor() as usize];
}
Some(Piece::Bishop) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_BISHOPS[square_to_index(square, playing_as)] / 10.0);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_BISHOPS[square_to_index(square, playing_as)] / 10.0);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece).floor() as usize];
}
Some(Piece::Rook) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_ROOKS[square_to_index(square, playing_as)] / 10.0);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_ROOKS[square_to_index(square, playing_as)] / 10.0);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece).floor() as usize];
}
Some(Piece::Queen) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_QUEENS[square_to_index(square, playing_as)] / 10.0);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_QUEENS[square_to_index(square, playing_as)] / 10.0);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece).floor() as usize];
}
Some(Piece::King) => {
mg_value += piece_tables::MIDGAME_KINGS[square_to_index(square, playing_as)] / 10.0;
eg_value += piece_tables::ENDGAME_KINGS[square_to_index(square, playing_as)] / 10.0;
}
None => {}
}
(mg_value, eg_value, gamephase)
}
fn static_board_eval(board: ChessBoard, playing_as: Color, move_history: Vec<ChessBoard>) -> f64 {
// basic material counting + midgame or endgame determination
let mut our_mg_value: f64 = 0.0;
let mut our_eg_value: f64 = 0.0;
let mut opponent_mg_value: f64 = 0.0;
let mut opponent_eg_value: f64 = 0.0;
let mut gamephase: f64 = 0.0;
board.color_combined(playing_as).for_each(|square| {
let tmp_gamephase;
(our_mg_value, our_eg_value, tmp_gamephase) =
evaluate_piece_square(board, square, playing_as);
gamephase += tmp_gamephase;
});
board.color_combined(!playing_as).for_each(|square| {
match board.piece_on(square) {
Some(Piece::Pawn) => current_eval -= 1.0,
Some(Piece::Knight) => current_eval -= 3.0,
Some(Piece::Bishop) => current_eval -= 5.0,
Some(Piece::Rook) => current_eval -= 5.0,
Some(Piece::Queen) => current_eval -= 8.0,
_ => { /* do nothing */ }
}
let tmp_gamephase;
(opponent_mg_value, opponent_eg_value, tmp_gamephase) =
evaluate_piece_square(board, square, !playing_as);
gamephase += tmp_gamephase;
});
let mg_score = our_mg_value - opponent_mg_value;
let eg_score = our_eg_value - opponent_eg_value;
let mg_phase = gamephase.min(24.0);
let eg_phase = 24.0 - mg_phase;
let mut current_eval = (mg_score * mg_phase + eg_score * eg_phase) / 24.0;
// checking heuristic
let mut are_we_in_check = false;
let mut is_opponent_in_check = false;
@ -60,97 +152,84 @@ fn static_board_eval(
.checkers()
.filter(|sq| board.color_on(*sq).unwrap() == !playing_as)
.for_each(|_| {
if !is_opponent_in_check
&& move_history.len()
> *vec![10, 11, 12, 13, 14, 15]
.choose(&mut rand::thread_rng())
.unwrap() as usize
{
current_eval += 17.5;
if !is_opponent_in_check && move_history.len() > 10 {
current_eval += 5.0;
is_opponent_in_check = true;
} else {
current_eval += 3.5;
}
});
// deprioritize king movement
/* // deprioritize king movement
if board.piece_on(mov.get_source()).unwrap_or(Piece::Pawn) == Piece::King && !are_we_in_check {
current_eval -= 12.5;
}
// incentivize capturing if material value of capturer is lower than material value of captured
// FIXME: this should take into account whether a piece is protected at all (and if so let pieces be captured by ones of equal and above importance)
if let (Some(captured_piece), Some(capturing_piece)) = (
old_board.piece_on(mov.get_dest()),
old_board.piece_on(mov.get_source()),
) {
current_eval +=
(get_piece_value(Some(captured_piece)) - get_piece_value(Some(capturing_piece)))
} */
current_eval
}
pub fn eval_board(
board: Board,
is_maximizing_player: bool,
depth: u8,
move_history: Vec<(ChessMove, Board)>,
last_move: Option<ChessMove>,
original_playing_as: Color,
mut alpha: f64,
mut beta: f64,
) -> f64 {
let moves_iter = MoveGen::new_legal(&board).into_iter();
if depth == 0 || board.status() == BoardStatus::Checkmate {
return static_board_eval(
last_move.unwrap_or(move_history.last().unwrap().0),
board,
original_playing_as,
move_history,
);
} else {
if is_maximizing_player {
let mut max_eval = NEG_INFINITY;
for mov in moves_iter {
let mut new_move_history = move_history.clone();
let new_board = board.make_move_new(mov);
new_move_history.push((mov, new_board));
let eval = eval_board(
new_board,
false,
depth - 1,
new_move_history,
Some(mov),
original_playing_as,
alpha,
beta,
);
max_eval = max_eval.max(eval);
alpha = alpha.max(eval);
if beta <= alpha {
break;
}
}
return max_eval;
} else {
let mut min_eval = INFINITY;
for mov in moves_iter {
let mut new_move_history = move_history.clone();
let new_board = board.make_move_new(mov);
new_move_history.push((mov, new_board));
let eval = eval_board(
new_board,
true,
depth - 1,
new_move_history,
Some(mov),
original_playing_as,
alpha,
beta,
);
min_eval = min_eval.min(eval);
beta = beta.min(eval);
if beta <= alpha {
break;
}
}
return min_eval;
#[derive(Clone)]
pub struct Board {
pub current_board: ChessBoard,
pub board_history: Vec<ChessBoard>,
}
pub struct Game;
impl minimax::Game for Game {
type S = Board;
type M = ChessMove;
fn generate_moves(state: &Self::S, moves: &mut Vec<Self::M>) {
let iter = MoveGen::new_legal(&state.current_board);
for mov in iter {
moves.push(mov)
}
}
fn get_winner(b: &Board) -> Option<minimax::Winner> {
match b.current_board.status() {
BoardStatus::Ongoing => None,
BoardStatus::Stalemate => Some(minimax::Winner::Draw),
BoardStatus::Checkmate => Some(minimax::Winner::PlayerJustMoved),
}
}
fn apply(b: &mut Board, m: ChessMove) -> Option<Board> {
let mut new_board_history = b.board_history.clone();
new_board_history.push(b.current_board);
Some(Board {
current_board: b.current_board.make_move_new(m),
board_history: new_board_history,
})
}
fn zobrist_hash(b: &Board) -> u64 {
b.current_board.get_hash()
}
}
#[derive(Default, Clone)]
pub struct Evaluator;
impl minimax::Evaluator for Evaluator {
type G = Game;
fn evaluate(&self, b: &Board) -> minimax::Evaluation {
static_board_eval(
b.current_board,
b.current_board.side_to_move(),
b.board_history.clone(),
) as i16
}
}

@ -1,25 +1,25 @@
mod config;
mod eval;
mod piece_tables;
mod piece_values;
use chess::{Board, ChessMove, MoveGen};
use chess::Board;
use config::INFO;
use eval::eval_board;
use itertools::Itertools;
use eval::{Board as EvalBoard, Evaluator};
use minimax::{IterativeOptions, ParallelOptions, ParallelSearch, Strategy};
use std::collections::HashMap;
use std::f64::{INFINITY, NEG_INFINITY};
use std::io::{self, BufRead};
use std::process;
use std::str::FromStr;
use vampirc_uci::parse_one;
use vampirc_uci::{UciMessage, UciOptionConfig, UciTimeControl};
use crate::config::depth;
use crate::config::DEPTH;
fn main() {
let _rng = rand::thread_rng();
let mut board: Option<Board> = None;
let mut move_history: Vec<(ChessMove, Board)> = vec![];
let mut move_history: Vec<Board> = vec![];
for line in io::stdin().lock().lines() {
let msg: UciMessage = parse_one(&line.unwrap());
match msg {
@ -94,71 +94,21 @@ fn main() {
}
if let Some(board) = board {
let color = board.side_to_move();
let moves = MoveGen::new_legal(&board);
let iter = moves.map(|mov| (mov, board.make_move_new(mov)));
let mut moves_hash_map = HashMap::new();
let mut sorted_moves = iter.sorted_by(|a, b| {
if !moves_hash_map.contains_key(a) {
moves_hash_map.insert(
*a,
eval_board(
a.1,
true,
depth,
move_history.clone(),
if move_history.len() > 0 {
Some(move_history.last().unwrap().0)
} else {
None
},
color,
NEG_INFINITY,
INFINITY,
),
);
}
if !moves_hash_map.contains_key(b) {
moves_hash_map.insert(
*b,
eval_board(
b.1,
true,
depth,
move_history.clone(),
None,
color,
NEG_INFINITY,
INFINITY,
),
);
}
let a_eval = moves_hash_map.get(a).unwrap();
let b_eval = moves_hash_map.get(b).unwrap();
b_eval.total_cmp(a_eval)
});
let best_move = sorted_moves.next().unwrap();
let worst_move = sorted_moves.last().unwrap_or(best_move);
move_history.push(best_move);
eprintln!(
"best move: {}, {}",
best_move.0,
moves_hash_map.get(&best_move).unwrap_or(&0.0)
);
eprintln!(
"worst move: {}, {}",
worst_move.0,
moves_hash_map.get(&worst_move).unwrap_or(&0.0)
let mut strat = ParallelSearch::new(
Evaluator::default(),
IterativeOptions::new().verbose(),
ParallelOptions::new().with_background_pondering(),
);
println!("bestmove {}", best_move.0);
strat.set_max_depth(DEPTH);
let mov = strat
.choose_move(&EvalBoard {
current_board: board,
board_history: move_history.clone(),
})
.unwrap();
println!("bestmove {}", mov);
}
}
UciMessage::Stop => {

@ -0,0 +1,147 @@
// piece tables originally sourced from https://www.talkchess.com/forum3/viewtopic.php?f=2&t=68311&start=19 via https://www.chessprogramming.org/PeSTO%27s_Evaluation_Function
pub const GAMEPHASE: [f64; 12] = [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0];
#[rustfmt::skip]
pub const MIDGAME_PAWNS: [f64; 64] = [
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
98.0, 134.0, 61.0, 95.0, 68.0, 126.0, 34.0, -11.0,
-6.0, 7.0, 26.0, 31.0, 65.0, 56.0, 25.0, -20.0,
-14.0, 13.0, 6.0, 21.0, 23.0, 12.0, 17.0, -23.0,
-27.0, -2.0, -5.0, 12.0, 17.0, 6.0, 10.0, -25.0,
-26.0, -4.0, -4.0, -10.0, 3.0, 3.0, 33.0, -12.0,
-35.0, -1.0, -20.0, -23.0, -15.0, 24.0, 38.0, -22.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
];
#[rustfmt::skip]
pub const ENDGAME_PAWNS: [f64; 64] = [
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
178.0, 173.0, 158.0, 134.0, 147.0, 132.0, 165.0, 187.0,
94.0, 100.0, 85.0, 67.0, 56.0, 53.0, 82.0, 84.0,
32.0, 24.0, 13.0, 5.0, -2.0, 4.0, 17.0, 17.0,
13.0, 9.0, -3.0, -7.0, -7.0, -8.0, 3.0, -1.0,
4.0, 7.0, -6.0, 1.0, 0.0, -5.0, -1.0, -8.0,
13.0, 8.0, 8.0, 10.0, 13.0, 0.0, 2.0, -7.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
];
#[rustfmt::skip]
pub const MIDGAME_HORSEYS: [f64; 64] = [
-167.0, -89.0, -34.0, -49.0, 61.0, -97.0, -15.0, -107.0,
-73.0, -41.0, 72.0, 36.0, 23.0, 62.0, 7.0, -17.0,
-47.0, 60.0, 37.0, 65.0, 84.0, 129.0, 73.0, 44.0,
-9.0, 17.0, 19.0, 53.0, 37.0, 69.0, 18.0, 22.0,
-13.0, 4.0, 16.0, 13.0, 28.0, 19.0, 21.0, -8.0,
-23.0, -9.0, 12.0, 10.0, 19.0, 17.0, 25.0, -16.0,
-29.0, -53.0, -12.0, -3.0, -1.0, 18.0, -14.0, -19.0,
-105.0, -21.0, -58.0, -33.0, -17.0, -28.0, -19.0, -23.0,
];
#[rustfmt::skip]
pub const ENDGAME_HORSEYS: [f64; 64] = [
-58.0, -38.0, -13.0, -28.0, -31.0, -27.0, -63.0, -99.0,
-25.0, -8.0, -25.0, -2.0, -9.0, -25.0, -24.0, -52.0,
-24.0, -20.0, 10.0, 9.0, -1.0, -9.0, -19.0, -41.0,
-17.0, 3.0, 22.0, 22.0, 22.0, 11.0, 8.0, -18.0,
-18.0, -6.0, 16.0, 25.0, 16.0, 17.0, 4.0, -18.0,
-23.0, -3.0, -1.0, 15.0, 10.0, -3.0, -20.0, -22.0,
-42.0, -20.0, -10.0, -5.0, -2.0, -20.0, -23.0, -44.0,
-29.0, -51.0, -23.0, -15.0, -22.0, -18.0, -50.0, -64.0,
];
#[rustfmt::skip]
pub const MIDGAME_BISHOPS: [f64; 64] = [
-29.0, 4.0, -82.0, -37.0, -25.0, -42.0, 7.0, -8.0,
-26.0, 16.0, -18.0, -13.0, 30.0, 59.0, 18.0, -47.0,
-16.0, 37.0, 43.0, 40.0, 35.0, 50.0, 37.0, -2.0,
-4.0, 5.0, 19.0, 50.0, 37.0, 37.0, 7.0, -2.0,
-6.0, 13.0, 13.0, 26.0, 34.0, 12.0, 10.0, 4.0,
0.0, 15.0, 15.0, 15.0, 14.0, 27.0, 18.0, 10.0,
4.0, 15.0, 16.0, 0.0, 7.0, 21.0, 33.0, 1.0,
-33.0, -3.0, -14.0, -21.0, -13.0, -12.0, -39.0, -21.0,
];
#[rustfmt::skip]
pub const ENDGAME_BISHOPS: [f64; 64] = [
-14.0, -21.0, -11.0, -8.0, -7.0, -9.0, -17.0, -24.0,
-8.0, -4.0, 7.0, -12.0, -3.0, -13.0, -4.0, -14.0,
2.0, -8.0, 0.0, -1.0, -2.0, 6.0, 0.0, 4.0,
-3.0, 9.0, 12.0, 9.0, 14.0, 10.0, 3.0, 2.0,
-6.0, 3.0, 13.0, 19.0, 7.0, 10.0, -3.0, -9.0,
-12.0, -3.0, 8.0, 10.0, 13.0, 3.0, -7.0, -15.0,
-14.0, -18.0, -7.0, -1.0, 4.0, -9.0, -15.0, -27.0,
-23.0, -9.0, -23.0, -5.0, -9.0, -16.0, -5.0, -17.0,
];
#[rustfmt::skip]
pub const MIDGAME_ROOKS: [f64; 64] = [
32.0, 42.0, 32.0, 51.0, 63.0, 9.0, 31.0, 43.0,
27.0, 32.0, 58.0, 62.0, 80.0, 67.0, 26.0, 44.0,
-5.0, 19.0, 26.0, 36.0, 17.0, 45.0, 61.0, 16.0,
-24.0, -11.0, 7.0, 26.0, 24.0, 35.0, -8.0, -20.0,
-36.0, -26.0, -12.0, -1.0, 9.0, -7.0, 6.0, -23.0,
-45.0, -25.0, -16.0, -17.0, 3.0, 0.0, -5.0, -33.0,
-44.0, -16.0, -20.0, -9.0, -1.0, 11.0, -6.0, -71.0,
-19.0, -13.0, 1.0, 17.0, 16.0, 7.0, -37.0, -26.0,
];
#[rustfmt::skip]
pub const ENDGAME_ROOKS: [f64; 64] = [
13.0, 10.0, 18.0, 15.0, 12.0, 12.0, 8.0, 5.0,
11.0, 13.0, 13.0, 11.0, -3.0, 3.0, 8.0, 3.0,
7.0, 7.0, 7.0, 5.0, 4.0, -3.0, -5.0, -3.0,
4.0, 3.0, 13.0, 1.0, 2.0, 1.0, -1.0, 2.0,
3.0, 5.0, 8.0, 4.0, -5.0, -6.0, -8.0, -11.0,
-4.0, 0.0, -5.0, -1.0, -7.0, -12.0, -8.0, -16.0,
-6.0, -6.0, 0.0, 2.0, -9.0, -9.0, -11.0, -3.0,
-9.0, 2.0, 3.0, -1.0, -5.0, -13.0, 4.0, -20.0,
];
#[rustfmt::skip]
pub const MIDGAME_QUEENS: [f64; 64] = [
-28.0, 0.0, 29.0, 12.0, 59.0, 44.0, 43.0, 45.0,
-24.0, -39.0, -5.0, 1.0, -16.0, 57.0, 28.0, 54.0,
-13.0, -17.0, 7.0, 8.0, 29.0, 56.0, 47.0, 57.0,
-27.0, -27.0, -16.0, -16.0, -1.0, 17.0, -2.0, 1.0,
-9.0, -26.0, -9.0, -10.0, -2.0, -4.0, 3.0, -3.0,
-14.0, 2.0, -11.0, -2.0, -5.0, 2.0, 14.0, 5.0,
-35.0, -8.0, 11.0, 2.0, 8.0, 15.0, -3.0, 1.0,
-1.0, -18.0, -9.0, 10.0, -15.0, -25.0, -31.0, -50.0,
];
#[rustfmt::skip]
pub const ENDGAME_QUEENS: [f64; 64] = [
-9.0, 22.0, 22.0, 27.0, 27.0, 19.0, 10.0, 20.0,
-17.0, 20.0, 32.0, 41.0, 58.0, 25.0, 30.0, 0.0,
-20.0, 6.0, 9.0, 49.0, 47.0, 35.0, 19.0, 9.0,
3.0, 22.0, 24.0, 45.0, 57.0, 40.0, 57.0, 36.0,
-18.0, 28.0, 19.0, 47.0, 31.0, 34.0, 39.0, 23.0,
-16.0, -27.0, 15.0, 6.0, 9.0, 17.0, 10.0, 5.0,
-22.0, -23.0, -30.0, -16.0, -16.0, -23.0, -36.0, -32.0,
-33.0, -28.0, -22.0, -43.0, -5.0, -32.0, -20.0, -41.0,
];
#[rustfmt::skip]
pub const MIDGAME_KINGS: [f64; 64] = [
-65.0, 23.0, 16.0, -15.0, -56.0, -34.0, 2.0, 13.0,
29.0, -1.0, -20.0, -7.0, -8.0, -4.0, -38.0, -29.0,
-9.0, 24.0, 2.0, -16.0, -20.0, 6.0, 22.0, -22.0,
-17.0, -20.0, -12.0, -27.0, -30.0, -25.0, -14.0, -36.0,
-49.0, -1.0, -27.0, -39.0, -46.0, -44.0, -33.0, -51.0,
-14.0, -14.0, -22.0, -46.0, -44.0, -30.0, -15.0, -27.0,
1.0, 7.0, -8.0, -64.0, -43.0, -16.0, 9.0, 8.0,
-15.0, 36.0, 12.0, -54.0, 8.0, -28.0, 24.0, 14.0,
];
#[rustfmt::skip]
pub const ENDGAME_KINGS: [f64; 64] = [
-74.0, -35.0, -18.0, -18.0, -11.0, 15.0, 4.0, -17.0,
-12.0, 17.0, 14.0, 17.0, 17.0, 38.0, 23.0, 11.0,
10.0, 17.0, 23.0, 15.0, 20.0, 45.0, 44.0, 13.0,
-8.0, 22.0, 24.0, 27.0, 26.0, 33.0, 26.0, 3.0,
-18.0, -4.0, 21.0, 24.0, 27.0, 23.0, 9.0, -11.0,
-19.0, -3.0, 11.0, 21.0, 23.0, 16.0, 7.0, -9.0,
-27.0, -11.0, 4.0, 13.0, 14.0, 4.0, -5.0, -17.0,
-53.0, -34.0, -21.0, -11.0, -28.0, -14.0, -24.0, -43.0,
];

@ -0,0 +1,22 @@
use chess::Piece;
pub const PAWN: f64 = 1.0;
pub const HORSEY: f64 = 3.0;
pub const BISHOP: f64 = 5.0;
pub const ROOK: f64 = 5.5;
pub const QUEEN: f64 = 10.0;
pub fn get_piece_value(piece: Option<Piece>) -> f64 {
match piece {
Some(Piece::Pawn) => PAWN,
Some(Piece::Knight) => HORSEY,
Some(Piece::Bishop) => BISHOP,
Some(Piece::Rook) => ROOK,
Some(Piece::Queen) => QUEEN,
_ => 0.0,
}
}
Loading…
Cancel
Save