Thunderbots Project
Loading...
Searching...
No Matches
play_selection_fsm.h
1#pragma once
2
3#include "proto/parameters.pb.h"
4#include "shared/constants.h"
5#include "software/ai/hl/stp/play/play.h"
6
8{
9 class Halt;
10 class Playing;
11 class Stop;
12 class SetPlay;
13 class OverridePlay;
14
15 struct Update
16 {
17 Update(const std::function<void(std::unique_ptr<Play>)>& set_current_play,
18 const GameState& game_state, const TbotsProto::AiConfig& ai_config)
19 : set_current_play(set_current_play),
20 game_state(game_state),
21 ai_config(ai_config)
22 {
23 }
24 std::function<void(std::unique_ptr<Play>)> set_current_play;
25 GameState game_state;
26 TbotsProto::AiConfig ai_config;
27 };
28
34 explicit PlaySelectionFSM(TbotsProto::AiConfig ai_config);
35
43 bool gameStateStopped(const Update& event);
44 bool gameStateHalted(const Update& event);
45 bool gameStatePlaying(const Update& event);
46 bool gameStateSetupRestart(const Update& event);
47
54 void setupSetPlay(const Update& event);
55 void setupStopPlay(const Update& event);
56 void setupHaltPlay(const Update& event);
57 void setupOffensePlay(const Update& event);
58
64 void resetSetPlay(const Update& event);
65
66 auto operator()()
67 {
68 using namespace boost::sml;
69
70 DEFINE_SML_STATE(SetPlay)
71 DEFINE_SML_STATE(Halt)
72 DEFINE_SML_STATE(Playing)
73 DEFINE_SML_STATE(Stop)
74
75 DEFINE_SML_GUARD(gameStateStopped)
76 DEFINE_SML_GUARD(gameStateHalted)
77 DEFINE_SML_GUARD(gameStatePlaying)
78 DEFINE_SML_GUARD(gameStateSetupRestart)
79
80 DEFINE_SML_EVENT(Update)
81
82 DEFINE_SML_ACTION(setupSetPlay)
83 DEFINE_SML_ACTION(setupStopPlay)
84 DEFINE_SML_ACTION(setupHaltPlay)
85 DEFINE_SML_ACTION(setupOffensePlay)
86 DEFINE_SML_ACTION(resetSetPlay)
87
88 return make_transition_table(
89 // src_state + event [guard] / action = dest_state
90
91 // Check for transitions to other states, if not then default to running the
92 // current play
93 *Halt_S + Update_E[gameStateStopped_G] / setupStopPlay_A = Stop_S,
94 Halt_S + Update_E[gameStatePlaying_G] / setupOffensePlay_A = Playing_S,
95 Halt_S + Update_E[gameStateSetupRestart_G] / setupSetPlay_A = SetPlay_S,
96
97 // Check for transitions to other states, if not then default to running the
98 // current play
99 Stop_S + Update_E[gameStateHalted_G] / setupHaltPlay_A = Halt_S,
100 Stop_S + Update_E[gameStatePlaying_G] / setupOffensePlay_A = Playing_S,
101 Stop_S + Update_E[gameStateSetupRestart_G] / setupSetPlay_A = SetPlay_S,
102
103 // Check for transitions to other states, if not then default to running the
104 // current play
105 Playing_S + Update_E[gameStateHalted_G] / setupHaltPlay_A = Halt_S,
106 Playing_S + Update_E[gameStateStopped_G] / setupStopPlay_A = Stop_S,
107 Playing_S + Update_E[gameStateSetupRestart_G] / setupSetPlay_A = SetPlay_S,
108
109 // Check for transitions to other states, if not then default to running the
110 // current play
111 SetPlay_S + Update_E[gameStateHalted_G] / (resetSetPlay_A, setupHaltPlay_A) =
112 Halt_S,
113 SetPlay_S + Update_E[gameStateStopped_G] / (resetSetPlay_A, setupStopPlay_A) =
114 Stop_S,
115 SetPlay_S + Update_E[gameStatePlaying_G] /
116 (resetSetPlay_A, setupOffensePlay_A) = Playing_S,
117 SetPlay_S + Update_E[gameStateSetupRestart_G] / setupSetPlay_A,
118
119 X + Update_E = X);
120 }
121
122 private:
123 TbotsProto::AiConfig ai_config;
124 std::optional<TbotsProto::PlayName> current_set_play;
125};
Holds the state of the game according to the referee.
Definition game_state.h:80
Definition play_selection_fsm.h:16
Definition play_selection_fsm.h:8
bool gameStateStopped(const Update &event)
Definition play_selection_fsm.cpp:21
void resetSetPlay(const Update &event)
Definition play_selection_fsm.cpp:125
void setupSetPlay(const Update &event)
Definition play_selection_fsm.cpp:41