Thunderbots Project
Loading...
Searching...
No Matches
world.h
1#pragma once
2
3
4#include <boost/circular_buffer.hpp>
5
6#include "software/world/ball.h"
7#include "software/world/field.h"
8#include "software/world/game_state.h"
9#include "software/world/team.h"
10
22class World final
23{
24 public:
25 World() = delete;
26
35 explicit World(const Field& field, const Ball& ball, const Team& friendly_team,
36 const Team& enemy_team, unsigned int buffer_size = 20);
37
44 explicit World(const TbotsProto::World& world_proto);
45
51 void updateBall(const Ball& new_ball);
52
58 void updateFriendlyTeamState(const Team& new_friendly_team_data);
59
65 void updateEnemyTeamState(const Team& new_enemy_team_data);
66
72 void updateRefereeCommand(const RefereeCommand& command);
73
80 void updateRefereeCommand(const RefereeCommand& command, Point ball_placement_point);
81
87 void updateRefereeStage(const RefereeStage& stage);
88
94 const Field& field() const;
95
101 const Ball& ball() const;
102
108 const Team& friendlyTeam() const;
109
115 const Team& enemyTeam() const;
116
122 const GameState& gameState() const;
123
129 void updateGameState(const GameState& game_state);
130
136 void updateGameStateBall(const Ball& ball);
137
143 const RefereeStage& getRefereeStage() const;
144
152 const Timestamp getMostRecentTimestamp() const;
153
162 void updateTimestamp(Timestamp timestamp);
163
169 void setTeamWithPossession(TeamPossession possession);
170
176 TeamPossession getTeamWithPossession() const;
177
186 bool operator==(const World& other) const;
187
194 bool operator!=(const World& other) const;
195
196 // The size of the referee history buffers to filter out noise with
197 static constexpr unsigned int REFEREE_COMMAND_BUFFER_SIZE = 3;
206 void setDribbleDisplacement(const std::optional<Segment>& displacement);
207
226 const std::optional<Segment>& getDribbleDisplacement() const;
227
228
229 private:
234 Timestamp getMostRecentTimestampFromMembers();
235
236 // Segment representing the displacement of the ball (in metres) due to
237 // the friendly team continuously dribbling the ball across the field
238 std::optional<Segment> dribble_displacement_;
239
240 Field field_;
241 Ball ball_;
242 Team friendly_team_;
243 Team enemy_team_;
244 GameState current_game_state_;
245 RefereeStage current_referee_stage_;
246 Timestamp last_update_timestamp_;
247 // A small buffer that stores previous referee command
248 boost::circular_buffer<RefereeCommand> referee_command_history_;
249 // A small buffer that stores previous referee stage
250 boost::circular_buffer<RefereeStage> referee_stage_history_;
251 // which team has possession of the ball
252 TeamPossession team_with_possession_;
253};
254
255using WorldPtr = std::shared_ptr<const World>;
Definition ball.h:11
Definition field.h:36
Holds the state of the game according to the referee.
Definition game_state.h:80
Definition point.h:14
Definition team.h:15
Definition timestamp.h:21
Definition world.h:23
const Timestamp getMostRecentTimestamp() const
Definition world.cpp:129
const Field & field() const
Definition world.cpp:61
void updateRefereeCommand(const RefereeCommand &command)
Definition world.cpp:81
bool operator!=(const World &other) const
Definition world.cpp:147
const Team & enemyTeam() const
Definition world.cpp:76
void updateBall(const Ball &new_ball)
Definition world.cpp:29
void updateTimestamp(Timestamp timestamp)
Definition world.cpp:48
void updateEnemyTeamState(const Team &new_enemy_team_data)
Definition world.cpp:42
void updateGameStateBall(const Ball &ball)
Definition world.cpp:153
void updateGameState(const GameState &game_state)
Definition world.cpp:158
void setTeamWithPossession(TeamPossession possession)
Definition world.cpp:168
const Ball & ball() const
Definition world.cpp:66
TeamPossession getTeamWithPossession() const
Definition world.cpp:173
const Team & friendlyTeam() const
Definition world.cpp:71
const RefereeStage & getRefereeStage() const
Definition world.cpp:163
const std::optional< Segment > & getDribbleDisplacement() const
Definition world.cpp:182
bool operator==(const World &other) const
Definition world.cpp:139
void setDribbleDisplacement(const std::optional< Segment > &displacement)
Definition world.cpp:177
const GameState & gameState() const
Definition world.cpp:134
void updateFriendlyTeamState(const Team &new_friendly_team_data)
Definition world.cpp:36
void updateRefereeStage(const RefereeStage &stage)
Definition world.cpp:102