From a9bd47b6bdabe3b3f324ca2bc4c4edca5a53d1d5 Mon Sep 17 00:00:00 2001 From: Lukewh Date: Mon, 23 Sep 2024 16:46:39 +0100 Subject: [PATCH] start charting results --- index.html | 48 ++++++++++++++++++++++++++++++++++++++ main.py | 7 ++++-- multi-play.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 index.html create mode 100644 multi-play.py diff --git a/index.html b/index.html new file mode 100644 index 0000000..c3936a4 --- /dev/null +++ b/index.html @@ -0,0 +1,48 @@ + + + + + +
+ +
+ + + + diff --git a/main.py b/main.py index 3bd0057..8e91111 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ from enum import Enum from random import randrange from time import sleep +print("v1") + class Stats(Enum): SPD = "SPEED" HND = "HANDLING" @@ -113,7 +115,7 @@ class Game(): print("") print(f"--- {self.p2.name} ---") - print(f"SP: {self.p2.SP} ---") + print(f"SP: {self.p2.SP}") else: print("========================================================") @@ -197,7 +199,7 @@ class Game(): self.leader = None print(f"> {self.p2.name} loses their lead") - sleep(5) + #sleep(5) self.round += 1 self.play_round() @@ -226,4 +228,5 @@ track.info() game = Game(player1, player2, track) game.roll_laps() +print(f"Laps: {game.laps}") game.play_round() diff --git a/multi-play.py b/multi-play.py new file mode 100644 index 0000000..8ed19dd --- /dev/null +++ b/multi-play.py @@ -0,0 +1,64 @@ +import subprocess + +runs = [] + +with open("runs.csv", "r") as data: + try: + runs = data.readlines() + print("Successfully opened runs.csv") + except: + print("runs.csv doesn't exist") + +number_of_runs = 100 + +def do_a_run(i): + print(f"Run {i}") + print("Playing Game") + command = "python main.py" + output = subprocess.check_output(command, shell=True, text=True) + + output_lines = output.splitlines() + + laps = 0 + p1_sp = 0 + p1_lead = 0 + p2_sp = 0, + p2_lead = 0 + winner = None + + line_cache = None + for line in output_lines: + line = line.strip() + if line_cache == "p1": + p1_sp = int(line.split("SP: ")[1]) + line_cache = None + if line_cache == "p2": + p2_sp = int(line.split("SP: ")[1]) + line_cache = None + if line.startswith("Laps:"): + laps = int(line.split("Laps:")[1].strip()) + if line.startswith("WINNER:"): + winner_line = line.split("WINNER: ")[1] + if "by" in winner_line: + winner_line = winner_line.split(" by ") + winner = winner_line[0] + if winner == "Player 1": + p1_lead = int(winner_line[1]) + else: + p2_lead = int(winner_line[1]) + else: + winner = "draw" + if line.startswith("--- Player 1"): + line_cache = "p1" + if line.startswith("--- Player 2"): + line_cache = "p2" + + runs.append(f"{laps},{p1_sp},{p1_lead},{p2_sp},{p2_lead},{winner}") + + if i < number_of_runs: + do_a_run(i + 1) + +do_a_run(1) + +with open("runs.csv", "w") as data: + data.write("\n".join(runs))