diff --git a/racer/car_info.py b/racer/car_info.py index fa50e27..d321523 100644 --- a/racer/car_info.py +++ b/racer/car_info.py @@ -44,13 +44,13 @@ def update(self, dt: float, throttle: float, steering_command: float): class CarInfo: def __init__(self, car_type: Car, track: Track): # angle of the first section - starting_vector = track.lines[1] - track.lines[0] + starting_vector = track.lines[0] - track.lines[-1] starting_vector.normalize_ip() starting_rotation = Rotation(starting_vector[0], -starting_vector[1], starting_vector[1], starting_vector[0]) self.car_type = car_type self.track = track - self.car_physics = CarPhysics(Transform(starting_rotation, deepcopy(track.lines[0])), + self.car_physics = CarPhysics(Transform(starting_rotation, deepcopy(track.lines[-1])), Vector2()) self.round = 0 self.next_waypoint = 0 diff --git a/racer/game_state.py b/racer/game_state.py index a4c514c..f728054 100644 --- a/racer/game_state.py +++ b/racer/game_state.py @@ -69,7 +69,10 @@ def get_bot_commands(self, bot, car_info): def ranked(self) -> List[Bot]: # Search for the car_info with the longest waypoint_timing bots = list(self.bots.keys()) - bots.sort( - key=lambda bot: (self.bots[bot].round, self.bots[bot].next_waypoint, -self.bots[bot].waypoint_timing[-1]), - reverse=True) + + def bot_distance(bot): + info = self.bots[bot] + return info.round, info.next_waypoint, -info.waypoint_timing[-1] if info.waypoint_timing else 0 + + bots.sort(key=bot_distance, reverse=True) return bots diff --git a/racer/tracks/track1.py b/racer/tracks/track1.py index 9f7de48..66f8666 100644 --- a/racer/tracks/track1.py +++ b/racer/tracks/track1.py @@ -8,7 +8,6 @@ scale = 2 track_width = 15 lines = [ - (694.59796, 220.4221), (733.31953, 226.15862), (759.13391, 248.62669), (762.00217, 278.26542), @@ -55,4 +54,5 @@ (325.0699300000001, 197.95403), (358.05497, 214.68557), (414.46417, 222.33427), + (694.59796, 220.4221), ] diff --git a/racer/tracks/track2.py b/racer/tracks/track2.py index a79e40f..05c99ba 100644 --- a/racer/tracks/track2.py +++ b/racer/tracks/track2.py @@ -8,7 +8,6 @@ scale = 1 track_width = 30 lines = [ - (1226.2844, 739.13218), (985.75603, 907.33965), (964.77402, 953.11646), (985.03829, 996.35491), @@ -58,4 +57,5 @@ (1714.8148, 316.77504), (1706.158, 403.61958), (1658.7513, 449.78183), + (1226.2844, 739.13218), ] diff --git a/racer/window.py b/racer/window.py index 904fd18..2241648 100755 --- a/racer/window.py +++ b/racer/window.py @@ -124,9 +124,12 @@ def draw(self, clock): fastest_bot = self.game_state.ranked()[0] for i, bot in enumerate(self.game_state.ranked()): car_info = self.game_state.bots[bot] - fastest_bot_time = self.game_state.bots[fastest_bot].waypoint_timing[len(car_info.waypoint_timing) - 1] - own_time = car_info.waypoint_timing[len(car_info.waypoint_timing) - 1] - behind = own_time - fastest_bot_time + if car_info.waypoint_timing: + fastest_bot_time = self.game_state.bots[fastest_bot].waypoint_timing[len(car_info.waypoint_timing) - 1] + own_time = car_info.waypoint_timing[len(car_info.waypoint_timing) - 1] + behind = own_time - fastest_bot_time + else: + behind = 0 text = self.font.render(f'{bot.name} ({bot.contributor})', True, bot.color) self.window.blit(text, (self.window.get_width() - 300, offset_from_top + i * 20))