-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.py
81 lines (61 loc) · 2.05 KB
/
Tests.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
81
from Constants import *
from MonteCarloTreeSearch import *
from MinimaxAlphaBeta import *
class MCTSvsMinimax:
def main():
wins = {}
wins[AGENT] = 0
wins[OPP] = 0
for i in range(10):
board = Board()
turn = AGENT
count = 0
agent = mctsAgent(AGENT)
while not board.isTerminal()[0]:
if turn == AGENT:
move, piece = agent.mcts(board, AGENT, 5)
else:
move, score, piece, = maxValue(OPP, 3, board)
if move == None:
board.movesLeft = False
break
board.move(piece, move)
turn = board.changeTurn()
count += 1
if board.isTerminal()[0]:
result = board.isTerminal()
if result[1] == AGENT:
wins[AGENT] += 1
else:
wins[OPP] += 1
print(wins)
main()
class MCTSvsAlphaBeta:
def main():
wins = {}
wins[AGENT] = 0
wins[OPP] = 0
for i in range(10):
board = Board()
turn = AGENT
count = 0
agent = mctsAgent(AGENT)
while not board.isTerminal()[0]:
if turn == AGENT:
move, piece = agent.mcts(board, AGENT, 5)
else:
move, score, piece, = alphaMaxValue(OPP, 3, board, -float("inf"), float("inf"))
if move == None:
board.movesLeft = False
break
board.move(piece, move)
turn = board.changeTurn()
count += 1
if board.isTerminal()[0]:
result = board.isTerminal()
if result[1] == AGENT:
wins[AGENT] += 1
else:
wins[OPP] += 1
print(wins)
main()