Compare commits

...

7 Commits

Author SHA1 Message Date
Drake e35f1dc666 NO MORE RC BAYBEE
12 months ago
Drake f35413d395 fdsnhkjfsdjkoilklhj;fvjlki;fdg
12 months ago
Drake 607fc63f4f i don't even know
12 months ago
Drake a2dfb8b6c8 stuff
12 months ago
Drake 4ad9875c01 deez
12 months 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)

@ -15,9 +15,8 @@ impl Info<'_> {
pub const INFO: Info = Info {
name: "inkwell",
version: "0.666.0-rc",
version: "0.666.0",
author: "Bendy (real)",
};
// FIXME: this needs to be configurable via UCI
pub const depth: u8 = 6;
pub const DEFAULT_DEPTH: u8 = 7;

@ -1,47 +1,144 @@
use rand::prelude::*;
use std::f64::{INFINITY, NEG_INFINITY};
use chess::{
Board as ChessBoard, BoardStatus, ChessMove, Color, File, MoveGen, Piece, Rank, Square,
};
use chess::{Board, BoardStatus, ChessMove, Color, MoveGen, Piece};
use crate::piece_tables;
use crate::piece_values::get_piece_value;
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;
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) -> (i16, i16, i16) {
let mut mg_value: i16 = 0;
let mut eg_value: i16 = 0;
let mut gamephase: i16 = 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)]);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_PAWNS[square_to_index(square, playing_as)]);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece) as usize];
}
Some(Piece::Knight) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_HORSEYS[square_to_index(square, playing_as)]);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_HORSEYS[square_to_index(square, playing_as)]);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece) as usize];
}
Some(Piece::Bishop) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_BISHOPS[square_to_index(square, playing_as)]);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_BISHOPS[square_to_index(square, playing_as)]);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece) as usize];
}
Some(Piece::Rook) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_ROOKS[square_to_index(square, playing_as)]);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_ROOKS[square_to_index(square, playing_as)]);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece) as usize];
}
Some(Piece::Queen) => {
mg_value += get_piece_value(piece)
+ (piece_tables::MIDGAME_QUEENS[square_to_index(square, playing_as)]);
eg_value += get_piece_value(piece)
+ (piece_tables::ENDGAME_QUEENS[square_to_index(square, playing_as)]);
gamephase += piece_tables::GAMEPHASE[get_piece_value(piece) as usize];
}
Some(Piece::King) => {
mg_value += piece_tables::MIDGAME_KINGS[square_to_index(square, playing_as)];
eg_value += piece_tables::ENDGAME_KINGS[square_to_index(square, playing_as)];
}
None => {}
}
(mg_value, eg_value, gamephase)
}
fn static_board_eval(
board: ChessBoard,
playing_as: Color,
move_history: Vec<ChessBoard>,
last_move: ChessMove,
) -> i16 {
// basic material counting + midgame or endgame determination
let mut our_mg_value: i16 = 0;
let mut our_eg_value: i16 = 0;
let mut opponent_mg_value: i16 = 0;
let mut opponent_eg_value: i16 = 0;
let mut gamephase: i16 = 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);
let eg_phase = 24 - mg_phase;
let mut current_eval = (mg_score * mg_phase + eg_score * eg_phase) / 24 / 5;
// checking heuristic
let mut are_we_in_check = false;
let mut is_opponent_in_check = false;
@ -50,107 +147,91 @@ fn static_board_eval(
.filter(|sq| board.color_on(*sq).unwrap() == playing_as)
.for_each(|_| {
if !are_we_in_check {
current_eval -= 66.6;
current_eval -= 10;
are_we_in_check = true;
} else {
current_eval -= 12.5;
current_eval -= 7;
}
});
board
.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;
is_opponent_in_check = true;
} else {
current_eval += 3.5;
current_eval += 3;
}
});
// deprioritize king movement
if board.piece_on(mov.get_source()).unwrap_or(Piece::Pawn) == Piece::King && !are_we_in_check {
current_eval -= 12.5;
current_eval
}
#[derive(Clone)]
pub struct Board {
pub current_board: ChessBoard,
pub board_history: Vec<ChessBoard>,
pub last_move: ChessMove,
}
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)
}
}
current_eval
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,
last_move: m,
})
}
fn zobrist_hash(b: &Board) -> u64 {
b.current_board.get_hash()
}
}
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;
}
#[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(),
b.last_move.clone(),
)
}
fn generate_noisy_moves(&self, state: &Board, moves: &mut Vec<<Self::G as minimax::Game>::M>) {
let iter = MoveGen::new_legal(&state.current_board);
for mov in iter {
if let Some(_) = state.current_board.piece_on(mov.get_dest()) {
moves.push(mov)
}
return min_eval;
}
}
}

@ -1,42 +1,74 @@
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 std::{process, unimplemented};
use vampirc_uci::parse_one;
use vampirc_uci::{UciMessage, UciOptionConfig, UciTimeControl};
use crate::config::depth;
use crate::config::DEFAULT_DEPTH;
struct Options {
pub en_passant: bool,
pub depth: i64,
pub debug: bool,
}
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![];
let mut options: Options = Options {
en_passant: false,
depth: DEFAULT_DEPTH.into(),
debug: false,
};
for line in io::stdin().lock().lines() {
let msg: UciMessage = parse_one(&line.unwrap());
let line = line.unwrap();
let msg: UciMessage = parse_one(&line);
match msg {
UciMessage::Uci => {
println!(
"{}\n{}\n{}",
"{}\n{}\n{}\n{}",
UciMessage::Id {
name: Some(INFO.to_name()),
author: Some(INFO.to_author())
},
UciMessage::Option(UciOptionConfig::Check {
name: "EnPassant".to_owned(),
default: Some(false)
default: Some(options.en_passant)
}),
UciMessage::Option(UciOptionConfig::Spin {
name: "Depth".to_owned(),
default: Some(options.depth),
min: Some(0),
max: None
}),
UciMessage::UciOk {}
)
}
UciMessage::SetOption { name, value } => match name.as_str() {
"EnPassant" => {
options.en_passant = match value.as_deref().unwrap_or_default() {
"true" => true,
"false" => false,
_ => options.en_passant,
}
}
"Depth" => {
options.depth = value.unwrap_or_default().parse().unwrap_or(options.depth)
}
_ => unimplemented!(),
},
UciMessage::Debug(debug) => options.debug = debug,
UciMessage::IsReady => {
println!("{}", UciMessage::ReadyOk)
}
@ -94,71 +126,29 @@ 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()
.with_null_window_search(true)
.with_countermoves()
.with_countermove_history()
.with_singular_extension()
.with_quiescence_search_depth(2)
.with_table_byte_size(8 * 1024 * 1024 * 1024),
ParallelOptions::new().with_background_pondering(),
);
println!("bestmove {}", best_move.0);
strat.set_max_depth(DEFAULT_DEPTH);
let mov = strat
.choose_move(&EvalBoard {
current_board: board,
board_history: move_history.clone(),
last_move: Default::default(),
})
.unwrap();
println!("bestmove {}", mov);
}
}
UciMessage::Stop => {
@ -171,5 +161,8 @@ fn main() {
todo!("{}", msg.to_string())
}
}
if options.debug {
println!("{}\n", UciMessage::info_string(line))
}
}
}

@ -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: [i16; 12] = [0, 0, 1, 1, 1, 1, 2, 2, 4, 4, 0, 0];
#[rustfmt::skip]
pub const MIDGAME_PAWNS: [i16; 64] = [
0, 0, 0, 0, 0, 0, 0, 0,
98, 134, 61, 95, 68, 126, 34, -11,
-6, 7, 26, 31, 65, 56, 25, -20,
-14, 13, 6, 21, 23, 12, 17, -23,
-27, -2, -5, 12, 17, 6, 10, -25,
-26, -4, -4, -10, 3, 3, 33, -12,
-35, -1, -20, -23, -15, 24, 38, -22,
0, 0, 0, 0, 0, 0, 0, 0,
];
#[rustfmt::skip]
pub const ENDGAME_PAWNS: [i16; 64] = [
0, 0, 0, 0, 0, 0, 0, 0,
178, 173, 158, 134, 147, 132, 165, 187,
94, 100, 85, 67, 56, 53, 82, 84,
32, 24, 13, 5, -2, 4, 17, 17,
13, 9, -3, -7, -7, -8, 3, -1,
4, 7, -6, 1, 0, -5, -1, -8,
13, 8, 8, 10, 13, 0, 2, -7,
0, 0, 0, 0, 0, 0, 0, 0,
];
#[rustfmt::skip]
pub const MIDGAME_HORSEYS: [i16; 64] = [
-167, -89, -34, -49, 61, -97, -15, -107,
-73, -41, 72, 36, 23, 62, 7, -17,
-47, 60, 37, 65, 84, 129, 73, 44,
-9, 17, 19, 53, 37, 69, 18, 22,
-13, 4, 16, 13, 28, 19, 21, -8,
-23, -9, 12, 10, 19, 17, 25, -16,
-29, -53, -12, -3, -1, 18, -14, -19,
-105, -21, -58, -33, -17, -28, -19, -23,
];
#[rustfmt::skip]
pub const ENDGAME_HORSEYS: [i16; 64] = [
-58, -38, -13, -28, -31, -27, -63, -99,
-25, -8, -25, -2, -9, -25, -24, -52,
-24, -20, 10, 9, -1, -9, -19, -41,
-17, 3, 22, 22, 22, 11, 8, -18,
-18, -6, 16, 25, 16, 17, 4, -18,
-23, -3, -1, 15, 10, -3, -20, -22,
-42, -20, -10, -5, -2, -20, -23, -44,
-29, -51, -23, -15, -22, -18, -50, -64,
];
#[rustfmt::skip]
pub const MIDGAME_BISHOPS: [i16; 64] = [
-29, 4, -82, -37, -25, -42, 7, -8,
-26, 16, -18, -13, 30, 59, 18, -47,
-16, 37, 43, 40, 35, 50, 37, -2,
-4, 5, 19, 50, 37, 37, 7, -2,
-6, 13, 13, 26, 34, 12, 10, 4,
0, 15, 15, 15, 14, 27, 18, 10,
4, 15, 16, 0, 7, 21, 33, 1,
-33, -3, -14, -21, -13, -12, -39, -21,
];
#[rustfmt::skip]
pub const ENDGAME_BISHOPS: [i16; 64] = [
-14, -21, -11, -8, -7, -9, -17, -24,
-8, -4, 7, -12, -3, -13, -4, -14,
2, -8, 0, -1, -2, 6, 0, 4,
-3, 9, 12, 9, 14, 10, 3, 2,
-6, 3, 13, 19, 7, 10, -3, -9,
-12, -3, 8, 10, 13, 3, -7, -15,
-14, -18, -7, -1, 4, -9, -15, -27,
-23, -9, -23, -5, -9, -16, -5, -17,
];
#[rustfmt::skip]
pub const MIDGAME_ROOKS: [i16; 64] = [
32, 42, 32, 51, 63, 9, 31, 43,
27, 32, 58, 62, 80, 67, 26, 44,
-5, 19, 26, 36, 17, 45, 61, 16,
-24, -11, 7, 26, 24, 35, -8, -20,
-36, -26, -12, -1, 9, -7, 6, -23,
-45, -25, -16, -17, 3, 0, -5, -33,
-44, -16, -20, -9, -1, 11, -6, -71,
-19, -13, 1, 17, 16, 7, -37, -26,
];
#[rustfmt::skip]
pub const ENDGAME_ROOKS: [i16; 64] = [
13, 10, 18, 15, 12, 12, 8, 5,
11, 13, 13, 11, -3, 3, 8, 3,
7, 7, 7, 5, 4, -3, -5, -3,
4, 3, 13, 1, 2, 1, -1, 2,
3, 5, 8, 4, -5, -6, -8, -11,
-4, 0, -5, -1, -7, -12, -8, -16,
-6, -6, 0, 2, -9, -9, -11, -3,
-9, 2, 3, -1, -5, -13, 4, -20,
];
#[rustfmt::skip]
pub const MIDGAME_QUEENS: [i16; 64] = [
-28, 0, 29, 12, 59, 44, 43, 45,
-24, -39, -5, 1, -16, 57, 28, 54,
-13, -17, 7, 8, 29, 56, 47, 57,
-27, -27, -16, -16, -1, 17, -2, 1,
-9, -26, -9, -10, -2, -4, 3, -3,
-14, 2, -11, -2, -5, 2, 14, 5,
-35, -8, 11, 2, 8, 15, -3, 1,
-1, -18, -9, 10, -15, -25, -31, -50,
];
#[rustfmt::skip]
pub const ENDGAME_QUEENS: [i16; 64] = [
-9, 22, 22, 27, 27, 19, 10, 20,
-17, 20, 32, 41, 58, 25, 30, 0,
-20, 6, 9, 49, 47, 35, 19, 9,
3, 22, 24, 45, 57, 40, 57, 36,
-18, 28, 19, 47, 31, 34, 39, 23,
-16, -27, 15, 6, 9, 17, 10, 5,
-22, -23, -30, -16, -16, -23, -36, -32,
-33, -28, -22, -43, -5, -32, -20, -41,
];
#[rustfmt::skip]
pub const MIDGAME_KINGS: [i16; 64] = [
-65, 23, 16, -15, -56, -34, 2, 13,
29, -1, -20, -7, -8, -4, -38, -29,
-9, 24, 2, -16, -20, 6, 22, -22,
-17, -20, -12, -27, -30, -25, -14, -36,
-49, -1, -27, -39, -46, -44, -33, -51,
-14, -14, -22, -46, -44, -30, -15, -27,
1, 7, -8, -64, -43, -16, 9, 8,
-15, 36, 12, -54, 8, -28, 24, 14,
];
#[rustfmt::skip]
pub const ENDGAME_KINGS: [i16; 64] = [
-74, -35, -18, -18, -11, 15, 4, -17,
-12, 17, 14, 17, 17, 38, 23, 11,
10, 17, 23, 15, 20, 45, 44, 13,
-8, 22, 24, 27, 26, 33, 26, 3,
-18, -4, 21, 24, 27, 23, 9, -11,
-19, -3, 11, 21, 23, 16, 7, -9,
-27, -11, 4, 13, 14, 4, -5, -17,
-53, -34, -21, -11, -28, -14, -24, -43,
];

@ -0,0 +1,22 @@
use chess::Piece;
pub const PAWN: i16 = 1;
pub const HORSEY: i16 = 3;
pub const BISHOP: i16 = 5;
pub const ROOK: i16 = 5;
pub const QUEEN: i16 = 10;
pub fn get_piece_value(piece: Option<Piece>) -> i16 {
match piece {
Some(Piece::Pawn) => PAWN,
Some(Piece::Knight) => HORSEY,
Some(Piece::Bishop) => BISHOP,
Some(Piece::Rook) => ROOK,
Some(Piece::Queen) => QUEEN,
_ => 0,
}
}
Loading…
Cancel
Save