Better UI
This commit is contained in:
parent
f4587b307e
commit
14cb50e1d2
|
@ -36,10 +36,11 @@ width = 40
|
||||||
height = 40
|
height = 40
|
||||||
|
|
||||||
def run_battle(ai1, ai2):
|
def run_battle(ai1, ai2):
|
||||||
|
games = 50
|
||||||
ai1_victories = 0
|
ai1_victories = 0
|
||||||
ai2_victories = 0
|
ai2_victories = 0
|
||||||
|
|
||||||
for _ in range(50):
|
for _ in range(games):
|
||||||
initial_position_one = [random.randint(0, width - 1), random.randint(0, height - 1)]
|
initial_position_one = [random.randint(0, width - 1), random.randint(0, height - 1)]
|
||||||
initial_position_two = [random.randint(0, width - 1), random.randint(0, height - 1)]
|
initial_position_two = [random.randint(0, width - 1), random.randint(0, height - 1)]
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ def run_battle(ai1, ai2):
|
||||||
elif game.winner == 2:
|
elif game.winner == 2:
|
||||||
ai1_victories += 1
|
ai1_victories += 1
|
||||||
|
|
||||||
return (ai1_victories, ai2_victories)
|
return (ai1_victories, ai2_victories, 2 * games - ai1_victories - ai2_victories)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
@ -79,8 +80,8 @@ def main():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print("Battling {} vs {}".format(ai1.name, ai2.name))
|
print("Battling {} vs {}".format(ai1.name, ai2.name))
|
||||||
(score1, score2) = run_battle(ai1, ai2)
|
(score1, score2, nulls) = run_battle(ai1, ai2)
|
||||||
dictionnary["battles"][ai1.name + "/" + ai2.name] = score1 / (score1 + score2)
|
dictionnary["battles"][ai1.name + "/" + ai2.name] = [score1, score2, nulls]
|
||||||
|
|
||||||
with open("assets/data.json", "w") as f:
|
with open("assets/data.json", "w") as f:
|
||||||
f.write(json.dumps(dictionnary))
|
f.write(json.dumps(dictionnary))
|
||||||
|
|
34
server.js
34
server.js
|
@ -64,6 +64,8 @@ function parse(data) {
|
||||||
name: ai,
|
name: ai,
|
||||||
victories: 0,
|
victories: 0,
|
||||||
defeats: 0,
|
defeats: 0,
|
||||||
|
nulls: 0,
|
||||||
|
score: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,26 +73,26 @@ function parse(data) {
|
||||||
let battlers = key.split('/');
|
let battlers = key.split('/');
|
||||||
let ai1 = battlers[0];
|
let ai1 = battlers[0];
|
||||||
let ai2 = battlers[1];
|
let ai2 = battlers[1];
|
||||||
parsed.battles[ai1 + '/' + ai2] = Math.floor(100 * content.battles[key]);
|
parsed.battles[ai1 + '/' + ai2] = content.battles[key][0];
|
||||||
parsed.battles[ai2 + '/' + ai1] = 100 - parsed.battles[ai1 + '/' + ai2];
|
parsed.battles[ai2 + '/' + ai1] = content.battles[key][1];
|
||||||
|
|
||||||
|
let realAi1 = parsed.ais.find((x) => x.name == ai1);
|
||||||
|
let realAi2 = parsed.ais.find((x) => x.name == ai2);
|
||||||
|
realAi1.victories += content.battles[key][0];
|
||||||
|
realAi1.defeats += content.battles[key][1];
|
||||||
|
realAi2.victories += content.battles[key][1];
|
||||||
|
realAi2.defeats += content.battles[key][0];
|
||||||
|
realAi1.nulls += content.battles[key][2];
|
||||||
|
realAi2.nulls += content.battles[key][2];
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed.sortedAis = parsed.ais.slice(0);
|
parsed.sortedAis = parsed.ais.slice(0);
|
||||||
|
|
||||||
parsed.sortedAis.sort((a, b) => {
|
for (let ai of parsed.sortedAis) {
|
||||||
if (a.victories < b.victories) {
|
ai.score = ai.victories * 3 + ai.nulls;
|
||||||
return -1;
|
|
||||||
} else if (a.victories > b.victories) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
if (a.defeats > b.defeats) {
|
|
||||||
return -1;
|
|
||||||
} else if (a.defeats < b.defeats) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
parsed.sortedAis.sort((a, b) => b.score - a.score);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,35 +10,38 @@ block content
|
||||||
th
|
th
|
||||||
for ai in ais
|
for ai in ais
|
||||||
th.has-text-centered= ai.name
|
th.has-text-centered= ai.name
|
||||||
th.has-text-centered.has-text-success ✓
|
|
||||||
th.has-text-centered.has-text-danger ✗
|
|
||||||
for ai1 in ais
|
for ai1 in ais
|
||||||
tr
|
tr
|
||||||
th.has-text-centered= ai1.name
|
th.has-text-centered= ai1.name
|
||||||
for ai2 in ais
|
for ai2 in ais
|
||||||
if ai1.name == ai2.name
|
if ai1.name == ai2.name
|
||||||
td
|
td
|
||||||
else if battles[ai1.name + "/" + ai2.name] > 50
|
else if battles[ai1.name + "/" + ai2.name] > battles[ai2.name + "/" + ai1.name]
|
||||||
td.has-text-success= battles[ai1.name + "/" + ai2.name]
|
td.has-text-success= battles[ai1.name + "/" + ai2.name]
|
||||||
else if battles[ai1.name + "/" + ai2.name] < 50
|
else if battles[ai1.name + "/" + ai2.name] < battles[ai2.name + "/" + ai1.name]
|
||||||
td.has-text-danger= battles[ai1.name + "/" + ai2.name]
|
td.has-text-danger= battles[ai1.name + "/" + ai2.name]
|
||||||
else
|
else
|
||||||
td= battles[ai1.name + "/" + ai2.name]
|
td= battles[ai1.name + "/" + ai2.name]
|
||||||
td.has-text-centered
|
|
||||||
strong= 0
|
|
||||||
td.has-text-centered
|
|
||||||
strong= 0
|
|
||||||
.column.is-narrow.is-desktop
|
.column.is-narrow.is-desktop
|
||||||
table.table.is-bordered.is-striped.is-hoverable
|
table.table.is-bordered.is-striped.is-hoverable
|
||||||
tr
|
tr
|
||||||
th.has-text-centered AI
|
th.has-text-centered AI
|
||||||
|
th.has-text-centered Victories
|
||||||
|
th.has-text-centered Nulls
|
||||||
|
th.has-text-centered Defeats
|
||||||
th.has-text-centered Score
|
th.has-text-centered Score
|
||||||
for ai in sortedAis
|
for ai in sortedAis
|
||||||
tr
|
tr
|
||||||
td.has-text-centered
|
td.has-text-centered
|
||||||
strong= ai.name
|
strong= ai.name
|
||||||
td.has-text-centered
|
td.has-text-centered
|
||||||
strong= ai.victories - ai.defeats
|
strong= ai.victories
|
||||||
|
td.has-text-centered
|
||||||
|
strong= ai.nulls
|
||||||
|
td.has-text-centered
|
||||||
|
strong= ai.defeats
|
||||||
|
td.has-text-centered
|
||||||
|
strong= ai.score
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue