aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-09-03 19:29:54 +0300
committereug-vs <eugene@eug-vs.xyz>2023-09-03 19:29:54 +0300
commite2934b95cbad65bc89cbc285c3ece2124bf44a55 (patch)
tree99252dd59ee15cace85730f68db0cd85ea628330 /src/board/mod.rs
parent9927af55dd12bc5eca7ff17e9dbc2665c42fcfb7 (diff)
downloadchessnost-e2934b95cbad65bc89cbc285c3ece2124bf44a55.tar.gz
feat: improved scoring for (semi)dead positions
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r--src/board/mod.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs
index 1e4fd93..01a5b03 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -392,6 +392,27 @@ impl Board {
pub fn threefold_repetition(&self) -> bool {
self.positions.iter().filter(|&&p| p == self.hash).count() >= 3
}
+
+ pub fn is_theoretically_winnable(&self, color: Color) -> bool {
+ if [
+ Piece::Pawn,
+ Piece::Rook,
+ Piece::Queen,
+ ].iter().any(|&piece| {
+ self.piece_sets[piece.colored(color) as usize].pop_count() > 0
+ }) {
+ return true;
+ };
+
+ let minor_pieces = [
+ Piece::Knight,
+ Piece::Bishop,
+ ].iter().fold(0, |acc, &piece| {
+ acc + self.piece_sets[piece.colored(color) as usize].pop_count()
+ });
+
+ minor_pieces > 1
+ }
}