1
+
2
+ import sys
3
+ import os
4
+ from google .protobuf .timestamp_pb2 import Timestamp
5
+ from google .protobuf .duration_pb2 import Duration
6
+
7
+ # Make sure to go back to the main roboteam directory
8
+ current_dir = os .path .dirname (os .path .abspath (__file__ ))
9
+ roboteam_path = os .path .abspath (os .path .join (current_dir , ".." , ".." , ".." ))
10
+
11
+ # Add to sys.path
12
+ sys .path .append (roboteam_path )
13
+
14
+ # Assuming you have generated Python classes from your .proto files
15
+ from roboteam_networking .proto_CI .ssl_gc_state_pb2 import State , GameState , Command
16
+ from roboteam_networking .proto_CI .ssl_gc_referee_message_pb2 import Referee
17
+ from roboteam_networking .proto_CI .ssl_gc_common_pb2 import Team
18
+
19
+
20
+ def reset_game_state_blue_kickoff ():
21
+ # Create a new State message
22
+ new_state = State ()
23
+
24
+ # Set the GameState to KICKOFF for Blue team
25
+ new_state .game_state .type = GameState .KICKOFF
26
+ new_state .game_state .for_team = Team .BLUE
27
+
28
+ # Set the current command to KICKOFF for Blue team
29
+ new_state .command .type = Command .KICKOFF
30
+ new_state .command .for_team = Team .BLUE
31
+
32
+ # Set Blue team as the first kickoff team
33
+ new_state .first_kickoff_team = Team .BLUE
34
+
35
+ # Reset stage and timers
36
+ new_state .stage = Referee .NORMAL_FIRST_HALF
37
+ new_state .stage_time_elapsed .Clear ()
38
+ new_state .stage_time_left .Clear ()
39
+ new_state .match_time_start .GetCurrentTime () # Set to current time
40
+
41
+ # Reset team states
42
+ for team , is_blue in [("Blue" , True ), ("Yellow" , False )]:
43
+ team_info = new_state .team_state [team ]
44
+ team_info .name = team
45
+ team_info .goals = 0
46
+ team_info .yellow_cards .clear ()
47
+ team_info .red_cards .clear ()
48
+ team_info .timeouts_left = 4 # Or appropriate number
49
+ team_info .timeout_time_left .CopyFrom (Duration (seconds = 300 )) # 5 minutes
50
+ team_info .ball_placement_failures = 0
51
+ team_info .on_positive_half = is_blue # Blue on positive half, Yellow on negative
52
+
53
+ return new_state
54
+
55
+ # Usage
56
+ new_state_change = reset_game_state_blue_kickoff ()
57
+ # Use this new_state_change to update your game controller state
0 commit comments