Thunderbots Project
Loading...
Searching...
No Matches
game_state.h
1#pragma once
2
3#include "software/geom/point.h"
4#include "software/util/make_enum/make_enum.hpp"
5#include "software/world/ball.h"
6
7// clang-format off
8MAKE_ENUM(RefereeCommand,
9 // these enums map to the enums in ssl_referee.proto
10 HALT,
11 STOP,
12 NORMAL_START,
13 FORCE_START,
14 PREPARE_KICKOFF_US,
15 PREPARE_KICKOFF_THEM,
16 PREPARE_PENALTY_US,
17 PREPARE_PENALTY_THEM,
18 DIRECT_FREE_US,
19 DIRECT_FREE_THEM,
20 INDIRECT_FREE_US,
21 INDIRECT_FREE_THEM,
22 TIMEOUT_US,
23 TIMEOUT_THEM,
24 GOAL_US,
25 GOAL_THEM,
26 BALL_PLACEMENT_US,
27 BALL_PLACEMENT_THEM);
28// clang-format on
29
30MAKE_ENUM(RefereeStage,
31 // The first half is about to start.
32 // A kickoff is called within this stage.
33 // This stage ends with the NORMAL_START.
34 NORMAL_FIRST_HALF_PRE,
35 // The first half of the normal game, before half time.
36 NORMAL_FIRST_HALF,
37 // Half time between first and second halves.
38 NORMAL_HALF_TIME,
39 // The second half is about to start.
40 // A kickoff is called within this stage.
41 // This stage ends with the NORMAL_START.
42 NORMAL_SECOND_HALF_PRE,
43 // The second half of the normal game, after half time.
44 NORMAL_SECOND_HALF,
45 // The break before extra time.
46 EXTRA_TIME_BREAK,
47 // The first half of extra time is about to start.
48 // A kickoff is called within this stage.
49 // This stage ends with the NORMAL_START.
50 EXTRA_FIRST_HALF_PRE,
51 // The first half of extra time.
52 EXTRA_FIRST_HALF,
53 // Half time between first and second extra halves.
54 EXTRA_HALF_TIME,
55 // The second half of extra time is about to start.
56 // A kickoff is called within this stage.
57 // This stage ends with the NORMAL_START.
58 EXTRA_SECOND_HALF_PRE,
59 // The second half of extra time.
60 EXTRA_SECOND_HALF,
61 // The break before penalty shootout.
62 PENALTY_SHOOTOUT_BREAK,
63 // The penalty shootout.
64 PENALTY_SHOOTOUT,
65 // The game is over.
66 POST_GAME);
67
80{
81 public:
82 enum PlayState
83 {
84 HALT, // Robots must not move
85 STOP, // Robots must stay a set distance away from ball
86 SETUP, // Robots not on starting team must stay a set distance away from ball
87 READY, // A robot on the starting team may kick the ball
88 PLAYING // Normal play
89 };
90
91 // Types of restarts
92 enum RestartReason
93 {
94 NONE,
95 KICKOFF,
96 DIRECT,
97 INDIRECT,
98 PENALTY,
99 BALL_PLACEMENT
100 };
101
102 GameState()
103 : play_state_(HALT),
104 restart_reason_(NONE),
105 command_(RefereeCommand::HALT),
106 ball_(std::nullopt),
107 our_restart_(false),
108 ball_placement_point_(std::nullopt)
109 {
110 }
111
118 explicit GameState(const TbotsProto::GameState& game_state_proto);
119
125 void updateRefereeCommand(RefereeCommand gameState);
126
132 void updateBall(const Ball& ball);
133
139 void setRestartCompleted();
140
146 const RefereeCommand& getRefereeCommand() const;
147
153 RestartReason getRestartReason() const;
154
155 /*
156 * Rule queries
157 *
158 * See https://download.tigers-mannheim.de/rules/2018_ssl-rules.pdf
159 * for more details
160 */
161
167 bool isHalted() const;
168
175 bool isStopped() const;
176
182 bool isPlaying() const;
183
190 bool isKickoff() const;
191
198 bool isPenalty() const;
199
206 bool isBallPlacement() const;
207
217 bool isOurRestart() const;
218
226 bool isDirectFree() const;
227
235 bool isIndirectFree() const;
236
243 bool isOurKickoff() const;
244
251 bool isOurPenalty() const;
252
259 bool isOurDirectFree() const;
260
267 bool isOurIndirectFree() const;
268
275 bool isOurFreeKick() const;
276
283 bool isOurBallPlacement() const;
284
291 bool isTheirKickoff() const;
292
299 bool isTheirPenalty() const;
300
306 bool isTheirDirectFree() const;
307
313 bool isTheirIndirectFree() const;
314
320 bool isTheirFreeKick() const;
321
328 bool isTheirBallPlacement() const;
329
335 PlayState getPlayState(void) const;
336
343 bool isSetupRestart() const;
344
351 bool isSetupState() const;
357 bool isReadyState() const;
358
364 bool canKick() const;
365
372 bool stayAwayFromBall() const;
373
380 bool stayOnSide() const;
381
389 bool stayBehindPenaltyLine() const;
390
397 bool operator==(const GameState& other) const;
398
406 bool operator!=(const GameState& other) const;
407
414 std::optional<Point> getBallPlacementPoint(void) const;
415
421 std::optional<Ball> getBall(void) const;
422
429 void setBallPlacementPoint(Point placementPoint);
430
431 private:
432 PlayState play_state_;
433 RestartReason restart_reason_;
434 RefereeCommand command_;
435 std::optional<Ball> ball_;
436
437 // True if our team can kick the ball during a restart
438 bool our_restart_;
439
440 // The point at which the ball should be placed by robots before a restart. See
441 // Robocup SSL Rules 9.2.
442 std::optional<Point> ball_placement_point_;
443};
Definition ball.h:11
Holds the state of the game according to the referee.
Definition game_state.h:80
bool isSetupRestart() const
Definition game_state.cpp:238
bool operator==(const GameState &other) const
Definition game_state.cpp:424
bool isOurPenalty() const
Definition game_state.cpp:177
bool isTheirIndirectFree() const
Definition game_state.cpp:217
bool isOurIndirectFree() const
Definition game_state.cpp:187
bool isIndirectFree() const
Definition game_state.cpp:167
bool stayAwayFromBall() const
Definition game_state.cpp:259
PlayState getPlayState(void) const
Definition game_state.cpp:232
bool isPlaying() const
Definition game_state.cpp:136
bool isDirectFree() const
Definition game_state.cpp:162
bool isOurKickoff() const
Definition game_state.cpp:172
void setRestartCompleted()
Definition game_state.cpp:418
std::optional< Point > getBallPlacementPoint(void) const
Definition game_state.cpp:281
void updateBall(const Ball &ball)
Definition game_state.cpp:389
const RefereeCommand & getRefereeCommand() const
Definition game_state.cpp:412
std::optional< Ball > getBall(void) const
Definition game_state.cpp:286
bool isTheirPenalty() const
Definition game_state.cpp:207
bool stayOnSide() const
Definition game_state.cpp:265
bool isTheirFreeKick() const
Definition game_state.cpp:222
RestartReason getRestartReason() const
Definition game_state.cpp:407
bool stayBehindPenaltyLine() const
Definition game_state.cpp:271
bool isOurDirectFree() const
Definition game_state.cpp:182
void updateRefereeCommand(RefereeCommand gameState)
Definition game_state.cpp:292
bool isHalted() const
Definition game_state.cpp:126
bool isOurBallPlacement() const
Definition game_state.cpp:197
bool operator!=(const GameState &other) const
Definition game_state.cpp:433
bool isTheirBallPlacement() const
Definition game_state.cpp:227
bool isTheirKickoff() const
Definition game_state.cpp:202
bool isBallPlacement() const
Definition game_state.cpp:151
bool isTheirDirectFree() const
Definition game_state.cpp:212
bool isOurRestart() const
Definition game_state.cpp:156
bool isOurFreeKick() const
Definition game_state.cpp:192
bool isPenalty() const
Definition game_state.cpp:146
void setBallPlacementPoint(Point placementPoint)
Definition game_state.cpp:276
bool canKick() const
Definition game_state.cpp:254
bool isStopped() const
Definition game_state.cpp:131
bool isReadyState() const
Definition game_state.cpp:248
bool isSetupState() const
Definition game_state.cpp:243
bool isKickoff() const
Definition game_state.cpp:141
Definition point.h:14