From fcb5e3a68f03c1705f472dfe5dba8ad187606b3a Mon Sep 17 00:00:00 2001 From: Nicolai Ommer Date: Fri, 5 Jul 2024 19:58:09 +0200 Subject: [PATCH] Require explicit rejection of possible goals --- frontend/src/helpers/texts.ts | 2 + frontend/src/proto/ssl_gc_engine.ts | 6 +++ .../engine/process_continue_next_action.go | 10 +++++ .../app/engine/process_continue_perform.go | 17 +++++++ internal/app/engine/ssl_gc_engine.pb.go | 44 ++++++++++--------- internal/app/statemachine/change_gameevent.go | 4 +- proto/ssl_gc_engine.proto | 1 + 7 files changed, 63 insertions(+), 21 deletions(-) diff --git a/frontend/src/helpers/texts.ts b/frontend/src/helpers/texts.ts index 84c65cd3..0c303f39 100644 --- a/frontend/src/helpers/texts.ts +++ b/frontend/src/helpers/texts.ts @@ -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: diff --git a/frontend/src/proto/ssl_gc_engine.ts b/frontend/src/proto/ssl_gc_engine.ts index 08e7bef7..f0235c7c 100644 --- a/frontend/src/proto/ssl_gc_engine.ts +++ b/frontend/src/proto/ssl_gc_engine.ts @@ -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", @@ -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; @@ -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: diff --git a/internal/app/engine/process_continue_next_action.go b/internal/app/engine/process_continue_next_action.go index eb92be8d..5f6a7a92 100644 --- a/internal/app/engine/process_continue_next_action.go +++ b/internal/app/engine/process_continue_next_action.go @@ -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)) diff --git a/internal/app/engine/process_continue_perform.go b/internal/app/engine/process_continue_perform.go index 162bd8c5..e01a25c3 100644 --- a/internal/app/engine/process_continue_perform.go +++ b/internal/app/engine/process_continue_perform.go @@ -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: diff --git a/internal/app/engine/ssl_gc_engine.pb.go b/internal/app/engine/ssl_gc_engine.pb.go index 76608969..aaa415ab 100644 --- a/internal/app/engine/ssl_gc_engine.pb.go +++ b/internal/app/engine/ssl_gc_engine.pb.go @@ -102,6 +102,7 @@ const ( ContinueAction_NEXT_STAGE ContinueAction_Type = 8 ContinueAction_END_GAME ContinueAction_Type = 16 ContinueAction_ACCEPT_GOAL ContinueAction_Type = 12 + ContinueAction_REJECT_GOAL ContinueAction_Type = 20 ContinueAction_NORMAL_START ContinueAction_Type = 13 ContinueAction_CHALLENGE_ACCEPT ContinueAction_Type = 18 ContinueAction_CHALLENGE_REJECT ContinueAction_Type = 19 @@ -127,6 +128,7 @@ var ( 8: "NEXT_STAGE", 16: "END_GAME", 12: "ACCEPT_GOAL", + 20: "REJECT_GOAL", 13: "NORMAL_START", 18: "CHALLENGE_ACCEPT", 19: "CHALLENGE_REJECT", @@ -149,6 +151,7 @@ var ( "NEXT_STAGE": 8, "END_GAME": 16, "ACCEPT_GOAL": 12, + "REJECT_GOAL": 20, "NORMAL_START": 13, "CHALLENGE_ACCEPT": 18, "CHALLENGE_REJECT": 19, @@ -939,7 +942,7 @@ var file_ssl_gc_engine_proto_rawDesc = []byte{ 0x18, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x52, 0x6f, 0x62, 0x6f, 0x74, 0x49, 0x64, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x03, 0x70, 0x6f, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x56, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x32, - 0x52, 0x03, 0x70, 0x6f, 0x73, 0x22, 0xe6, 0x05, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, + 0x52, 0x03, 0x70, 0x6f, 0x73, 0x22, 0xf7, 0x05, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x02, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, @@ -954,7 +957,7 @@ var file_ssl_gc_engine_proto_rawDesc = []byte{ 0x61, 0x6d, 0x70, 0x52, 0x07, 0x72, 0x65, 0x61, 0x64, 0x79, 0x41, 0x74, 0x12, 0x2b, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x15, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x8c, 0x03, 0x0a, 0x04, 0x54, 0x79, + 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x9d, 0x03, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x41, 0x4c, 0x54, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x52, 0x45, 0x53, 0x55, 0x4d, 0x45, 0x5f, 0x46, 0x52, 0x4f, 0x4d, 0x5f, 0x48, 0x41, @@ -975,24 +978,25 @@ var file_ssl_gc_engine_proto_rawDesc = []byte{ 0x53, 0x54, 0x49, 0x54, 0x55, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x07, 0x12, 0x0e, 0x0a, 0x0a, 0x4e, 0x45, 0x58, 0x54, 0x5f, 0x53, 0x54, 0x41, 0x47, 0x45, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x44, 0x5f, 0x47, 0x41, 0x4d, 0x45, 0x10, 0x10, 0x12, 0x0f, 0x0a, 0x0b, 0x41, 0x43, 0x43, - 0x45, 0x50, 0x54, 0x5f, 0x47, 0x4f, 0x41, 0x4c, 0x10, 0x0c, 0x12, 0x10, 0x0a, 0x0c, 0x4e, 0x4f, - 0x52, 0x4d, 0x41, 0x4c, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x0d, 0x12, 0x14, 0x0a, 0x10, - 0x43, 0x48, 0x41, 0x4c, 0x4c, 0x45, 0x4e, 0x47, 0x45, 0x5f, 0x41, 0x43, 0x43, 0x45, 0x50, 0x54, - 0x10, 0x12, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x48, 0x41, 0x4c, 0x4c, 0x45, 0x4e, 0x47, 0x45, 0x5f, - 0x52, 0x45, 0x4a, 0x45, 0x43, 0x54, 0x10, 0x13, 0x22, 0x64, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, - 0x65, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, - 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x45, 0x44, 0x10, - 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x49, 0x54, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0e, - 0x0a, 0x0a, 0x52, 0x45, 0x41, 0x44, 0x59, 0x5f, 0x41, 0x55, 0x54, 0x4f, 0x10, 0x03, 0x12, 0x10, - 0x0a, 0x0c, 0x52, 0x45, 0x41, 0x44, 0x59, 0x5f, 0x4d, 0x41, 0x4e, 0x55, 0x41, 0x4c, 0x10, 0x04, - 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x05, 0x22, 0x28, - 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x48, 0x69, 0x6e, 0x74, 0x12, 0x18, - 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x02, 0x28, 0x09, 0x52, - 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x52, 0x6f, 0x62, 0x6f, 0x43, 0x75, 0x70, 0x2d, 0x53, - 0x53, 0x4c, 0x2f, 0x73, 0x73, 0x6c, 0x2d, 0x67, 0x61, 0x6d, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x61, 0x70, 0x70, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, + 0x45, 0x50, 0x54, 0x5f, 0x47, 0x4f, 0x41, 0x4c, 0x10, 0x0c, 0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x45, + 0x4a, 0x45, 0x43, 0x54, 0x5f, 0x47, 0x4f, 0x41, 0x4c, 0x10, 0x14, 0x12, 0x10, 0x0a, 0x0c, 0x4e, + 0x4f, 0x52, 0x4d, 0x41, 0x4c, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x0d, 0x12, 0x14, 0x0a, + 0x10, 0x43, 0x48, 0x41, 0x4c, 0x4c, 0x45, 0x4e, 0x47, 0x45, 0x5f, 0x41, 0x43, 0x43, 0x45, 0x50, + 0x54, 0x10, 0x12, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x48, 0x41, 0x4c, 0x4c, 0x45, 0x4e, 0x47, 0x45, + 0x5f, 0x52, 0x45, 0x4a, 0x45, 0x43, 0x54, 0x10, 0x13, 0x22, 0x64, 0x0a, 0x05, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, + 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x45, 0x44, + 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x49, 0x54, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, + 0x0e, 0x0a, 0x0a, 0x52, 0x45, 0x41, 0x44, 0x59, 0x5f, 0x41, 0x55, 0x54, 0x4f, 0x10, 0x03, 0x12, + 0x10, 0x0a, 0x0c, 0x52, 0x45, 0x41, 0x44, 0x59, 0x5f, 0x4d, 0x41, 0x4e, 0x55, 0x41, 0x4c, 0x10, + 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x05, 0x22, + 0x28, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x48, 0x69, 0x6e, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x02, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x52, 0x6f, 0x62, 0x6f, 0x43, 0x75, 0x70, 0x2d, + 0x53, 0x53, 0x4c, 0x2f, 0x73, 0x73, 0x6c, 0x2d, 0x67, 0x61, 0x6d, 0x65, 0x2d, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, } var ( diff --git a/internal/app/statemachine/change_gameevent.go b/internal/app/statemachine/change_gameevent.go index 017127d6..394fee08 100644 --- a/internal/app/statemachine/change_gameevent.go +++ b/internal/app/statemachine/change_gameevent.go @@ -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, @@ -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 } diff --git a/proto/ssl_gc_engine.proto b/proto/ssl_gc_engine.proto index 6e58206d..b87dd336 100644 --- a/proto/ssl_gc_engine.proto +++ b/proto/ssl_gc_engine.proto @@ -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;