forked from UBC-Thunderbots/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffense_play_fsm.h
More file actions
91 lines (76 loc) · 2.79 KB
/
offense_play_fsm.h
File metadata and controls
91 lines (76 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include "proto/parameters.pb.h"
#include "shared/constants.h"
#include "software/ai/evaluation/possession.h"
#include "software/ai/hl/stp/play/defense/defense_play.h"
#include "software/ai/hl/stp/play/play_fsm.hpp"
#include "software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play.h"
#include "software/logger/logger.h"
struct OffensePlayFSM : PlayFSM<OffensePlayFSM>
{
/**
* Control Parameters for Offense Play
*/
struct ControlParams
{
};
class OffensiveState;
class DefensiveState;
/**
* Creates an offense play FSM
*
* @param ai_config_ptr shared pointer to ai_config
*/
explicit OffensePlayFSM(std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr);
/**
* Guard to check whether the enemy team has possession of the ball
*
* @param event the FSM event
*
* @return whether the enemy team has possession of the ball
*/
bool enemyHasPossession(const Update& event);
/**
* Action to configure the play for offensive gameplay
*
* @param event the FSM event
*/
void setupOffensiveStrategy(const Update& event);
/**
* Action to configure the play for defensive gameplay
*
* @param event the FSM event
*/
void setupDefensiveStrategy(const Update& event);
/**
* Helper function to set the tactics for the play depending on the
* specified number of attackers and defenders to setup
*
* @param event the FSM event
* @param num_shoot_or_pass the number of attackers (ShootOrPassPlay)
* @param num_defenders the number of defenders (DefensePlay)
*/
void setTactics(const Update& event, int num_shoot_or_pass, int num_defenders);
auto operator()()
{
using namespace boost::sml;
DEFINE_SML_STATE(OffensiveState)
DEFINE_SML_STATE(DefensiveState)
DEFINE_SML_EVENT(Update)
DEFINE_SML_GUARD(enemyHasPossession)
DEFINE_SML_ACTION(setupOffensiveStrategy)
DEFINE_SML_ACTION(setupDefensiveStrategy)
return make_transition_table(
// src_state + event [guard] / action = dest_state
*OffensiveState_S + Update_E[enemyHasPossession_G] /
setupDefensiveStrategy_A = DefensiveState_S,
OffensiveState_S + Update_E / setupOffensiveStrategy_A = OffensiveState_S,
DefensiveState_S + Update_E[!enemyHasPossession_G] /
setupOffensiveStrategy_A = OffensiveState_S,
DefensiveState_S + Update_E / setupDefensiveStrategy_A = DefensiveState_S,
X + Update_E = X);
}
private:
std::shared_ptr<ShootOrPassPlay> shoot_or_pass_play;
std::shared_ptr<DefensePlay> defense_play;
};