-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmarkRandomVsRandom.py
More file actions
63 lines (48 loc) · 1.52 KB
/
BenchmarkRandomVsRandom.py
File metadata and controls
63 lines (48 loc) · 1.52 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from agents.AiAgent import AiAgent
from agents.RandomAiAgent import RandomAiAgent
from chess_backend.GameState import GameState
from chess_backend.common import PlayerEnum
class DummyNetwork:
def __call__(self, game_state):
count = len(game_state.legal_moves)
policy = [1 / count] * count
value = 0
return policy, value
def main(do_print=True):
net = DummyNetwork()
white = RandomAiAgent()
black = AiAgent(net)
game_number = 1
white_wins = 0
black_wins = 0
draws = 0
all = 0
while True:
game = GameState()
game.start_new()
idx = 1
while game.state == game.RUNNING:
if game.board.turn == PlayerEnum.white:
selected = white.select_action(game)
else:
selected = black.select_action(game)
game.apply(selected)
idx += 1
if game.state == game.WHITE_WON:
white_wins += 1
elif game.state == game.BLACK_WON:
black_wins += 1
elif game.state == game.STALEMATE:
draws += 1
elif game.state == game.DRAW:
draws += 1
all += 1
print(f"{game_number:4d}: "
f"white_wins:{(100 * white_wins) / all:3.2f}%\t"
f"black_wins:{(100 * black_wins) / all:3.2f}%\t"
f"draws:{(100 * draws) / all:3.2f}%")
game_number += 1
if __name__ == '__main__':
main()
# import cProfile
# cProfile.run('main(do_print=False)', sort="tottime")