-
Notifications
You must be signed in to change notification settings - Fork 0
/
testratio.py
executable file
·48 lines (44 loc) · 1.24 KB
/
testratio.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
#!/usr/bin/env python3
# syntax: testratio.py <checkpoint> [netid]
from sys import stdout, argv
from random import choice
import neat
from Morpx import Morpx, play, listMoves
print("Loading network")
checkpoint = argv[1]
p = neat.Checkpointer.restore_checkpoint(checkpoint)
population = p.population
config = p.config
gid = None
if len(argv)==3:
gid = int(argv[2])
else:
for e in population:
gid = e
genome = population[gid]
network=neat.nn.recurrent.RecurrentNetwork.create(genome, config)
print("Running 100 games against random AI")
wins=0
losses=0
draws=0
for i in range(100):
network.reset()
turn = 0
player = 1+(i%2)
current_player = 1
game = Morpx()
while game.ended==0:
if current_player==player:
play(game, network, player, turn)
else:
xyxy=choice(listMoves(game))
game.set(int(xyxy[0]), int(xyxy[1]), int(xyxy[2]), int(xyxy[3]), current_player)
current_player = 2 if current_player==1 else 1
turn+=1
if game.ended==player:
wins+=1
elif game.ended==(2 if player==1 else 1):
losses+=1
else:
draws+=1
print("{}/{} Wins: {} Losses: {} Draws {} Score {}".format(checkpoint, gid, wins, losses, draws, 3*wins+draws))