Skip to content

Commit dd937d3

Browse files
committed
Implement shootout procedure
1 parent 512d623 commit dd937d3

File tree

7 files changed

+140
-52
lines changed

7 files changed

+140
-52
lines changed

frontend/src/components/match/MatchTeamTable.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {useMatchStateStore} from "@/store/matchState";
77
import formatDuration from "format-duration";
88
import {teams} from "@/helpers";
99
import type {Team} from "@/proto/ssl_gc_common";
10+
import {Referee_Stage} from "@/proto/ssl_gc_referee_message";
11+
import {computed} from "vue";
1012
1113
const store = useMatchStateStore()
1214
@@ -30,6 +32,12 @@ const nextYellowCardDue = (team: Team) => {
3032
}
3133
return 0
3234
}
35+
const isShootout = computed(() => {
36+
return store.matchState.stage === Referee_Stage.PENALTY_SHOOTOUT
37+
})
38+
const penaltyAttempts = (team: Team) => {
39+
return store.matchState.shootoutState?.numberOfAttempts?.[team] || 0
40+
}
3341
</script>
3442

3543
<template>
@@ -79,6 +87,17 @@ const nextYellowCardDue = (team: Team) => {
7987
</q-item-label>
8088
</q-item-section>
8189
</q-item>
90+
91+
<q-item v-ripple v-if="isShootout">
92+
<q-item-section class="text-center">
93+
<q-item-label>
94+
{{ penaltyAttempts(team) }}
95+
</q-item-label>
96+
<q-item-label caption>
97+
Number of penalty attempts
98+
</q-item-label>
99+
</q-item-section>
100+
</q-item>
82101
</q-list>
83102
</div>
84103
</template>

frontend/src/proto/ssl_gc_state.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ export interface State_TeamStateEntry {
258258

259259
export interface ShootoutState {
260260
nextTeam?: Team;
261+
numberOfAttempts?: { [key: string]: number };
262+
}
263+
264+
export interface ShootoutState_NumberOfAttemptsEntry {
265+
key: string;
266+
value: number;
261267
}
262268

263269
export const YellowCard = {
@@ -558,12 +564,39 @@ export const State_TeamStateEntry = {
558564

559565
export const ShootoutState = {
560566
fromJSON(object: any): ShootoutState {
561-
return { nextTeam: isSet(object.nextTeam) ? teamFromJSON(object.nextTeam) : Team.UNKNOWN };
567+
return {
568+
nextTeam: isSet(object.nextTeam) ? teamFromJSON(object.nextTeam) : Team.UNKNOWN,
569+
numberOfAttempts: isObject(object.numberOfAttempts)
570+
? Object.entries(object.numberOfAttempts).reduce<{ [key: string]: number }>((acc, [key, value]) => {
571+
acc[key] = Number(value);
572+
return acc;
573+
}, {})
574+
: {},
575+
};
562576
},
563577

564578
toJSON(message: ShootoutState): unknown {
565579
const obj: any = {};
566580
message.nextTeam !== undefined && (obj.nextTeam = teamToJSON(message.nextTeam));
581+
obj.numberOfAttempts = {};
582+
if (message.numberOfAttempts) {
583+
Object.entries(message.numberOfAttempts).forEach(([k, v]) => {
584+
obj.numberOfAttempts[k] = Math.round(v);
585+
});
586+
}
587+
return obj;
588+
},
589+
};
590+
591+
export const ShootoutState_NumberOfAttemptsEntry = {
592+
fromJSON(object: any): ShootoutState_NumberOfAttemptsEntry {
593+
return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? Number(object.value) : 0 };
594+
},
595+
596+
toJSON(message: ShootoutState_NumberOfAttemptsEntry): unknown {
597+
const obj: any = {};
598+
message.key !== undefined && (obj.key = message.key);
599+
message.value !== undefined && (obj.value = Math.round(message.value));
567600
return obj;
568601
},
569602
};

internal/app/engine/process_continue_next_action.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ func (e *Engine) randomTeam() state.Team {
331331
func suggestEndOfMatch(currentState *state.State) bool {
332332
goalsY := int(*currentState.TeamInfo(state.Team_YELLOW).Goals)
333333
goalsB := int(*currentState.TeamInfo(state.Team_BLUE).Goals)
334+
335+
if *currentState.Stage == state.Referee_PENALTY_SHOOTOUT {
336+
attempts := currentState.ShootoutState.NumberOfAttempts[state.Team_BLUE.String()] +
337+
currentState.ShootoutState.NumberOfAttempts[state.Team_YELLOW.String()]
338+
339+
if attempts < 10 || attempts%2 == 1 {
340+
return false
341+
}
342+
return goalsY != goalsB
343+
}
344+
334345
if *currentState.Stage != state.Referee_POST_GAME &&
335346
(goalsY >= 10 || goalsB >= 10) && math.Abs(float64(goalsY-goalsB)) > 1 {
336347
return true

internal/app/state/ssl_gc_state.pb.go

Lines changed: 70 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/app/statemachine/change_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
6363
if *newState.Stage == state.Referee_PENALTY_SHOOTOUT &&
6464
newState.ShootoutState != nil {
6565
if *newCommand.Command.Type == state.Command_NORMAL_START {
66+
newState.ShootoutState.NumberOfAttempts[newState.ShootoutState.NextTeam.String()]++
6667
*newState.ShootoutState.NextTeam = newState.ShootoutState.NextTeam.Opposite()
6768
} else if *newState.GameState.Type == state.GameState_STOP {
6869
forTeam := *newState.ShootoutState.NextTeam

internal/app/statemachine/change_stage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (s *StateMachine) proceedStage(newState *state.State, newStage state.Refere
6262
if newStage == state.Referee_PENALTY_SHOOTOUT {
6363
newState.ShootoutState = &state.ShootoutState{
6464
NextTeam: newState.FirstKickoffTeam,
65+
NumberOfAttempts: map[string]int32{
66+
state.Team_BLUE.String(): 0,
67+
state.Team_YELLOW.String(): 0,
68+
},
6569
}
6670
}
6771

proto/ssl_gc_state.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ message State {
121121

122122
message ShootoutState {
123123
optional Team next_team = 1;
124+
map<string, int32> number_of_attempts = 2;
124125
}

0 commit comments

Comments
 (0)