Thunderbots Project
Loading...
Searching...
No Matches
shadow_enemy_fsm.h
1#pragma once
2
3#include "software/ai/evaluation/calc_best_shot.h"
4#include "software/ai/evaluation/enemy_threat.h"
5#include "software/ai/hl/stp/tactic/move/move_fsm.h"
6#include "software/ai/hl/stp/tactic/tactic.h"
7#include "software/geom/algorithms/distance.h"
8#include "software/logger/logger.h"
9
11{
12 public:
13 class BlockPassState;
14 class StealAndChipState;
15
16 // this struct defines the unique control parameters that the ShadowEnemyFSM requires
17 // in its update
19 {
20 // The Enemy Threat indicating which enemy to shadow
21 std::optional<EnemyThreat> enemy_threat;
22
23 // How far from the enemy the robot will position itself to shadow. If the enemy
24 // threat has the ball, it will position itself to block the shot on goal.
25 // Otherwise it will try to block the pass to the enemy threat.
26 double shadow_distance;
27 };
28
29 DEFINE_TACTIC_UPDATE_STRUCT_WITH_CONTROL_AND_COMMON_PARAMS
30
31
32 // Distance to chip the ball when trying to yeet it
33 // TODO (#1878): Replace this with a more intelligent chip distance system
34 static constexpr double YEET_CHIP_DISTANCE_METERS = 2.0;
35
36
45 static Point findBlockPassPoint(const Point &ball_position, const Robot &shadowee,
46 const double &shadow_distance);
47
59 static Point findBlockShotPoint(const Robot &robot, const Field &field,
60 const Team &friendlyTeam, const Team &enemyTeam,
61 const Robot &shadowee, const double &shadow_distance);
62
70 bool enemyThreatHasBall(const Update &event);
71
78 void blockPass(const Update &event);
79
86 void blockShot(const Update &event,
87 boost::sml::back::process<MoveFSM::Update> processEvent);
88
96 void stealAndChip(const Update &event);
97
98 auto operator()()
99 {
100 using namespace boost::sml;
101
102 DEFINE_SML_STATE(MoveFSM)
103 DEFINE_SML_STATE(BlockPassState)
104 DEFINE_SML_STATE(StealAndChipState)
105 DEFINE_SML_EVENT(Update)
106
107 DEFINE_SML_GUARD(enemyThreatHasBall)
108 DEFINE_SML_ACTION(blockPass)
109 DEFINE_SML_ACTION(stealAndChip)
110 DEFINE_SML_SUB_FSM_UPDATE_ACTION(blockShot, MoveFSM)
111
112 return make_transition_table(
113 // src_state + event [guard] / action = dest_state
114 *MoveFSM_S + Update_E[!enemyThreatHasBall_G] / blockPass_A = BlockPassState_S,
115 MoveFSM_S + Update_E / blockShot_A, MoveFSM_S = StealAndChipState_S,
116 BlockPassState_S + Update_E[!enemyThreatHasBall_G] / blockPass_A,
117 BlockPassState_S + Update_E[enemyThreatHasBall_G] / blockShot_A = MoveFSM_S,
118 StealAndChipState_S + Update_E[enemyThreatHasBall_G] / stealAndChip_A,
119 StealAndChipState_S + Update_E[!enemyThreatHasBall_G] / blockPass_A = X,
120 X + Update_E[!enemyThreatHasBall_G] / blockPass_A = BlockPassState_S,
121 X + Update_E[enemyThreatHasBall_G] / blockShot_A = MoveFSM_S,
122 X + Update_E / SET_STOP_PRIMITIVE_ACTION = X);
123 }
124};
Definition field.h:36
Definition point.h:14
Definition robot.h:16
Definition team.h:15
Definition move_fsm.h:6
Definition shadow_enemy_fsm.h:19
Definition shadow_enemy_fsm.h:11
void blockShot(const Update &event, boost::sml::back::process< MoveFSM::Update > processEvent)
Definition shadow_enemy_fsm.cpp:79
void blockPass(const Update &event)
Definition shadow_enemy_fsm.cpp:50
static Point findBlockShotPoint(const Robot &robot, const Field &field, const Team &friendlyTeam, const Team &enemyTeam, const Robot &shadowee, const double &shadow_distance)
Definition shadow_enemy_fsm.cpp:14
void stealAndChip(const Update &event)
Definition shadow_enemy_fsm.cpp:114
static Point findBlockPassPoint(const Point &ball_position, const Robot &shadowee, const double &shadow_distance)
Definition shadow_enemy_fsm.cpp:5
bool enemyThreatHasBall(const Update &event)
Definition shadow_enemy_fsm.cpp:38