Skip to content

Commit

Permalink
Initialize scores with infinity instead of arbitrarily large scores
Browse files Browse the repository at this point in the history
Also remove accidentally-added hash calls
  • Loading branch information
jameshochadel committed Mar 13, 2021
1 parent 3e2270b commit c39463f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions engines/alphabeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ func (e *AlphaBetaEngine) alphabeta(pos *chess.Position, depth int, maxPlayer bo
value: e.evaluatePosition(pos),
}
}
pos.Hash()

bestScore := &positionScore{}
var comparator func(float64, float64) float64

if maxPlayer {
bestScore.value = -9999
bestScore.value = math.Inf(-1)
comparator = math.Max
} else {
bestScore.value = 9999
bestScore.value = math.Inf(1)
comparator = math.Min
}

Expand Down
5 changes: 2 additions & 3 deletions engines/minimax.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ func (e *MinimaxEngine) minimax(pos *chess.Position, depth int, maxPlayer bool)
value: e.evaluatePosition(pos),
}
}
pos.Hash()

bestScore := &positionScore{}
var comparator func(float64, float64) float64

if maxPlayer {
bestScore.value = -9999
bestScore.value = math.Inf(-1)
comparator = math.Max
} else {
bestScore.value = 9999
bestScore.value = math.Inf(1)
comparator = math.Min
}

Expand Down

0 comments on commit c39463f

Please sign in to comment.