Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

board.status() for mate checking #14

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/engine/search.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::engine::pv_table::PVTable;
use crate::engine::tt::TTFlag;
use crate::{constants::*, engine::eval, uci::SearchType};
use cozy_chess::{BitBoard, Board, Color, Move, Piece};
use cozy_chess::{BitBoard, Board, Color, GameStatus, Move, Piece};
use std::cmp::{max, min};
use std::time::Instant;

Expand Down Expand Up @@ -65,15 +65,17 @@ impl Search {
return eval::evaluate(board);
}

match board.status() {
GameStatus::Won => return ply as i16 - MATE,
GameStatus::Drawn => return 8 - (self.nodes as i16 & 7),
_ => (),
}

self.pv_table.length[ply as usize] = ply;
let hash_key = board.hash();
let root = ply == 0;

if !root {
if board.halfmove_clock() >= 100 {
return 0;
}

if self.repetition(board, hash_key) {
return 8 - (self.nodes as i16 & 7);
}
Expand Down Expand Up @@ -174,15 +176,6 @@ impl Search {
let mut move_list = movegen::all_moves(self, board, tt_move, ply);
let mut quiet_moves: Vec<Move> = vec![];

// Checkmates and stalemates
if move_list.is_empty() {
if in_check {
return ply as i16 - MATE;
} else {
return 0;
}
}

for i in 0..move_list.len() {
let mv = movegen::pick_move(&mut move_list, i);

Expand Down