Skip to content

Commit 53ecc77

Browse files
committed
Added lone king bishop knight draw
1 parent b69c825 commit 53ecc77

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/bot/eval.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@ pub fn evaluate_board(board: &Board) -> i32 {
3838
return if board.side_to_move() == White { -10_000 } else { 10_000 };
3939
}
4040

41+
// Count pieces for draw evaluation
42+
let mut white_pieces = vec![];
43+
let mut black_pieces = vec![];
44+
45+
for sq in chess::ALL_SQUARES {
46+
if let Some(piece) = board.piece_on(sq) {
47+
let color = board.color_on(sq).unwrap();
48+
if color == White {
49+
white_pieces.push(piece);
50+
} else {
51+
black_pieces.push(piece);
52+
}
53+
}
54+
}
55+
56+
let minor_or_lone = |pieces: &[Piece]| {
57+
match pieces {
58+
[King] => true,
59+
[King, Bishop] => true,
60+
[King, Knight] => true,
61+
[King, Knight, Knight] => true,
62+
_ => false,
63+
}
64+
};
65+
66+
// Case 1: Both sides have only king/king+bishop/knight/(2 knights)
67+
if minor_or_lone(&white_pieces) && minor_or_lone(&black_pieces) {
68+
return 0;
69+
}
70+
71+
// Case 2: One side has only king+bishop or king+knight; ignore its score
4172
let mut score: i32 = 0;
4273
let is_endgame = is_endgame(board);
4374

@@ -59,7 +90,6 @@ pub fn evaluate_board(board: &Board) -> i32 {
5990
King => 0,
6091
};
6192

62-
// Use table from GlobalMap
6393
let positional = match piece {
6494
Pawn => GlobalMap::PAWN_TABLE[row][col],
6595
Knight => GlobalMap::KNIGHT_TABLE[row][col],
@@ -78,9 +108,13 @@ pub fn evaluate_board(board: &Board) -> i32 {
78108
let value = base + positional;
79109

80110
if color == White {
81-
score += value;
111+
if !minor_or_lone(&white_pieces) {
112+
score += value;
113+
}
82114
} else {
83-
score -= value;
115+
if !minor_or_lone(&black_pieces) {
116+
score -= value;
117+
}
84118
}
85119
}
86120
}

0 commit comments

Comments
 (0)