65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
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))
|