@@ -71,120 +71,134 @@ func (e *Engine) nextActions() (actions []*ContinueAction, hints []*ContinueHint
71
71
}
72
72
73
73
if * e .currentState .Command .Type == state .Command_STOP || * e .currentState .Command .Type == state .Command_HALT {
74
- for _ , team := range state .BothTeams () {
75
- if e .currentState .HasGameEventByTeam (state .GameEvent_POSSIBLE_GOAL , team ) &&
76
- ! e .currentState .HasGameEventByTeam (state .GameEvent_GOAL , team ) &&
77
- ! e .currentState .HasGameEventByTeam (state .GameEvent_INVALID_GOAL , team ) {
78
- actions = append (actions , createContinueAction (
79
- ContinueAction_ACCEPT_GOAL ,
80
- team ,
81
- ContinueAction_READY_MANUAL ,
82
- ))
83
- }
74
+ newActions , newHints := e .actionsToContinueFromStop ()
75
+ actions = append (actions , newActions ... )
76
+ hints = append (hints , newHints ... )
77
+ } else {
78
+ // reset random placing team
79
+ e .randomPlacingTeam = state .Team_UNKNOWN
80
+ }
84
81
85
- challengeFlagsRaised := len (e .currentState .FindGameEventsByTeam (state .GameEvent_CHALLENGE_FLAG , team ))
86
- challengeFlagsHandled := len (e .currentState .FindGameEventsByTeam (state .GameEvent_CHALLENGE_FLAG_HANDLED , team ))
87
-
88
- if challengeFlagsRaised > challengeFlagsHandled {
89
- actions = append (actions , createContinueAction (
90
- ContinueAction_CHALLENGE_ACCEPT ,
91
- team ,
92
- ContinueAction_READY_MANUAL ,
93
- ))
94
- actions = append (actions , createContinueAction (
95
- ContinueAction_CHALLENGE_REJECT ,
96
- team ,
97
- ContinueAction_READY_MANUAL ,
98
- ))
82
+ if * e .currentState .Command .Type == state .Command_HALT {
83
+ // disable continue actions that can't be used after halt
84
+ for _ , action := range actions {
85
+ switch * action .Type {
86
+ case
87
+ ContinueAction_FORCE_START ,
88
+ ContinueAction_FREE_KICK ,
89
+ ContinueAction_NEXT_COMMAND ,
90
+ ContinueAction_BALL_PLACEMENT_START :
91
+ * action .State = ContinueAction_DISABLED
99
92
}
100
93
}
101
- }
102
94
103
- if * e .currentState .Command .Type == state .Command_STOP ||
104
- * e .currentState .Command .Type == state .Command_HALT {
105
- if (e .gameConfig .RecommendHalfTimes || e .currentState .Stage .IsPausedStage ()) &&
106
- e .currentState .StageTimeLeft .AsDuration () < 0 &&
107
- * e .currentState .Stage != state .Referee_PENALTY_SHOOTOUT {
108
- actions = append (actions , createContinueAction (
109
- ContinueAction_NEXT_STAGE ,
110
- state .Team_UNKNOWN ,
111
- ContinueAction_READY_MANUAL ,
112
- ))
95
+ continueFromHalt := createContinueAction (
96
+ ContinueAction_RESUME_FROM_HALT ,
97
+ state .Team_UNKNOWN ,
98
+ ContinueAction_READY_MANUAL ,
99
+ )
100
+ if e .teamDoingBotSubstitution () {
101
+ continueFromHalt .ContinuationIssues = append (continueFromHalt .ContinuationIssues ,
102
+ "Robot substitution in progress" )
113
103
}
114
- if suggestEndOfMatch (e .currentState ) {
104
+ actions = append ([]* ContinueAction {continueFromHalt }, actions ... )
105
+ }
106
+
107
+ return
108
+ }
109
+
110
+ func (e * Engine ) actionsToContinueFromStop () (actions []* ContinueAction , hints []* ContinueHint ) {
111
+ for _ , team := range state .BothTeams () {
112
+ if e .currentState .HasGameEventByTeam (state .GameEvent_POSSIBLE_GOAL , team ) &&
113
+ ! e .currentState .HasGameEventByTeam (state .GameEvent_GOAL , team ) &&
114
+ ! e .currentState .HasGameEventByTeam (state .GameEvent_INVALID_GOAL , team ) {
115
115
actions = append (actions , createContinueAction (
116
- ContinueAction_END_GAME ,
117
- state . Team_UNKNOWN ,
116
+ ContinueAction_ACCEPT_GOAL ,
117
+ team ,
118
118
ContinueAction_READY_MANUAL ,
119
119
))
120
120
}
121
121
122
- var teamRequestingBotSubstitution = e .teamRequestingBotSubstitution ()
123
- var teamRequestingTimeout = e .teamRequestingTimeout ()
124
- if teamRequestingBotSubstitution != nil {
122
+ challengeFlagsRaised := len (e .currentState .FindGameEventsByTeam (state .GameEvent_CHALLENGE_FLAG , team ))
123
+ challengeFlagsHandled := len (e .currentState .FindGameEventsByTeam (state .GameEvent_CHALLENGE_FLAG_HANDLED , team ))
124
+
125
+ if challengeFlagsRaised > challengeFlagsHandled {
125
126
actions = append (actions , createContinueAction (
126
- ContinueAction_BOT_SUBSTITUTION ,
127
- * teamRequestingBotSubstitution ,
128
- ContinueAction_READY_AUTO ,
127
+ ContinueAction_CHALLENGE_ACCEPT ,
128
+ team ,
129
+ ContinueAction_READY_MANUAL ,
129
130
))
130
- } else if teamRequestingTimeout != nil {
131
131
actions = append (actions , createContinueAction (
132
- ContinueAction_TIMEOUT_START ,
133
- * teamRequestingTimeout ,
132
+ ContinueAction_CHALLENGE_REJECT ,
133
+ team ,
134
134
ContinueAction_READY_MANUAL ,
135
135
))
136
136
}
137
137
}
138
138
139
- if * e .currentState .Command .Type == state .Command_STOP {
140
- if e .ballPlacementRequired () {
141
- placingTeam := e .ballPlacementTeam ()
142
- if placingTeam .Known () {
143
- actions = append (actions , createContinueAction (
144
- ContinueAction_BALL_PLACEMENT_START ,
145
- placingTeam ,
146
- ContinueAction_READY_AUTO ,
147
- ))
148
- } else {
149
- hint := fmt .Sprintf ("Manually place the ball at x: %.2fm, y: %.2fm" ,
150
- * e .currentState .PlacementPos .X , * e .currentState .PlacementPos .Y )
151
- hints = append (hints , & ContinueHint {
152
- Message : & hint ,
153
- })
154
- }
155
- }
156
- if e .currentState .NextCommand != nil {
157
- var forTeam state.Team
158
- if e .currentState .NextCommand != nil && e .currentState .NextCommand .ForTeam != nil {
159
- forTeam = * e .currentState .NextCommand .ForTeam
160
- } else {
161
- forTeam = state .Team_UNKNOWN
162
- }
163
- actions = append (actions , e .createNextCommandContinueAction (ContinueAction_NEXT_COMMAND , forTeam ))
164
- } else {
165
- actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FORCE_START , state .Team_UNKNOWN ))
166
- actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FREE_KICK , state .Team_YELLOW ))
167
- actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FREE_KICK , state .Team_BLUE ))
168
- }
169
- } else {
170
- // reset random placing team
171
- e .randomPlacingTeam = state .Team_UNKNOWN
139
+ if (e .gameConfig .RecommendHalfTimes || e .currentState .Stage .IsPausedStage ()) &&
140
+ e .currentState .StageTimeLeft .AsDuration () < 0 &&
141
+ * e .currentState .Stage != state .Referee_PENALTY_SHOOTOUT {
142
+ actions = append (actions , createContinueAction (
143
+ ContinueAction_NEXT_STAGE ,
144
+ state .Team_UNKNOWN ,
145
+ ContinueAction_READY_MANUAL ,
146
+ ))
172
147
}
173
-
174
- if * e .currentState .Command .Type == state .Command_HALT {
175
- continueFromHalt := createContinueAction (
176
- ContinueAction_RESUME_FROM_HALT ,
148
+ if suggestEndOfMatch (e .currentState ) {
149
+ actions = append (actions , createContinueAction (
150
+ ContinueAction_END_GAME ,
177
151
state .Team_UNKNOWN ,
178
152
ContinueAction_READY_MANUAL ,
179
- )
180
- if e .teamDoingBotSubstitution () {
181
- continueFromHalt .ContinuationIssues = append (continueFromHalt .ContinuationIssues ,
182
- "Robot substitution in progress" )
183
- }
184
- actions = append (actions , continueFromHalt )
153
+ ))
185
154
}
186
155
187
- return
156
+ var teamRequestingBotSubstitution = e .teamRequestingBotSubstitution ()
157
+ var teamRequestingTimeout = e .teamRequestingTimeout ()
158
+ if teamRequestingBotSubstitution != nil {
159
+ actions = append (actions , createContinueAction (
160
+ ContinueAction_BOT_SUBSTITUTION ,
161
+ * teamRequestingBotSubstitution ,
162
+ ContinueAction_READY_AUTO ,
163
+ ))
164
+ } else if teamRequestingTimeout != nil {
165
+ actions = append (actions , createContinueAction (
166
+ ContinueAction_TIMEOUT_START ,
167
+ * teamRequestingTimeout ,
168
+ ContinueAction_READY_MANUAL ,
169
+ ))
170
+ }
171
+
172
+ if e .ballPlacementRequired () {
173
+ placingTeam := e .ballPlacementTeam ()
174
+ if placingTeam .Known () {
175
+ actions = append (actions , createContinueAction (
176
+ ContinueAction_BALL_PLACEMENT_START ,
177
+ placingTeam ,
178
+ ContinueAction_READY_AUTO ,
179
+ ))
180
+ } else {
181
+ hint := fmt .Sprintf ("Manually place the ball at x: %.2fm, y: %.2fm" ,
182
+ * e .currentState .PlacementPos .X , * e .currentState .PlacementPos .Y )
183
+ hints = append (hints , & ContinueHint {
184
+ Message : & hint ,
185
+ })
186
+ }
187
+ }
188
+ if e .currentState .NextCommand != nil {
189
+ var forTeam state.Team
190
+ if e .currentState .NextCommand != nil && e .currentState .NextCommand .ForTeam != nil {
191
+ forTeam = * e .currentState .NextCommand .ForTeam
192
+ } else {
193
+ forTeam = state .Team_UNKNOWN
194
+ }
195
+ actions = append (actions , e .createNextCommandContinueAction (ContinueAction_NEXT_COMMAND , forTeam ))
196
+ } else {
197
+ actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FORCE_START , state .Team_UNKNOWN ))
198
+ actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FREE_KICK , state .Team_YELLOW ))
199
+ actions = append (actions , e .createNextCommandContinueAction (ContinueAction_FREE_KICK , state .Team_BLUE ))
200
+ }
201
+ return actions , hints
188
202
}
189
203
190
204
func (e * Engine ) teamRequestingBotSubstitution () * state.Team {
0 commit comments