Skip to content

Commit

Permalink
Update score and ranking models for 2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed May 13, 2024
1 parent 38580fa commit 69bcff2
Show file tree
Hide file tree
Showing 31 changed files with 775 additions and 1,305 deletions.
2 changes: 1 addition & 1 deletion field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (arena *Arena) LoadSettings() error {
arena.MatchTimingNotifier.Notify()

game.MelodyBonusThresholdWithoutCoop = settings.MelodyBonusThresholdWithoutCoop
game.MelodyBonusWithCoop = settings.MelodyBonusWithCoop
game.MelodyBonusThresholdWithCoop = settings.MelodyBonusThresholdWithCoop
game.AmplificationNoteLimit = settings.AmplificationNoteLimit
game.AmplificationDurationSec = settings.AmplificationDurationSec

Expand Down
49 changes: 20 additions & 29 deletions game/amp_speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import (
"time"
)

const bankedAmpNoteLimit = 2

type AmpSpeaker struct {
BankedAmpNotes int
CoopActivated bool
autoAmpNotes int
teleopAmpNotes int
autoSpeakerNotes int
teleopUnamplifiedSpeakerNotes int
teleopAmplifiedSpeakerNotes int
AutoAmpNotes int
TeleopAmpNotes int
AutoSpeakerNotes int
TeleopUnamplifiedSpeakerNotes int
TeleopAmplifiedSpeakerNotes int
lastAmplifiedTime time.Time
lastAmplifiedSpeakerNotes int
}
Expand All @@ -33,9 +31,9 @@ func (ampSpeaker *AmpSpeaker) UpdateState(
// Handle the autonomous period.
autoValidityCutoff := matchStartTime.Add(GetDurationToAutoEnd() + speakerAutoGracePeriodSec*time.Second)
if currentTime.Before(autoValidityCutoff) {
ampSpeaker.autoAmpNotes += newAmpNotes
ampSpeaker.AutoAmpNotes += newAmpNotes
ampSpeaker.BankedAmpNotes = min(ampSpeaker.BankedAmpNotes+newAmpNotes, bankedAmpNoteLimit)
ampSpeaker.autoSpeakerNotes += newSpeakerNotes
ampSpeaker.AutoSpeakerNotes += newSpeakerNotes

// Bail out to avoid exercising the teleop logic.
return
Expand All @@ -45,7 +43,7 @@ func (ampSpeaker *AmpSpeaker) UpdateState(
teleopAmpValidityCutoff := matchStartTime.Add(GetDurationToTeleopEnd())
if currentTime.Before(teleopAmpValidityCutoff) {
// Handle incoming Amp notes.
ampSpeaker.teleopAmpNotes += newAmpNotes
ampSpeaker.TeleopAmpNotes += newAmpNotes
if !ampSpeaker.isAmplified(currentTime, false) {
ampSpeaker.BankedAmpNotes = min(ampSpeaker.BankedAmpNotes+newAmpNotes, bankedAmpNoteLimit)
}
Expand All @@ -71,11 +69,11 @@ func (ampSpeaker *AmpSpeaker) UpdateState(
)
if currentTime.Before(teleopSpeakerValidityCutoff) {
for newSpeakerNotes > 0 && ampSpeaker.isAmplified(currentTime, true) {
ampSpeaker.teleopAmplifiedSpeakerNotes++
ampSpeaker.TeleopAmplifiedSpeakerNotes++
ampSpeaker.lastAmplifiedSpeakerNotes++
newSpeakerNotes--
}
ampSpeaker.teleopUnamplifiedSpeakerNotes += newSpeakerNotes
ampSpeaker.TeleopUnamplifiedSpeakerNotes += newSpeakerNotes
}
}

Expand All @@ -90,7 +88,7 @@ func (ampSpeaker *AmpSpeaker) AmplifiedTimeRemaining(currentTime time.Time) floa
// Returns true if the co-op window during the match is currently open.
func (ampSpeaker *AmpSpeaker) IsCoopWindowOpen(matchStartTime, currentTime time.Time) bool {
coopValidityCutoff := matchStartTime.Add(GetDurationToTeleopStart() + coopTeleopWindowSec*time.Second)
return MelodyBonusWithCoop > 0 && currentTime.Before(coopValidityCutoff)
return MelodyBonusThresholdWithCoop > 0 && currentTime.Before(coopValidityCutoff)
}

// Returns the total number of notes scored in the Amp and Speaker.
Expand All @@ -100,38 +98,31 @@ func (ampSpeaker *AmpSpeaker) TotalNotesScored() int {

// Returns the total points scored in the Amp and Speaker during the autonomous period.
func (ampSpeaker *AmpSpeaker) AutoNotePoints() int {
return 2*ampSpeaker.autoAmpNotes + 5*ampSpeaker.autoSpeakerNotes
}

// Returns the total points scored in the Amp and Speaker during the teleoperated period.
func (ampSpeaker *AmpSpeaker) TeleopNotePoints() int {
return ampSpeaker.teleopAmpNotes +
2*ampSpeaker.teleopUnamplifiedSpeakerNotes +
5*ampSpeaker.teleopAmplifiedSpeakerNotes
return 2*ampSpeaker.AutoAmpNotes + 5*ampSpeaker.AutoSpeakerNotes
}

// Returns the total points scored in the Amp.
func (ampSpeaker *AmpSpeaker) AmpPoints() int {
return 2*ampSpeaker.autoAmpNotes + ampSpeaker.teleopAmpNotes
return 2*ampSpeaker.AutoAmpNotes + ampSpeaker.TeleopAmpNotes
}

// Returns the total points scored in the Speaker.
func (ampSpeaker *AmpSpeaker) SpeakerPoints() int {
return 5*ampSpeaker.autoSpeakerNotes +
2*ampSpeaker.teleopUnamplifiedSpeakerNotes +
5*ampSpeaker.teleopAmplifiedSpeakerNotes
return 5*ampSpeaker.AutoSpeakerNotes +
2*ampSpeaker.TeleopUnamplifiedSpeakerNotes +
5*ampSpeaker.TeleopAmplifiedSpeakerNotes
}

// Returns the total number of notes scored in the Amp.
func (ampSpeaker *AmpSpeaker) ampNotesScored() int {
return ampSpeaker.autoAmpNotes + ampSpeaker.teleopAmpNotes
return ampSpeaker.AutoAmpNotes + ampSpeaker.TeleopAmpNotes
}

// Returns the total number of notes scored in the Speaker.
func (ampSpeaker *AmpSpeaker) speakerNotesScored() int {
return ampSpeaker.autoSpeakerNotes +
ampSpeaker.teleopUnamplifiedSpeakerNotes +
ampSpeaker.teleopAmplifiedSpeakerNotes
return ampSpeaker.AutoSpeakerNotes +
ampSpeaker.TeleopUnamplifiedSpeakerNotes +
ampSpeaker.TeleopAmplifiedSpeakerNotes
}

// Returns whether the Speaker should be counting new incoming notes as amplified.
Expand Down
25 changes: 12 additions & 13 deletions game/amp_speaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ var matchStartTime = time.Unix(10, 0)

func TestAmpSpeaker_CalculationMethods(t *testing.T) {
ampSpeaker := AmpSpeaker{
autoAmpNotes: 1,
teleopAmpNotes: 2,
autoSpeakerNotes: 3,
teleopUnamplifiedSpeakerNotes: 5,
teleopAmplifiedSpeakerNotes: 8,
AutoAmpNotes: 1,
TeleopAmpNotes: 2,
AutoSpeakerNotes: 3,
TeleopUnamplifiedSpeakerNotes: 5,
TeleopAmplifiedSpeakerNotes: 8,
}
assert.Equal(t, 3, ampSpeaker.ampNotesScored())
assert.Equal(t, 16, ampSpeaker.speakerNotesScored())
assert.Equal(t, 19, ampSpeaker.TotalNotesScored())
assert.Equal(t, 17, ampSpeaker.AutoNotePoints())
assert.Equal(t, 52, ampSpeaker.TeleopNotePoints())
assert.Equal(t, 4, ampSpeaker.AmpPoints())
assert.Equal(t, 65, ampSpeaker.SpeakerPoints())
}
Expand All @@ -33,11 +32,11 @@ func TestAmpSpeaker_MatchSequence(t *testing.T) {
assertAmpSpeaker := func(
autoAmpNotes, teleopAmpNotes, autoSpeakerNotes, teleopUnamplifiedSpeakerNotes, teleopAmplifiedSpeakerNotes int,
) {
assert.Equal(t, autoAmpNotes, ampSpeaker.autoAmpNotes)
assert.Equal(t, teleopAmpNotes, ampSpeaker.teleopAmpNotes)
assert.Equal(t, autoSpeakerNotes, ampSpeaker.autoSpeakerNotes)
assert.Equal(t, teleopUnamplifiedSpeakerNotes, ampSpeaker.teleopUnamplifiedSpeakerNotes)
assert.Equal(t, teleopAmplifiedSpeakerNotes, ampSpeaker.teleopAmplifiedSpeakerNotes)
assert.Equal(t, autoAmpNotes, ampSpeaker.AutoAmpNotes)
assert.Equal(t, teleopAmpNotes, ampSpeaker.TeleopAmpNotes)
assert.Equal(t, autoSpeakerNotes, ampSpeaker.AutoSpeakerNotes)
assert.Equal(t, teleopUnamplifiedSpeakerNotes, ampSpeaker.TeleopUnamplifiedSpeakerNotes)
assert.Equal(t, teleopAmplifiedSpeakerNotes, ampSpeaker.TeleopAmplifiedSpeakerNotes)
}

ampSpeaker.UpdateState(0, 0, false, false, matchStartTime, timeAfterStart(0))
Expand Down Expand Up @@ -171,7 +170,7 @@ func TestAmpSpeaker_MatchSequence(t *testing.T) {
assertAmpSpeaker(0, 1, 0, 0, 0)
assert.Equal(t, 1, ampSpeaker.BankedAmpNotes)
assert.Equal(t, true, ampSpeaker.IsCoopWindowOpen(matchStartTime, timeAfterStart(60)))
MelodyBonusWithCoop = 0
MelodyBonusThresholdWithCoop = 0
assert.Equal(t, false, ampSpeaker.IsCoopWindowOpen(matchStartTime, timeAfterStart(60)))
ampSpeaker.UpdateState(2, 0, false, true, matchStartTime, timeAfterStart(60))
assertAmpSpeaker(0, 2, 0, 0, 0)
Expand Down Expand Up @@ -217,7 +216,7 @@ func TestAmpSpeaker_MatchSequence(t *testing.T) {
assert.Equal(t, false, ampSpeaker.isAmplified(timeAfterStart(99.1), true))
assert.Equal(t, 0.0, ampSpeaker.AmplifiedTimeRemaining(timeAfterStart(99.1)))

// Restore global constants.
// Restore default settings.
AmplificationNoteLimit = 4
AmplificationDurationSec = 10

Expand Down
217 changes: 0 additions & 217 deletions game/grid.go

This file was deleted.

Loading

0 comments on commit 69bcff2

Please sign in to comment.