Skip to content

Commit d911019

Browse files
committed
Suggest alternating penalty kick in shootout
1 parent fc18e84 commit d911019

File tree

6 files changed

+171
-61
lines changed

6 files changed

+171
-61
lines changed

frontend/src/proto/ssl_gc_state.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,18 @@ export interface State {
248248
firstKickoffTeam?: Team;
249249
matchType?: MatchType;
250250
readyContinueTime?: Date;
251+
shootoutState?: ShootoutState;
251252
}
252253

253254
export interface State_TeamStateEntry {
254255
key: string;
255256
value?: TeamInfo;
256257
}
257258

259+
export interface ShootoutState {
260+
nextTeam?: Team;
261+
}
262+
258263
export const YellowCard = {
259264
fromJSON(object: any): YellowCard {
260265
return {
@@ -486,6 +491,7 @@ export const State = {
486491
firstKickoffTeam: isSet(object.firstKickoffTeam) ? teamFromJSON(object.firstKickoffTeam) : Team.UNKNOWN,
487492
matchType: isSet(object.matchType) ? matchTypeFromJSON(object.matchType) : MatchType.UNKNOWN_MATCH,
488493
readyContinueTime: isSet(object.readyContinueTime) ? fromJsonTimestamp(object.readyContinueTime) : undefined,
494+
shootoutState: isSet(object.shootoutState) ? ShootoutState.fromJSON(object.shootoutState) : undefined,
489495
};
490496
},
491497

@@ -528,6 +534,8 @@ export const State = {
528534
message.firstKickoffTeam !== undefined && (obj.firstKickoffTeam = teamToJSON(message.firstKickoffTeam));
529535
message.matchType !== undefined && (obj.matchType = matchTypeToJSON(message.matchType));
530536
message.readyContinueTime !== undefined && (obj.readyContinueTime = message.readyContinueTime.toISOString());
537+
message.shootoutState !== undefined &&
538+
(obj.shootoutState = message.shootoutState ? ShootoutState.toJSON(message.shootoutState) : undefined);
531539
return obj;
532540
},
533541
};
@@ -548,6 +556,18 @@ export const State_TeamStateEntry = {
548556
},
549557
};
550558

559+
export const ShootoutState = {
560+
fromJSON(object: any): ShootoutState {
561+
return { nextTeam: isSet(object.nextTeam) ? teamFromJSON(object.nextTeam) : Team.UNKNOWN };
562+
},
563+
564+
toJSON(message: ShootoutState): unknown {
565+
const obj: any = {};
566+
message.nextTeam !== undefined && (obj.nextTeam = teamToJSON(message.nextTeam));
567+
return obj;
568+
},
569+
};
570+
551571
function fromTimestamp(t: Timestamp): Date {
552572
let millis = t.seconds * 1_000;
553573
millis += t.nanos / 1_000_000;

internal/app/state/ssl_gc_state.pb.go

Lines changed: 130 additions & 53 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
6060
newState.NextCommand = nil
6161
}
6262

63+
if *newState.Stage == state.Referee_PENALTY_SHOOTOUT &&
64+
newState.ShootoutState != nil {
65+
if *newCommand.Command.Type == state.Command_NORMAL_START {
66+
*newState.ShootoutState.NextTeam = newState.ShootoutState.NextTeam.Opposite()
67+
} else if *newState.GameState.Type == state.GameState_STOP {
68+
forTeam := *newState.ShootoutState.NextTeam
69+
newState.NextCommand = state.NewCommand(state.Command_PENALTY, forTeam)
70+
}
71+
}
72+
6373
return
6474
}
6575

internal/app/statemachine/change_gameevent.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,10 @@ func (s *StateMachine) nextCommandForEvent(newState *state.State, gameEvent *sta
354354
state.GameEvent_PENALTY_KICK_FAILED,
355355
state.GameEvent_POSSIBLE_GOAL,
356356
state.GameEvent_INVALID_GOAL:
357-
if *newState.Stage == state.Referee_PENALTY_SHOOTOUT {
358-
return state.NewCommand(state.Command_PENALTY, gameEvent.ByTeam().Opposite())
359-
}
360357
return state.NewCommand(state.Command_DIRECT, gameEvent.ByTeam().Opposite())
361358
case state.GameEvent_DEFENDER_IN_DEFENSE_AREA:
362359
return state.NewCommand(state.Command_PENALTY, gameEvent.ByTeam().Opposite())
363360
case state.GameEvent_GOAL:
364-
if *newState.Stage == state.Referee_PENALTY_SHOOTOUT {
365-
return state.NewCommand(state.Command_PENALTY, gameEvent.ByTeam().Opposite())
366-
}
367361
return state.NewCommand(state.Command_KICKOFF, gameEvent.ByTeam().Opposite())
368362
case state.GameEvent_NO_PROGRESS_IN_GAME,
369363
state.GameEvent_TOO_MANY_ROBOTS:

internal/app/statemachine/change_stage.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func (s *StateMachine) proceedStage(newState *state.State, newStage state.Refere
5959
newState.PlacementPos = geom.NewVector2(0.0, 0.0)
6060
}
6161

62+
if newStage == state.Referee_PENALTY_SHOOTOUT {
63+
newState.ShootoutState = &state.ShootoutState{
64+
NextTeam: newState.FirstKickoffTeam,
65+
}
66+
}
67+
6268
// Reset game events and proposals
6369
newState.ProposalGroups = nil
6470
newState.GameEvents = nil
@@ -75,8 +81,6 @@ func (s *StateMachine) getNextCommandForStage(newState *state.State, stage state
7581
return state.NewCommand(state.Command_KICKOFF, *newState.FirstKickoffTeam)
7682
case state.Referee_NORMAL_SECOND_HALF_PRE, state.Referee_EXTRA_SECOND_HALF_PRE:
7783
return state.NewCommand(state.Command_KICKOFF, newState.FirstKickoffTeam.Opposite())
78-
case state.Referee_PENALTY_SHOOTOUT:
79-
return state.NewCommand(state.Command_PENALTY, *newState.FirstKickoffTeam)
8084
default:
8185
return nil
8286
}

proto/ssl_gc_state.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,9 @@ message State {
116116
optional Team first_kickoff_team = 17;
117117
optional MatchType match_type = 18;
118118
optional google.protobuf.Timestamp ready_continue_time = 20;
119+
optional ShootoutState shootout_state = 21;
120+
}
121+
122+
message ShootoutState {
123+
optional Team next_team = 1;
119124
}

0 commit comments

Comments
 (0)