Skip to content

Commit

Permalink
Require explicit rejection of possible goals
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Jul 5, 2024
1 parent c1285ce commit fcb5e3a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21 deletions.
2 changes: 2 additions & 0 deletions frontend/src/helpers/texts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export function continueActionLabel(type: ContinueAction_Type, nextCommand?: Com
return 'End match'
case ContinueAction_Type.ACCEPT_GOAL:
return 'Accept Goal'
case ContinueAction_Type.REJECT_GOAL:
return 'Reject Goal'
case ContinueAction_Type.NORMAL_START:
return 'Normal Start'
case ContinueAction_Type.CHALLENGE_ACCEPT:
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/proto/ssl_gc_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export enum ContinueAction_Type {
NEXT_STAGE = "NEXT_STAGE",
END_GAME = "END_GAME",
ACCEPT_GOAL = "ACCEPT_GOAL",
REJECT_GOAL = "REJECT_GOAL",
NORMAL_START = "NORMAL_START",
CHALLENGE_ACCEPT = "CHALLENGE_ACCEPT",
CHALLENGE_REJECT = "CHALLENGE_REJECT",
Expand Down Expand Up @@ -212,6 +213,9 @@ export function continueAction_TypeFromJSON(object: any): ContinueAction_Type {
case 12:
case "ACCEPT_GOAL":
return ContinueAction_Type.ACCEPT_GOAL;
case 20:
case "REJECT_GOAL":
return ContinueAction_Type.REJECT_GOAL;
case 13:
case "NORMAL_START":
return ContinueAction_Type.NORMAL_START;
Expand Down Expand Up @@ -264,6 +268,8 @@ export function continueAction_TypeToJSON(object: ContinueAction_Type): string {
return "END_GAME";
case ContinueAction_Type.ACCEPT_GOAL:
return "ACCEPT_GOAL";
case ContinueAction_Type.REJECT_GOAL:
return "REJECT_GOAL";
case ContinueAction_Type.NORMAL_START:
return "NORMAL_START";
case ContinueAction_Type.CHALLENGE_ACCEPT:
Expand Down
10 changes: 10 additions & 0 deletions internal/app/engine/process_continue_next_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func (e *Engine) actionsToContinueFromStop() (actions []*ContinueAction, hints [
actions = append(actions, continueActionAcceptGoal)
}

if e.currentState.HasGameEventByTeam(state.GameEvent_POSSIBLE_GOAL, team) &&
!e.currentState.HasGameEventByTeam(state.GameEvent_INVALID_GOAL, team) {
continueActionRejectGoal := createContinueAction(
ContinueAction_REJECT_GOAL,
team,
ContinueAction_READY_MANUAL,
)
actions = append(actions, continueActionRejectGoal)
}

challengeFlagsRaised := len(e.currentState.FindGameEventsByTeam(state.GameEvent_CHALLENGE_FLAG, team))
challengeFlagsHandled := len(e.currentState.FindGameEventsByTeam(state.GameEvent_CHALLENGE_FLAG_HANDLED, team))

Expand Down
17 changes: 17 additions & 0 deletions internal/app/engine/process_continue_perform.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ func (e *Engine) performContinueAction(action *ContinueAction) {
} else {
log.Println("No possible goal event present to accept")
}
case ContinueAction_REJECT_GOAL:
possibleGoals := e.currentState.FindGameEventsByTeam(state.GameEvent_POSSIBLE_GOAL, *action.ForTeam)
if len(possibleGoals) == 1 {
possibleGoal := possibleGoals[0]
goal := state.GameEvent_Goal{}
proto.Merge(&goal, possibleGoal.GetPossibleGoal())
goal.Message = new(string)
*goal.Message = "Rejected by GC operator"
goalEvent := &state.GameEvent{
Event: &state.GameEvent_InvalidGoal{
InvalidGoal: &goal,
},
}
e.Enqueue(createGameEventChange(state.GameEvent_INVALID_GOAL, goalEvent))
} else {
log.Println("No possible goal event present to reject")
}
case ContinueAction_NORMAL_START:
e.Enqueue(createCommandChange(state.NewCommandNeutral(state.Command_NORMAL_START)))
case ContinueAction_CHALLENGE_ACCEPT:
Expand Down
44 changes: 24 additions & 20 deletions internal/app/engine/ssl_gc_engine.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/app/statemachine/change_gameevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func (s *StateMachine) nextCommandForEvent(newState *state.State, gameEvent *sta
state.GameEvent_BOT_DRIBBLED_BALL_TOO_FAR,
state.GameEvent_ATTACKER_DOUBLE_TOUCHED_BALL,
state.GameEvent_PENALTY_KICK_FAILED,
state.GameEvent_POSSIBLE_GOAL,
state.GameEvent_INVALID_GOAL:
return lastCommandOnUnknownTeam(
newState.NextCommand,
Expand Down Expand Up @@ -392,6 +391,9 @@ func (s *StateMachine) nextCommandForEvent(newState *state.State, gameEvent *sta
newState.NextCommand,
state.NewCommand(state.Command_DIRECT, gameEvent.ByTeam().Opposite()),
)
case state.GameEvent_POSSIBLE_GOAL:
// explicitly no next command. GCO has to accept or reject the goal.
return nil
default:
return newState.NextCommand
}
Expand Down
1 change: 1 addition & 0 deletions proto/ssl_gc_engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ message ContinueAction {
NEXT_STAGE = 8;
END_GAME = 16;
ACCEPT_GOAL = 12;
REJECT_GOAL = 20;
NORMAL_START = 13;
CHALLENGE_ACCEPT = 18;
CHALLENGE_REJECT = 19;
Expand Down

0 comments on commit fcb5e3a

Please sign in to comment.