start charting results
This commit is contained in:
48
index.html
Normal file
48
index.html
Normal file
@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="chart">
|
||||
|
||||
</div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" integrity="sha512-ZwR1/gSZM3ai6vCdI+LVF1zSq/5HznD3ZSTk7kajkaj4D292NLuduDCO1c/NT8Id+jE58KYLKT7hXnbtryGmMg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script>
|
||||
async function letsGo() {
|
||||
const req = await fetch("./runs.csv");
|
||||
const data = await req.text();
|
||||
let lines = data.split("\n").map((l) => l.trim()).filter((l) => l !== "");
|
||||
const keys = lines.splice(0, 1)[0].split(",");
|
||||
lines = lines.map((l) => l.split(","));
|
||||
console.log(lines[0]);
|
||||
const d = lines.map((line) => {
|
||||
const datum = {};
|
||||
line.forEach((cell, index) => datum[keys[index]] = cell);
|
||||
return datum;
|
||||
});
|
||||
|
||||
const table = document.createElement("table");
|
||||
const thead = document.createElement("thead");
|
||||
table.appendChild(thead);
|
||||
const tr = document.createElement("tr");
|
||||
for (const key of keys) {
|
||||
const th = document.createElement("th");
|
||||
th.innerText = key;
|
||||
tr.appendChild(th);
|
||||
}
|
||||
thead.appendChild(tr);
|
||||
|
||||
const tbody = document.createElement("tbody");
|
||||
for (const row of d) {
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `<td>${row.laps}</td><td>${row.p1_sp}</td><td>${row.p1_lead}</td><td>${row.p2_sp}</td><td>${row.p2_lead}</td><td>${row.winner}</td>`;
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
table.appendChild(tbody);
|
||||
|
||||
document.getElementById("chart").appendChild(table);
|
||||
}
|
||||
letsGo();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
7
main.py
7
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()
|
||||
|
64
multi-play.py
Normal file
64
multi-play.py
Normal file
@ -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))
|
Reference in New Issue
Block a user