Skip to content

Commit

Permalink
search: generate moves less often
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Jun 21, 2024
1 parent 3dddff9 commit 0ae3e93
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/search/negamax.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ func (s *NegamaxSearcher) doSearch(position chess.Position, alpha int, beta int,
extensions++
}

moves := position.GenerateMoves(chess.LegalMoveGeneration)
if len(moves) == 0 {
if inCheck {
return -evaluation.MateScore + ply
} else {
return evaluation.DrawScore
}
}

if depth == 0 {
if inCheck { // don't go in quiescence search when in check
return s.evaluator.AbsoluteEvaluation(&position)
Expand Down Expand Up @@ -202,6 +193,7 @@ func (s *NegamaxSearcher) doSearch(position chess.Position, alpha int, beta int,
}
}

moves := position.GenerateMoves(chess.LegalMoveGeneration)
slices.SortFunc(moves, func(m1, m2 chess.Move) int {
return cmp.Compare(s.scoreMove(position, m1, ply), s.scoreMove(position, m2, ply))
})
Expand Down Expand Up @@ -264,6 +256,14 @@ func (s *NegamaxSearcher) doSearch(position chess.Position, alpha int, beta int,
}
}

if len(moves) == 0 {
if inCheck {
return -evaluation.MateScore + ply
}

return evaluation.DrawScore
}

if !s.stop {
entry := NewTableEntry(position.Hash(), nodeType, bestMove, bestScore, depth, position.Plies())
s.ttable.Insert(position.Hash(), entry)
Expand Down

0 comments on commit 0ae3e93

Please sign in to comment.