···196196197197/// Returns the current game state: A win, draw or neither.
198198pub fn state(game: Game) -> GameState {
199199- // TODO: Check for insufficient material
200199 use <- bool.guard(game.half_moves >= 50, Draw(FiftyMoves))
200200+ use <- bool.guard(
201201+ game.is_insufficient_material(game),
202202+ Draw(InsufficientMaterial),
203203+ )
201204 use <- bool.guard(
202205 game.is_threefold_repetition(game),
203206 Draw(ThreefoldRepetition),
···161161 SearchResult(0, cached_positions, hash.Exact, False),
162162 )
163163164164- // If we have reached fifty moves, the game is already a draw, so there's no
164164+ // Check for draw conditions. If it's a draw, the game is over so there's no
165165 // point searching further.
166166 use <- bool.guard(
167167- game.half_moves >= 50,
168168- SearchResult(0, cached_positions, hash.Exact, True),
169169- )
170170-171171- // Threefold repetition is also a draw
172172- use <- bool.guard(
173173- game.is_threefold_repetition(game),
167167+ game.half_moves >= 50
168168+ || game.is_threefold_repetition(game)
169169+ || game.is_insufficient_material(game),
174170 SearchResult(0, cached_positions, hash.Exact, True),
175171 )
176172