Skip to content

Commit aaae019

Browse files
committed
Add disqualification state distinct from a red card (closes #131).
1 parent 5d283e6 commit aaae019

5 files changed

+67
-13
lines changed

model/match_result.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func (matchResult *MatchResult) BlueScoreSummary() *game.ScoreSummary {
7676
func (matchResult *MatchResult) CorrectPlayoffScore() {
7777
matchResult.RedScore.PlayoffDq = false
7878
for _, card := range matchResult.RedCards {
79-
if card == "red" {
79+
if card == "red" || card == "dq" {
8080
matchResult.RedScore.PlayoffDq = true
8181
}
8282
}
8383
for _, card := range matchResult.BlueCards {
84-
if card == "red" {
84+
if card == "red" || card == "dq" {
8585
matchResult.BlueScore.PlayoffDq = true
8686
}
8787
}

templates/edit_match_result.html

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ <h6 class="fw-bold mb-2">Notes in Traps</h6>
216216
Red
217217
</label>
218218
</div>
219+
<div class="col-lg-2">
220+
<label>
221+
<input type="radio" name="{{"{{alliance}}"}}Team{{"{{team"}}{{$i}}{{"}}"}}Card" value="dq">
222+
DQ
223+
</label>
224+
</div>
219225
</div>
220226
</div>
221227
</div>

tournament/qualification_rankings.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ func CalculateTeamCards(database *model.Database, matchType model.MatchType) err
107107

108108
// Mark the team as having a yellow card if they got either a yellow or red in a previous match.
109109
for teamId, card := range matchResult.RedCards {
110-
if team, ok := teamsMap[teamId]; ok && card != "" {
110+
if team, ok := teamsMap[teamId]; ok && (card == "red" || card == "yellow") {
111111
team.YellowCard = true
112112
teamsMap[teamId] = team
113113
}
114114
}
115115
for teamId, card := range matchResult.BlueCards {
116-
if team, ok := teamsMap[teamId]; ok && card != "" {
116+
if team, ok := teamsMap[teamId]; ok && (card == "red" || card == "yellow") {
117117
team.YellowCard = true
118118
teamsMap[teamId] = team
119119
}
@@ -149,7 +149,7 @@ func addMatchResultToRankings(
149149
cards = matchResult.BlueCards
150150
}
151151
disqualified := false
152-
if card, ok := cards[strconv.Itoa(teamId)]; ok && card == "red" {
152+
if card, ok := cards[strconv.Itoa(teamId)]; ok && (card == "red" || card == "dq") {
153153
disqualified = true
154154
}
155155

tournament/qualification_rankings_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ func TestCalculateRankings(t *testing.T) {
104104

105105
}
106106

107+
func TestAddMatchResultToRankingsHandleCards(t *testing.T) {
108+
rankings := map[int]*game.Ranking{}
109+
matchResult := model.BuildTestMatchResult(1, 1)
110+
matchResult.RedCards = map[string]string{"1": "yellow", "2": "red", "3": "dq"}
111+
matchResult.BlueCards = map[string]string{"4": "red", "5": "dq", "6": "yellow"}
112+
addMatchResultToRankings(rankings, 1, matchResult, true)
113+
addMatchResultToRankings(rankings, 2, matchResult, true)
114+
addMatchResultToRankings(rankings, 3, matchResult, true)
115+
addMatchResultToRankings(rankings, 4, matchResult, false)
116+
addMatchResultToRankings(rankings, 5, matchResult, false)
117+
addMatchResultToRankings(rankings, 6, matchResult, false)
118+
assert.Equal(t, 0, rankings[1].Disqualifications)
119+
assert.Equal(t, 1, rankings[2].Disqualifications)
120+
assert.Equal(t, 1, rankings[3].Disqualifications)
121+
assert.Equal(t, 1, rankings[4].Disqualifications)
122+
assert.Equal(t, 1, rankings[5].Disqualifications)
123+
assert.Equal(t, 0, rankings[6].Disqualifications)
124+
}
125+
107126
// Sets up a schedule and results that touches on all possible variables.
108127
func setupMatchResultsForRankings(database *model.Database) {
109128
match1 := model.Match{Type: model.Qualification, TypeOrder: 1, Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,

web/match_play_test.go

+37-8
Original file line numberDiff line numberDiff line change
@@ -190,34 +190,56 @@ func TestCommitCards(t *testing.T) {
190190
web := setupTestWeb(t)
191191

192192
// Check that a yellow card sticks with a team.
193-
team := &model.Team{Id: 5}
194-
web.arena.Database.CreateTeam(team)
193+
team1 := &model.Team{Id: 3}
194+
team2 := &model.Team{Id: 5}
195+
web.arena.Database.CreateTeam(team1)
196+
web.arena.Database.CreateTeam(team2)
195197
match := &model.Match{Id: 0, Type: model.Qualification, Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
196198
assert.Nil(t, web.arena.Database.CreateMatch(match))
197199
matchResult := model.NewMatchResult()
198200
matchResult.MatchId = match.Id
201+
matchResult.RedCards = map[string]string{"3": "yellow"}
199202
matchResult.BlueCards = map[string]string{"5": "yellow"}
200203
err := web.commitMatchScore(match, matchResult, true)
201204
assert.Nil(t, err)
202-
team, _ = web.arena.Database.GetTeamById(5)
203-
assert.True(t, team.YellowCard)
205+
team1, _ = web.arena.Database.GetTeamById(3)
206+
assert.True(t, team1.YellowCard)
207+
team2, _ = web.arena.Database.GetTeamById(5)
208+
assert.True(t, team2.YellowCard)
204209

205210
// Check that editing a match result removes a yellow card from a team.
206211
matchResult = model.NewMatchResult()
207212
matchResult.MatchId = match.Id
208213
err = web.commitMatchScore(match, matchResult, true)
209214
assert.Nil(t, err)
210-
team, _ = web.arena.Database.GetTeamById(5)
211-
assert.False(t, team.YellowCard)
215+
team1, _ = web.arena.Database.GetTeamById(3)
216+
assert.False(t, team1.YellowCard)
217+
team2, _ = web.arena.Database.GetTeamById(5)
218+
assert.False(t, team2.YellowCard)
212219

213220
// Check that a red card causes a yellow card to stick with a team.
214221
matchResult = model.NewMatchResult()
215222
matchResult.MatchId = match.Id
223+
matchResult.RedCards = map[string]string{"3": "red"}
216224
matchResult.BlueCards = map[string]string{"5": "red"}
217225
err = web.commitMatchScore(match, matchResult, true)
218226
assert.Nil(t, err)
219-
team, _ = web.arena.Database.GetTeamById(5)
220-
assert.True(t, team.YellowCard)
227+
team1, _ = web.arena.Database.GetTeamById(3)
228+
assert.True(t, team1.YellowCard)
229+
team2, _ = web.arena.Database.GetTeamById(5)
230+
assert.True(t, team2.YellowCard)
231+
232+
// Check that a DQ does not cause a yellow card to stick with a team.
233+
matchResult = model.NewMatchResult()
234+
matchResult.MatchId = match.Id
235+
matchResult.RedCards = map[string]string{"3": "dq"}
236+
matchResult.BlueCards = map[string]string{"5": "dq"}
237+
err = web.commitMatchScore(match, matchResult, true)
238+
assert.Nil(t, err)
239+
team1, _ = web.arena.Database.GetTeamById(3)
240+
assert.False(t, team1.YellowCard)
241+
team2, _ = web.arena.Database.GetTeamById(5)
242+
assert.False(t, team2.YellowCard)
221243

222244
// Check that a red card in playoffs zeroes out the score.
223245
tournament.CreateTestAlliances(web.arena.Database, 2)
@@ -235,6 +257,13 @@ func TestCommitCards(t *testing.T) {
235257
assert.Nil(t, web.commitMatchScore(match, matchResult, true))
236258
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
237259
assert.NotEqual(t, 0, matchResult.BlueScoreSummary().Score)
260+
261+
// Check that a DQ in playoffs zeroes out the score.
262+
matchResult.RedCards = map[string]string{}
263+
matchResult.BlueCards = map[string]string{"5": "dq"}
264+
assert.Nil(t, web.commitMatchScore(match, matchResult, true))
265+
assert.NotEqual(t, 0, matchResult.RedScoreSummary().Score)
266+
assert.Equal(t, 0, matchResult.BlueScoreSummary().Score)
238267
}
239268

240269
func TestMatchPlayWebsocketCommands(t *testing.T) {

0 commit comments

Comments
 (0)