-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.py
More file actions
47 lines (45 loc) · 1.92 KB
/
Copy pathevaluate.py
File metadata and controls
47 lines (45 loc) · 1.92 KB
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
from quarto import Quarto
import numpy as np
def evaluate(sampleGame, cycles=50, print_end_value="\r"):
players = sampleGame._Quarto__players
# print("----------")
# print(f"{type(players[0]).__name__} (goes first) vs. {type(players[1]).__name__}")
agent1_win_count = 0
agent2_win_count = 0
tie_count = 0
total_games = 0
# for i in tqdm.tqdm(range(cycles)):
print(f"{type(players[0]).__name__} vs. {type(players[1]).__name__}")
for i in range(cycles):
sampleGame.reset()
winner = -1
current_player = 0
while winner < 0 and not sampleGame.check_finished():
piece_ok = False
piece = None
while not piece_ok:
# print(f"(P{current_player} ♟︎ )", end='')
piece = players[current_player].choose_piece()
piece_ok = sampleGame.select(piece)
piece_ok = False
current_player = 1 - current_player
sampleGame._Quarto__current_player = current_player
x, y = None, None
while not piece_ok:
# print(f"(P{current_player} 🙾 )", end='')
x, y = players[current_player].place_piece()
piece_ok = sampleGame.place(x, y)
winner = sampleGame.check_winner()
total_games += 1
if winner==0:
agent1_win_count+=1
# print('(P1.WIN)', end="")
elif winner==1:
agent2_win_count+=1
# print('(P2.WIN)', end="")
else:
tie_count+=1
# print('(TIE)', end="")
print(f"{type(players[0]).__name__} won: {round(agent1_win_count/total_games, 3)}, {type(players[1]).__name__} won: {round(agent2_win_count/total_games, 3)}, ties: {round(tie_count/total_games, 3)}, played {total_games} times! ", end=print_end_value)
print("\n----------")
# print(f"Played a total of {total_games} times!")