Fix NaN error

This commit is contained in:
Trevor Slocum 2023-12-02 10:29:27 -08:00
parent bc5fe93e6a
commit 2a8f1687c4
2 changed files with 7 additions and 2 deletions

View file

@ -25,5 +25,5 @@ type Analysis struct {
}
func (a *Analysis) String() string {
return fmt.Sprintf("Moves: %s Score: %.2f - Score: %.2f Pips: %d Blots: %d Hits: %d / Score: %.2f Pips: %.2f Blots: %.2f Hits: %.2f", fmt.Sprint(a.Moves), a.Score, a.PlayerScore, a.Pips, a.Blots, a.Hits, a.OppScore, a.OppPips, a.OppBlots, a.OppHits)
return fmt.Sprintf("Moves: %s Score: %.2f - Score: %.2f Pips: %d Blots: %d Hits: %d / Score: %.2f Pips: %.2f Blots: %.2f Hits: %.2f Past: %v", fmt.Sprint(a.Moves), a.Score, a.PlayerScore, a.Pips, a.Blots, a.Hits, a.OppScore, a.OppPips, a.OppBlots, a.OppHits, a.past)
}

View file

@ -2,6 +2,7 @@ package tabula
import (
"log"
"math"
"sort"
"sync"
)
@ -500,11 +501,15 @@ func (b Board) Analyze(player int, available [][]int) []*Analysis {
oppScore += r.PlayerScore
count++
}
score := result[i].PlayerScore
if !math.IsNaN(oppScore) {
score += result[i].OppScore * WeightOppScore
}
result[i].OppPips = (oppPips / count)
result[i].OppBlots = (oppBlots / count)
result[i].OppHits = (oppHits / count)
result[i].OppScore = (oppScore / count)
result[i].Score = result[i].PlayerScore + result[i].OppScore*WeightOppScore
result[i].Score = score
}
}
sort.Slice(result, func(i, j int) bool {