-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
80 lines (62 loc) · 2.02 KB
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import random
from general import *
from network import *
from readwrite import *
class Test_Results:
def __init__(self, games, wins, draws, losses):
self.games = games
self.wins = wins
self.draws = draws
self.losses = losses
def print_results(self):
print(str(self.games) + " games")
print("wins: " + str(self.wins))
print("draws: " + str(self.draws))
print("losses: " + str(self.losses))
def random_move(board):
move = -1
while move not in avail_moves(board):
move = random.randint(0, 8)
return move
def play(player, games, nodes, situations):
wins = 0
losses = 0
draws = 0
for i in range(games):
board = [0 for i in range(9)]
curr_player = random.randint(0, 1)
if curr_player == 0:
curr_player = -1
while check_end(board) == 0:
if curr_player == 1:
board[random_move(board)] = 1
else:
if player == "nn":
board[find_move(nodes, board)] = -1
elif player == "ds":
board[search_move(board, situations)] = -1
elif player == "bm":
board[best_move(board.count(0), -1, board)] = -1
curr_player *= -1
result = check_end(board)
if result == -1:
wins += 1
elif result == 2:
draws += 1
elif result == 1:
losses += 1
return Test_Results(games, wins, draws, losses)
def main():
nodes = generate()
read_params(nodes, "good_params/12nodes_97percent_params.txt")
situations = read_situations("situations.txt")
print("\nnetwork vs random")
results = play("nn", 10000, nodes, situations)
results.print_results()
print("\ndataset searcher vs random")
results = play("ds", 10000, nodes, situations)
results.print_results()
print("\nbest_move vs random")
results = play("bm", 10000, nodes, situations)
results.print_results()
main()