From a1bebf99c7a2a686950acc098675cec2ca9343e1 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 17 Dec 2023 20:10:24 -0800 Subject: [PATCH] Fix calculating hit score --- analysis.go | 2 +- board_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/analysis.go b/analysis.go index 7cc0c9f..fec9812 100644 --- a/analysis.go +++ b/analysis.go @@ -86,7 +86,7 @@ func (a *Analysis) _analyze() { } checkers := checkers(o, a.Board[move[1]]) if checkers == 1 { - hs += PseudoPips(o, move[1]) + hs += PseudoPips(a.player, move[1]) } a.Board = a.Board.Move(move[0], move[1], a.player).UseRoll(move[0], move[1], a.player) } diff --git a/board_test.go b/board_test.go index 0fe7b57..0b40bb9 100644 --- a/board_test.go +++ b/board_test.go @@ -96,6 +96,23 @@ func TestBlots(t *testing.T) { } } +func TestHitScore(t *testing.T) { + b := Board{0, 0, -2, -2, -2, 4, 0, -1, 0, 0, -2, 4, 0, -2, -1, 0, -2, 4, 0, 2, 0, 0, 0, 0, -1, 0, 1, 0, 4, 1, 0, 0, 1, 1, 1} + available, _ := b.Available(1) + analysis := make([]*Analysis, 0, AnalysisBufferSize) + b.Analyze(available, &analysis) + + expectedHits := []int{296, 341, 0, 296, 0, 296} + if len(analysis) != len(expectedHits) { + t.Errorf("unexpected analysis length: expected %d, got %d", len(expectedHits), len(analysis)) + } + for i, a := range analysis { + if a.hitScore != expectedHits[i] { + t.Errorf("unexpected hit score for analysis %d: expected %d, got %d", i, expectedHits[i], a.hitScore) + } + } +} + func TestAnalyze(t *testing.T) { b := NewBoard(false) b = b.Move(24, 23, 1)