Skip to content

Commit

Permalink
Add consideration of playoff tiebreakers.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Aug 21, 2022
1 parent 0fdfc78 commit 20cb056
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 155 deletions.
14 changes: 7 additions & 7 deletions bracket/bracket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package bracket

import (
"github.com/Team254/cheesy-arena-lite/model"
"github.com/Team254/cheesy-arena-lite/game"
"github.com/Team254/cheesy-arena-lite/tournament"
"github.com/stretchr/testify/assert"
"testing"
Expand Down Expand Up @@ -96,8 +96,8 @@ func TestBracketUpdateTiming(t *testing.T) {
assert.Equal(t, int64(2200), matches[2].Time.Unix())
assert.Equal(t, int64(2800), matches[3].Time.Unix())
}
scoreMatch(database, "SF1-1", model.RedWonMatch)
scoreMatch(database, "SF1-2", model.BlueWonMatch)
scoreMatch(database, "SF1-1", game.RedWonMatch)
scoreMatch(database, "SF1-2", game.BlueWonMatch)
startTime = time.Unix(5000, 0)
assert.Nil(t, bracket.Update(database, &startTime))
matches, err = database.GetMatchesByType("elimination")
Expand Down Expand Up @@ -133,8 +133,8 @@ func TestBracketUpdateTeamPositions(t *testing.T) {
match2.Blue1, match2.Blue3 = 305, match2.Blue1
database.UpdateMatch(&match1)
database.UpdateMatch(&match2)
scoreMatch(database, "SF1-1", model.RedWonMatch)
scoreMatch(database, "SF2-1", model.BlueWonMatch)
scoreMatch(database, "SF1-1", game.RedWonMatch)
scoreMatch(database, "SF2-1", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, _ = database.GetMatchesByType("elimination")
if assert.Equal(t, 4, len(matches)) {
Expand All @@ -154,8 +154,8 @@ func TestBracketUpdateTeamPositions(t *testing.T) {
}

// Advance them to the finals and verify that the team position updates have been propagated.
scoreMatch(database, "SF1-2", model.RedWonMatch)
scoreMatch(database, "SF2-2", model.BlueWonMatch)
scoreMatch(database, "SF1-2", game.RedWonMatch)
scoreMatch(database, "SF2-2", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, _ = database.GetMatchesByType("elimination")
if assert.Equal(t, 6, len(matches)) {
Expand Down
52 changes: 26 additions & 26 deletions bracket/double_elimination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package bracket

import (
"github.com/Team254/cheesy-arena-lite/model"
"github.com/Team254/cheesy-arena-lite/game"
"github.com/Team254/cheesy-arena-lite/tournament"
"github.com/stretchr/testify/assert"
"testing"
Expand Down Expand Up @@ -50,13 +50,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 4, len(matches))

scoreMatch(database, "1", model.BlueWonMatch)
scoreMatch(database, "1", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 4, len(matches))

scoreMatch(database, "2", model.RedWonMatch)
scoreMatch(database, "2", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -65,13 +65,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
assertMatch(t, matches[5], "7", 8, 4)
}

scoreMatch(database, "3", model.RedWonMatch)
scoreMatch(database, "3", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 6, len(matches))

scoreMatch(database, "4", model.BlueWonMatch)
scoreMatch(database, "4", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -82,27 +82,27 @@ func TestDoubleEliminationProgression(t *testing.T) {
assertMatch(t, matches[7], "8", 3, 7)
}

scoreMatch(database, "5", model.BlueWonMatch)
scoreMatch(database, "5", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 8, len(matches))

scoreMatch(database, "6", model.BlueWonMatch)
scoreMatch(database, "6", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 8, len(matches))

scoreMatch(database, "7", model.BlueWonMatch)
scoreMatch(database, "7", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
if assert.Equal(t, 9, len(matches)) {
assertMatch(t, matches[8], "9", 8, 2)
}

scoreMatch(database, "8", model.RedWonMatch)
scoreMatch(database, "8", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -111,13 +111,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
assertMatch(t, matches[10], "12", 4, 3)
}

scoreMatch(database, "9", model.RedWonMatch)
scoreMatch(database, "9", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 11, len(matches))

scoreMatch(database, "10", model.RedWonMatch)
scoreMatch(database, "10", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -126,21 +126,21 @@ func TestDoubleEliminationProgression(t *testing.T) {
assertMatch(t, matches[11], "12", 4, 3)
}

scoreMatch(database, "11", model.BlueWonMatch)
scoreMatch(database, "11", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 12, len(matches))

scoreMatch(database, "12", model.RedWonMatch)
scoreMatch(database, "12", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
if assert.Equal(t, 13, len(matches)) {
assertMatch(t, matches[12], "13", 3, 7)
}

scoreMatch(database, "13", model.BlueWonMatch)
scoreMatch(database, "13", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -152,7 +152,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Equal(t, 0, bracket.Winner())
assert.Equal(t, 0, bracket.Finalist())

scoreMatch(database, "F-1", model.BlueWonMatch)
scoreMatch(database, "F-1", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -161,7 +161,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Equal(t, 0, bracket.Winner())
assert.Equal(t, 0, bracket.Finalist())

scoreMatch(database, "F-2", model.RedWonMatch)
scoreMatch(database, "F-2", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -172,7 +172,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Equal(t, 0, bracket.Winner())
assert.Equal(t, 0, bracket.Finalist())

scoreMatch(database, "F-3", model.TieMatch)
scoreMatch(database, "F-3", game.TieMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -183,7 +183,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Equal(t, 0, bracket.Winner())
assert.Equal(t, 0, bracket.Finalist())

scoreMatch(database, "F-4", model.TieMatch)
scoreMatch(database, "F-4", game.TieMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -194,7 +194,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
assert.Equal(t, 0, bracket.Winner())
assert.Equal(t, 0, bracket.Finalist())

scoreMatch(database, "F-5", model.BlueWonMatch)
scoreMatch(database, "F-5", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -215,23 +215,23 @@ func TestDoubleEliminationTie(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 4, len(matches))

scoreMatch(database, "1", model.TieMatch)
scoreMatch(database, "1", game.TieMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
if assert.Equal(t, 5, len(matches)) {
assertMatch(t, matches[4], "1-2", 1, 8)
}

scoreMatch(database, "1-2", model.TieMatch)
scoreMatch(database, "1-2", game.TieMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
if assert.Equal(t, 6, len(matches)) {
assertMatch(t, matches[5], "1-3", 1, 8)
}

scoreMatch(database, "1-3", model.RedWonMatch)
scoreMatch(database, "1-3", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -249,13 +249,13 @@ func TestDoubleEliminationChangeResult(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 4, len(matches))

scoreMatch(database, "1", model.BlueWonMatch)
scoreMatch(database, "1", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 4, len(matches))

scoreMatch(database, "2", model.RedWonMatch)
scoreMatch(database, "2", game.RedWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand All @@ -264,12 +264,12 @@ func TestDoubleEliminationChangeResult(t *testing.T) {
assertMatch(t, matches[5], "7", 8, 4)
}

scoreMatch(database, "2", model.MatchNotPlayed)
scoreMatch(database, "2", game.MatchNotPlayed)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Equal(t, 4, len(matches))

scoreMatch(database, "2", model.BlueWonMatch)
scoreMatch(database, "2", game.BlueWonMatch)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err = database.GetMatchesByType("elimination")
assert.Nil(t, err)
Expand Down
5 changes: 3 additions & 2 deletions bracket/matchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package bracket

import (
"fmt"
"github.com/Team254/cheesy-arena-lite/game"
"github.com/Team254/cheesy-arena-lite/model"
"strconv"
)
Expand Down Expand Up @@ -266,9 +267,9 @@ func (matchup *Matchup) update(database *model.Database) error {
}

// Check who won.
if match.Status == model.RedWonMatch {
if match.Status == game.RedWonMatch {
matchup.RedAllianceWins++
} else if match.Status == model.BlueWonMatch {
} else if match.Status == game.BlueWonMatch {
matchup.BlueAllianceWins++
}
}
Expand Down
Loading

0 comments on commit 20cb056

Please sign in to comment.