Thunderbots Project
Loading...
Searching...
No Matches
free_kick_play_fsm.h
1#pragma once
2
3#include "proto/parameters.pb.h"
4#include "shared/constants.h"
5#include "software/ai/evaluation/calc_best_shot.h"
6#include "software/ai/hl/stp/play/defense/defense_play.h"
7#include "software/ai/hl/stp/play/play.h"
8#include "software/ai/hl/stp/tactic/chip/chip_tactic.h"
9#include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h"
10#include "software/ai/hl/stp/tactic/kick/kick_tactic.h"
11#include "software/ai/hl/stp/tactic/move/move_tactic.h"
12#include "software/ai/hl/stp/tactic/receiver/receiver_tactic.h"
13#include "software/ai/passing/eighteen_zone_pitch_division.h"
14#include "software/ai/passing/pass_generator.h"
15#include "software/ai/passing/receiver_position_generator.hpp"
16#include "software/logger/logger.h"
17
29{
30 class SetupPositionState;
31 class ShootState;
32 class AttemptPassState;
33 class PassState;
34 class ChipState;
35
37 {
38 };
39
40 DEFINE_PLAY_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
41
47 explicit FreeKickPlayFSM(const TbotsProto::AiConfig& ai_config);
48
54 void setupPosition(const Update& event);
55
63 bool setupDone(const Update& event);
64
77 const WorldPtr world, unsigned int num_tactics,
78 const std::vector<Point>& existing_receiver_positions = {},
79 const std::optional<Point>& pass_origin_override = std::nullopt);
80
97 PriorityTacticVector& tactics_to_run, const Update& event,
98 int ideal_num_receivers, int num_tactics_already_assigned,
99 const std::vector<Point>& existing_receiver_positions = {},
100 const std::optional<Point>& pass_origin_override = std::nullopt);
101
107 void updateAlignToBallTactic(const WorldPtr& world_ptr);
108
114 void startLookingForPass(const Update& event);
115
121 void lookForPass(const Update& event);
122
128 void shootBall(const Update& event);
129
135 void passBall(const Update& event);
136
142 void chipBall(const Update& event);
143
151 bool shotFound(const Update& event);
152
160 bool passFound(const Update& event);
161
169 bool shouldAbortPass(const Update& event);
170
178 bool timeExpired(const Update& event);
179
187 bool shotDone(const Update& event);
188
196 bool passDone(const Update& event);
197
205 bool chipDone(const Update& event);
206
207 auto operator()()
208 {
209 using namespace boost::sml;
210
211 DEFINE_SML_STATE(SetupPositionState)
212 DEFINE_SML_STATE(ShootState)
213 DEFINE_SML_STATE(AttemptPassState)
214 DEFINE_SML_STATE(PassState)
215 DEFINE_SML_STATE(ChipState)
216
217 DEFINE_SML_EVENT(Update)
218
219 DEFINE_SML_ACTION(setupPosition)
220 DEFINE_SML_ACTION(shootBall)
221 DEFINE_SML_ACTION(startLookingForPass)
222 DEFINE_SML_ACTION(lookForPass)
223 DEFINE_SML_ACTION(passBall)
224 DEFINE_SML_ACTION(chipBall)
225
226 DEFINE_SML_GUARD(setupDone)
227 DEFINE_SML_GUARD(shotFound)
228 DEFINE_SML_GUARD(shotDone)
229 DEFINE_SML_GUARD(shouldAbortPass)
230 DEFINE_SML_GUARD(passFound)
231 DEFINE_SML_GUARD(passDone)
232 DEFINE_SML_GUARD(chipDone)
233 DEFINE_SML_GUARD(timeExpired)
234
235 return make_transition_table(
236 // src_state + event [guard] / action = dest_state
237 // Start with setting up the position of the kicker
238 *SetupPositionState_S + Update_E[!setupDone_G] / setupPosition_A =
239 SetupPositionState_S,
240
241 // Shoot towards the enemy net directly if there is a clear shot
242 SetupPositionState_S + Update_E[shotFound_G] = ShootState_S,
243 ShootState_S + Update_E[!shotDone_G] / shootBall_A = ShootState_S,
244 ShootState_S + Update_E[shotDone_G] = X,
245
246 // Otherwise, start looking for a pass
247 SetupPositionState_S + Update_E / startLookingForPass_A = AttemptPassState_S,
248
249 // If the time to look for a pass is over, chip the ball towards the enemy net
250 AttemptPassState_S + Update_E[timeExpired_G] = ChipState_S,
251
252 // Keep looking for a pass
253 AttemptPassState_S + Update_E[!passFound_G] / lookForPass_A =
254 AttemptPassState_S,
255 AttemptPassState_S + Update_E[passFound_G] = PassState_S,
256
257 PassState_S + Update_E[shouldAbortPass_G] = AttemptPassState_S,
258 PassState_S + Update_E[!passDone_G] / passBall_A = PassState_S,
259 PassState_S + Update_E[passDone_G] = X,
260
261 ChipState_S + Update_E[!chipDone_G] / chipBall_A = ChipState_S,
262 ChipState_S + Update_E[chipDone_G] = X);
263 }
264
265 private:
266 TbotsProto::AiConfig ai_config;
267 std::optional<Shot> shot;
268 std::shared_ptr<MoveTactic> align_to_ball_tactic;
269 std::shared_ptr<KickTactic> shoot_tactic;
270 std::shared_ptr<ChipTactic> chip_tactic;
271 std::shared_ptr<KickTactic> passer_tactic;
272 std::shared_ptr<ReceiverTactic> receiver_tactic;
273 std::vector<std::shared_ptr<MoveTactic>> receiver_positioning_tactics;
274 std::shared_ptr<DefensePlay> defense_play;
275
276 ReceiverPositionGenerator<EighteenZoneId> receiver_position_generator;
277 PassGenerator pass_generator;
278 PassWithRating best_pass_and_score_so_far;
279 Timestamp pass_optimization_start_time;
280};
Definition pass_generator.h:15
Definition receiver_position_generator.hpp:20
Definition timestamp.h:21
Definition free_kick_play_fsm.h:37
Definition free_kick_play_fsm.h:29
void lookForPass(const Update &event)
Definition free_kick_play_fsm.cpp:209
void shootBall(const Update &event)
Definition free_kick_play_fsm.cpp:143
bool shouldAbortPass(const Update &event)
Definition free_kick_play_fsm.cpp:264
void setupPosition(const Update &event)
Definition free_kick_play_fsm.cpp:24
void setReceiverAndDefenderTactics(PriorityTacticVector &tactics_to_run, const Update &event, int ideal_num_receivers, int num_tactics_already_assigned, const std::vector< Point > &existing_receiver_positions={}, const std::optional< Point > &pass_origin_override=std::nullopt)
Definition free_kick_play_fsm.cpp:78
bool timeExpired(const Update &event)
Definition free_kick_play_fsm.cpp:163
bool chipDone(const Update &event)
Definition free_kick_play_fsm.cpp:314
void updateAlignToBallTactic(const WorldPtr &world_ptr)
Definition free_kick_play_fsm.cpp:116
void startLookingForPass(const Update &event)
Definition free_kick_play_fsm.cpp:158
void updateReceiverPositioningTactics(const WorldPtr world, unsigned int num_tactics, const std::vector< Point > &existing_receiver_positions={}, const std::optional< Point > &pass_origin_override=std::nullopt)
Definition free_kick_play_fsm.cpp:44
bool shotFound(const Update &event)
Definition free_kick_play_fsm.cpp:131
bool setupDone(const Update &event)
Definition free_kick_play_fsm.cpp:39
bool shotDone(const Update &event)
Definition free_kick_play_fsm.cpp:304
bool passFound(const Update &event)
Definition free_kick_play_fsm.cpp:241
void passBall(const Update &event)
Definition free_kick_play_fsm.cpp:284
void chipBall(const Update &event)
Definition free_kick_play_fsm.cpp:171
bool passDone(const Update &event)
Definition free_kick_play_fsm.cpp:309
Definition pass_with_rating.h:6