Skip to content

Commit

Permalink
Draw the finish time + optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Dec 2, 2024
1 parent e6c205f commit 729d3d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions racer/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
framerate = 60
rounds = 3
frames_after_finish = 25_000
4 changes: 4 additions & 0 deletions racer/game_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .car import Car
from .car_info import CarInfo
from .cars import car1
from .constants import rounds
from .track import Track


Expand Down Expand Up @@ -35,6 +36,9 @@ def reset(self):
def update(self, dt: float):
self.frames += 1
for bot, car_info in self.bots.items():
if car_info.round >= rounds:
continue

result, cpu = self.get_bot_commands(bot, car_info)

car_info.cpu += cpu
Expand Down
7 changes: 5 additions & 2 deletions racer/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pygame_widgets.button import Button
from pygame_widgets.dropdown import Dropdown

from .constants import framerate
from .constants import framerate, rounds
from .game_state import GameState
from .linear_math import Transform
from .track import Track
Expand Down Expand Up @@ -135,7 +135,10 @@ def draw(self, clock):
self.window.blit(text, (self.window.get_width() - 300, offset_from_top + i * 20))

# Draw behind time
text = self.font.render(f'{behind:+.2f}', True, Color('white'))
if car_info.round >= rounds:
text = self.font.render(f'{car_info.waypoint_timing[-1]:.3f}', True, Color('white'))
else:
text = self.font.render(f'{behind:+.3f}', True, Color('white'))
self.window.blit(text, (self.window.get_width() - 50, offset_from_top + i * 20))

def selected_track(self):
Expand Down
3 changes: 1 addition & 2 deletions tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pygame
import tqdm

from racer.constants import framerate, rounds
from racer.constants import framerate, rounds, frames_after_finish
from racer.game_state import GameState
from racer.track import Track
from racer.tracks import all_tracks
Expand Down Expand Up @@ -56,7 +56,6 @@ def main(track):

def single_game(track):
min_frames = 6000
frames_after_finish = 25_000

game_state = GameState(track)
finishing = False
Expand Down

0 comments on commit 729d3d6

Please sign in to comment.