Thunderbots Project
Loading...
Searching...
No Matches
play.h
1#pragma once
2
3#include <boost/bind.hpp>
4#include <boost/coroutine2/all.hpp>
5#include <vector>
6
7#include "proto/parameters.pb.h"
8#include "software/ai/hl/stp/play/play_fsm.h"
9#include "software/ai/hl/stp/tactic/goalie/goalie_tactic.h"
10#include "software/ai/hl/stp/tactic/tactic.h"
11#include "software/ai/navigator/trajectory/trajectory_planner.h"
12
13// This coroutine returns a list of list of shared_ptrs to Tactic objects
14using TacticCoroutine = boost::coroutines2::coroutine<PriorityTacticVector>;
15
33class Play
34{
35 public:
42 explicit Play(TbotsProto::AiConfig ai_config, bool requires_goalie);
43
54 virtual std::unique_ptr<TbotsProto::PrimitiveSet> get(
55 const WorldPtr& world_ptr, const InterPlayCommunication& inter_play_communication,
56 const SetInterPlayCommunicationCallback& set_inter_play_communication_fun);
57
63 const std::map<std::shared_ptr<const Tactic>, RobotId>& getTacticRobotIdAssignment()
64 const;
65
66 virtual ~Play() = default;
67
73 virtual std::vector<std::string> getState();
74
75 protected:
76 // The Play configuration
77 TbotsProto::AiConfig ai_config;
78
79 // Goalie tactic common to all plays
80 std::shared_ptr<GoalieTactic> goalie_tactic;
81
82 std::map<std::shared_ptr<const Tactic>, RobotId> tactic_robot_id_assignment;
83
84 // Cached robot trajectories
85 std::map<RobotId, TrajectoryPath> robot_trajectories;
86
87 // List of all obstacles in the world at the current iteration
88 // and all robot paths. Used for visualization
89 TbotsProto::ObstacleList obstacle_list;
90 TbotsProto::PathVisualization path_visualization;
91
92 // TODO (#2359): make pure virtual once all plays are not coroutines
99 virtual void updateTactics(const PlayUpdate& play_update);
100
101 private:
113 std::tuple<std::vector<Robot>, std::unique_ptr<TbotsProto::PrimitiveSet>,
114 std::map<std::shared_ptr<const Tactic>, RobotId>>
115 assignTactics(const WorldPtr& world_ptr, TacticVector tactic_vector,
116 const std::vector<Robot>& robots_to_assign);
117
135 PriorityTacticVector getTactics(const WorldPtr& world_ptr);
136
159 void getNextTacticsWrapper(TacticCoroutine::push_type& yield);
160
170 virtual void getNextTactics(TacticCoroutine::push_type& yield,
171 const WorldPtr& world_ptr) = 0;
172
173 // HaltTactics common to all plays for robots that don't have tactics assigned
174 TacticVector halt_tactics;
175
176 // Whether this play requires a goalie
177 const bool requires_goalie;
178
179 // TODO (#2359): remove this
180 // The coroutine that sequentially returns the Tactics the Play wants to run
181 TacticCoroutine::pull_type tactic_sequence;
182
183 // TODO (#2359): remove this
184 // The Play's knowledge of the most up-to-date World
185 std::optional<WorldPtr> world_ptr_;
186
187 // TODO (#2359): remove this
188 PriorityTacticVector priority_tactics;
189
190 uint64_t sequence_number = 0;
191
192 RobotNavigationObstacleFactory obstacle_factory;
193};
Definition play.h:34
virtual std::vector< std::string > getState()
Definition play.cpp:407
virtual void updateTactics(const PlayUpdate &play_update)
Definition play.cpp:252
const std::map< std::shared_ptr< const Tactic >, RobotId > & getTacticRobotIdAssignment() const
Definition play.cpp:228
virtual std::unique_ptr< TbotsProto::PrimitiveSet > get(const WorldPtr &world_ptr, const InterPlayCommunication &inter_play_communication, const SetInterPlayCommunicationCallback &set_inter_play_communication_fun)
Definition play.cpp:85
Definition robot_navigation_obstacle_factory.h:19
Definition play_fsm.h:15
Definition play_fsm.h:25