From 03931365883562f616b3c9d88ad9d6003b9aa4ee Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Sat, 19 May 2018 13:36:58 -0700 Subject: [PATCH] Fix score calculation for park/climb when they exceed limits. --- game/score.go | 13 ++++++++++--- game/score_test.go | 17 +++++++++++++++++ game/test_helpers.go | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/game/score.go b/game/score.go index 624ebf8..96e979f 100644 --- a/game/score.go +++ b/game/score.go @@ -7,13 +7,13 @@ package game type Score struct { AutoRuns int - AutoEndSwitchOwnership bool AutoOwnershipPoints int + AutoEndSwitchOwnership bool TeleopOwnershipPoints int VaultCubes int Levitate bool - Parks int Climbs int + Parks int Fouls []Foul ElimDq bool } @@ -47,10 +47,17 @@ func (score *Score) Summarize(opponentFouls []Foul) *ScoreSummary { summary.OwnershipPoints = score.AutoOwnershipPoints + score.TeleopOwnershipPoints summary.VaultPoints = 5 * score.VaultCubes climbs := score.Climbs + if climbs > 3 { + climbs = 3 + } if score.Levitate && score.Climbs < 3 { climbs++ } - summary.ParkClimbPoints = 5*score.Parks + 30*climbs + parks := score.Parks + if parks+climbs > 3 { + parks = 3 - climbs + } + summary.ParkClimbPoints = 5*parks + 30*climbs // Calculate bonuses. if score.AutoRuns == 3 && score.AutoEndSwitchOwnership { diff --git a/game/score_test.go b/game/score_test.go index 967c034..a5f13e4 100644 --- a/game/score_test.go +++ b/game/score_test.go @@ -34,6 +34,23 @@ func TestScoreSummary(t *testing.T) { assert.Equal(t, true, blueSummary.AutoQuest) assert.Equal(t, false, blueSummary.FaceTheBoss) + // Test park/climb limits. + redScore.Levitate = false + redScore.Climbs = 3 + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Levitate = true + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Climbs = 4 + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Climbs = 50 + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Parks = 2 + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Parks = 25 + assert.Equal(t, 90, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + redScore.Climbs = 0 + assert.Equal(t, 40, redScore.Summarize(blueScore.Fouls).ParkClimbPoints) + // Test Auto Quest boundary conditions. blueScore.AutoEndSwitchOwnership = false assert.Equal(t, false, blueScore.Summarize(redScore.Fouls).AutoQuest) diff --git a/game/test_helpers.go b/game/test_helpers.go index de1b370..c233a13 100644 --- a/game/test_helpers.go +++ b/game/test_helpers.go @@ -8,11 +8,11 @@ package game func TestScore1() *Score { fouls := []Foul{{Rule{"G22", false}, 25, 25.2}, {Rule{"G18", true}, 25, 150}, {Rule{"G20", true}, 1868, 0}} - return &Score{1, true, 12, 47, 3, true, 0, 2, fouls, false} + return &Score{1, 12, true, 47, 3, true, 2, 0, fouls, false} } func TestScore2() *Score { - return &Score{3, true, 20, 73, 6, false, 1, 1, []Foul{}, false} + return &Score{3, 20, true, 73, 6, false, 1, 1, []Foul{}, false} } func TestRanking1() *Ranking {