def on_tick( self, tick: TrainingTickPacket) -> Optional[Union[Pass, WrongGoalFail]]: score = { team.team_index: team.score for team in tick.game_tick_packet.teams } # Initialize or re-initialize due to some major change in the tick packet. if (self.init_score is None or score.keys() != self.init_score.keys() or any(score[t] < self.init_score[t] for t in self.init_score)): self.init_score = score return scoring_team_id = None for team_id in self.init_score: if self.init_score[team_id] < score[ team_id]: # team score value has increased assert scoring_team_id is None, "Only one team should score per tick." scoring_team_id = team_id if scoring_team_id is not None: return Pass( ) if scoring_team_id == self.ally_team else WrongGoalFail()
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: packet = tick.game_tick_packet if self.first_time is None: self.first_time = packet.game_info.seconds_elapsed self.last_packet = packet car = packet.game_cars[self.car_index] if self.init_team_score is None: self.init_team_score = packet.teams[car.team].score # Wait for new goal if packet.teams[car.team].score == self.init_team_score: return None # Are we in kickoff countdown? if self.goal_time is None: self.goal_time = packet.game_info.seconds_elapsed # if packet.game_info.seconds_elapsed - self.goal_time > 5.0: # return GotSpawnLocation(spawn_location=car.physics.location, yaw_over_pi=car.physics.rotation.yaw / pi) ball_y = packet.game_ball.physics.location.y if packet.game_info.seconds_elapsed - self.first_time > 6 and abs( ball_y) > 4000: scored_for_ally = ball_y > 0 if car.team == 1: scored_for_ally = not scored_for_ally if scored_for_ally: return Pass() else: return WrongGoalFail() return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: packet = tick.game_tick_packet if self.first_packet_time is None: self.first_packet_time = time.time() self.blue_first_loc_y = packet.game_cars[0].physics.location.y self.orange_first_loc_y = packet.game_cars[1].physics.location.y else: # Compare y location to check if bots have moved blue_new_loc_y = packet.game_cars[0].physics.location.y self.blue_moved = self.blue_moved or abs(self.blue_first_loc_y - blue_new_loc_y) > 5 orange_new_loc_y = packet.game_cars[1].physics.location.y self.orange_moved = self.orange_moved or abs( self.orange_first_loc_y - orange_new_loc_y) > 5 # Both bots have moved! if time.time( ) - self.first_packet_time > self.test_min_time and self.blue_moved and self.orange_moved: return Pass() # Check if time is up. If so fail test if time.time() - self.first_packet_time > self.test_total_time: if not self.blue_moved and not self.orange_moved: return FailDueToNoMovement(packet.game_cars[0].name, packet.game_cars[1].name) if not self.blue_moved: return FailDueToNoMovement(packet.game_cars[0].name) else: return FailDueToNoMovement(packet.game_cars[1].name) return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: car = tick.game_tick_packet.game_cars[self.car_index].physics.location ball = tick.game_tick_packet.game_ball.physics.location dist = sqrt((car.x - ball.x)**2 + (car.y - ball.y)**2) if dist <= self.min_dist_to_pass: return Pass() return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: target = self.target ball = tick.game_tick_packet.game_ball.physics.location dist = sqrt((target.x - ball.x)**2 + (target.y - ball.y)**2) if dist <= self.min_dist_to_pass: return Pass() return None
def on_tick( self, tick: TrainingTickPacket) -> Optional[Union[Pass, WrongGoalFail]]: to_own_goal = 1 if self.ally_team == 0 else -1 if tick.game_tick_packet.game_ball.physics.velocity.y * to_own_goal > 0: self.consequtive_good_ticks += 1 else: self.consequtive_good_ticks = 0 if self.consequtive_good_ticks >= self.REQUIRED_CONSECUTIVE_TICKS: return Pass()
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: assert self.matchcomms if not self.initialized: self.matchcomms.outgoing_broadcast.put_nowait('start') if not self.matchcomms.incoming_broadcast.empty(): print(self.matchcomms.incoming_broadcast.get_nowait()) return Pass() return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: if not self.has_pressed_h: hide_hud_macro() do_director_spectating_macro() show_percentages_macro() hide_rendering_macro() self.has_pressed_h = True self.replay_monitor.ensure_monitoring() # Check for mercy rule self.mercy_rule.check_for_mercy(tick.game_tick_packet) if self.mercy_rule.game_ended: self.match_result = fetch_match_score(tick.game_tick_packet) time.sleep( 1 ) # Give time for replay_monitor to register replay and for RL to load main menu if self.replay_monitor.replay_id or self.replay_monitor.replay_preference == ReplayPreference.IGNORE_REPLAY: self.replay_monitor.stop_monitoring() return Pass() # Check if game is over and replay recorded self.last_game_tick_packet = tick.game_tick_packet game_info = tick.game_tick_packet.game_info if game_info.is_match_ended and self.saw_active_packets: self.match_result = fetch_match_score(tick.game_tick_packet) if self.replay_monitor.replay_id or self.replay_monitor.replay_preference == ReplayPreference.IGNORE_REPLAY: self.replay_monitor.stop_monitoring() return Pass() seconds_since_game_end = game_info.seconds_elapsed - self.last_match_time if seconds_since_game_end > 15: self.replay_monitor.stop_monitoring() return FailDueToNoReplay() else: if game_info.is_round_active and not game_info.is_match_ended: self.saw_active_packets = True self.last_match_time = game_info.seconds_elapsed return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: self.replay_monitor.ensure_monitoring() self.last_game_tick_packet = tick.game_tick_packet game_info = tick.game_tick_packet.game_info if game_info.is_match_ended: self.fetch_match_score(tick.game_tick_packet) if self.replay_monitor.replay_id: self.replay_monitor.stop_monitoring() return Pass() seconds_since_game_end = game_info.seconds_elapsed - self.last_match_time if seconds_since_game_end > 15: self.replay_monitor.stop_monitoring() return FailDueToNoReplay() else: self.last_match_time = game_info.seconds_elapsed return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: assert self.matchcomms incoming = self.matchcomms.incoming_broadcast outgoing = self.matchcomms.outgoing_broadcast while not incoming.empty(): message = incoming.get_nowait() if message == "initialized": self.initialized = True elif message == "pass" and self.initialized: return Pass() elif message == "fail" and self.initialized: return Fail() if not self.initialized: outgoing.put_nowait("start") return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: self.replay_monitor.ensure_monitoring() self.last_game_tick_packet = tick.game_tick_packet game_info = tick.game_tick_packet.game_info if game_info.is_match_ended and self.saw_active_packets: self.match_result = fetch_match_score(tick.game_tick_packet) if self.replay_monitor.replay_id or self.replay_monitor.replay_preference == ReplayPreference.IGNORE_REPLAY: self.replay_monitor.stop_monitoring() return Pass() seconds_since_game_end = game_info.seconds_elapsed - self.last_match_time if seconds_since_game_end > 15: self.replay_monitor.stop_monitoring() return FailDueToNoReplay() else: if game_info.is_round_active and not game_info.is_match_ended: self.saw_active_packets = True self.last_match_time = game_info.seconds_elapsed return None
def on_tick(self, tick: TrainingTickPacket) -> Optional[Grade]: self.replay_monitor.ensure_monitoring() self.last_game_tick_packet = tick.game_tick_packet game_info = tick.game_tick_packet.game_info if game_info.is_match_ended: self.fetch_match_score(tick.game_tick_packet) # Since a recent update to RLBot and due to how rlbottraining calls on_tick, we only get one # packet where game_info.is_math_ended is True. Now we setup a busy loop to wait for replay game_end_time = time.time() seconds_since_game_end = 0 while seconds_since_game_end < 30: seconds_since_game_end = time.time() - game_end_time if self.replay_monitor.replay_id: self.replay_monitor.stop_monitoring() return Pass() # 30 seconds passed with no replay self.replay_monitor.stop_monitoring() return FailDueToNoReplay() else: self.last_match_time = game_info.seconds_elapsed return None
def on_tick(self, game_tick_packet: GameTickPacket) -> Optional[Result]: car_pos = game_tick_packet.game_cars[0].physics.location ball_pos = game_tick_packet.game_ball.physics.location to_ball_x = ball_pos.x - car_pos.x to_ball_y = ball_pos.y - car_pos.y dist_to_ball = math.sqrt(to_ball_x ** 2 + to_ball_y ** 2) # Did we score? scores = [int(team.score) for team in game_tick_packet.teams] if self.init_scores is None: self.init_scores = scores elif scores != self.init_scores: if scores[0] - self.init_scores[0] > 0: return Pass() # GOOOAAL! elif scores[1] - self.init_scores[1] > 0: return FailWithReason('own goal') # oops # timeout seconds_elapsed = game_tick_packet.game_info.seconds_elapsed if self.init_game_seconds is None: self.init_game_seconds = seconds_elapsed if seconds_elapsed - self.init_game_seconds > self.timeout_seconds: overtime_ratio = 1/0 # this error is intentional return FailWithReason(f"Hit the timout of {self.timeout_seconds} seconds ({ratio_over_time}% over")
def on_tick(self, game_tick_packet: GameTickPacket) -> Optional[Result]: self.num_on_tick_calls += 1 if self.num_on_tick_calls >= 100: nonlocal test_self test_self.assertEqual(self.num_on_tick_calls-1, self.num_render_calls) return Pass()