-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheuristicTesting.py
More file actions
90 lines (67 loc) · 2.7 KB
/
heuristicTesting.py
File metadata and controls
90 lines (67 loc) · 2.7 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import numpy as np
import math
import time
from game import Game
from minimax import minimax, minValue, maxValue
from minimaxDepthLimit import minimaxDepth, minValueDepth, maxValueDepth
from alphabeta import alphaBeta, minValueAB, maxValueAB
from alphabetaDepthLimit import alphaBetaDepth, minValueABDepth, maxValueABDepth
from alphabetaHeuristic import alphaBetaDepthHeuristic, minValueABDepthHeuristic, maxValueABDepthHeuristic
from gui import getWinner
import random
random.seed(time.time())
if __name__ == "__main__":
gameCount = 100000
gameSize = 3
maxDepth = 3
heuristicWins = 0
noHeuristicWins = 0
ties = 0
for i in range(gameCount):
tictactoe = Game(gameSize)
while not(tictactoe.isTerminal(tictactoe.board)):
aiActionAB = alphaBetaDepthHeuristic(tictactoe, tictactoe.board, 1, 1, maxDepth)
tictactoe.board = tictactoe.result(tictactoe.board, aiActionAB, 1)
if (tictactoe.isTerminal(tictactoe.board)):
break
aiActionRand = random.choice(tictactoe.getActions(tictactoe.board))
#aiActionAB = alphaBetaDepth(tictactoe, tictactoe.board, 2, 1, 5)
tictactoe.board = tictactoe.result(tictactoe.board, aiActionRand, 2)
winner = getWinner(tictactoe)
if winner == 0:
ties += 1
elif winner == 1:
heuristicWins += 1
else:
noHeuristicWins += 1
#tictactoe.display()
#print()
print("Heuristic Wins:", heuristicWins)
print("Random Wins:", noHeuristicWins)
print("Ties:", ties)
print("---------------------------------------------------")
heuristicWins = 0
noHeuristicWins = 0
ties = 0
for i in range(gameCount):
tictactoe = Game(gameSize)
while not(tictactoe.isTerminal(tictactoe.board)):
aiActionAB = alphaBetaDepth(tictactoe, tictactoe.board, 1, 1, maxDepth)
tictactoe.board = tictactoe.result(tictactoe.board, aiActionAB, 1)
if (tictactoe.isTerminal(tictactoe.board)):
break
aiActionRand = random.choice(tictactoe.getActions(tictactoe.board))
#aiActionAB = alphaBetaDepth(tictactoe, tictactoe.board, 2, 1, 5)
tictactoe.board = tictactoe.result(tictactoe.board, aiActionRand, 2)
winner = getWinner(tictactoe)
if winner == 0:
ties += 1
elif winner == 1:
heuristicWins += 1
else:
noHeuristicWins += 1
#tictactoe.display()
#print()
print("No Heuristic Wins:", heuristicWins)
print("Random Wins:", noHeuristicWins)
print("Ties:", ties)