-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dodo.py
53 lines (47 loc) · 1.64 KB
/
test_dodo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""test du jeu dodo"""
import time
from dodo.dodo_game import DodoGame
def test(iterations: int, size: int, starting) -> None:
"""fonction de test"""
score: int = 0
tps1 = time.time()
max_val: float = 0
for i in range(iterations):
tps2 = time.time()
game = DodoGame(size=size, starting_player=starting)
while game.final():
# print(game)
if game.get_player() == 1:
play = game.strategy_mc(7333)
game.make_move(play)
game.set_player(player=2)
else:
play = game.strategy_random()
game.make_move(play)
game.set_player(player=1)
# on compte le nombre de parties gagnées par le joueur 1
if game.get_player() == 1:
if game.score() == 1:
score += 1
else:
if game.score() == -1:
score += 1
temps2: float = time.time() - tps2
max_val = max(temps2, max_val)
del game
print(f"Avancement : {i} winrate : {(score/(i+1))*100}")
temps: float = time.time() - tps1
print()
print(
f"Nb itérations : {iterations} | taille : {size} | joueur départ : {starting}"
)
print(f"Temps d'éxécution : {temps:.4f} secondes")
if iterations > 1:
print(
f"Temps par partie : {temps/iterations:.4f} secondes. Max : {max_val:.4f} secondes."
)
print(f"Nb de win pour le joueur 1: {score} {(score/iterations)*100:.2f}%")
print(
f"Nb de win pour le joueur 2: {iterations-score} {((iterations-score)/iterations)*100:.2f}%"
)
test(10, 4, 1)