-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
64 lines (61 loc) · 1.73 KB
/
game.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
from tictactoe import TicTacToe
from agents import *
from util import *
AGENT = ExpectimaxAgent
def run(game, agent):
if(game.gameState.T == 1):
'''
CPU TURN
'''
print("CPU Turn: ")
action = agent.getMove(game.gameState, 0.95, 0.0, 4)
game.gameState = game.transition(action)
return
'''
Player Turn
'''
print("Your Turn: ")
cmd = getInput(game)
handleInput(game, cmd)
if(__name__ == "__main__"):
N = 0
while(N < 3):
try:
N = input("Enter Board Size: ")
except NameError:
print("ERROR: Not a number")
continue
except SyntaxError:
print("ERROR: No input")
continue
if(N < 3):
print("ERROR: Can't play with a board size less than 3")
K = 0
while(K < 3 or K > N):
try:
K = input("Enter the number of adjacent squares needed to win: ")
except NameError:
print("ERROR: Not a number")
continue
except SyntaxError:
print("ERROR: No input")
continue
if(K > N):
print("ERROR: Can't be greater than board size")
elif(K < 3):
print("ERROR: Must be at least 3")
game = TicTacToe(N, K)
print(game)
help(game)
agent = AGENT(K)
won, winner = False, None
while(not(won) and sum(game.gameState.actions) > 0):
run(game, agent)
won, winner = agent.check(game.gameState)
print("CURRENT GAME STATE\n%s"%game)
if(not won): #Tie
print("Stalemate.")
elif(winner == 0): #Player Won
print("Victory is Yours!!!")
else: #CPU Won
print("FOOLISH MORTAL. TRY HARDER NEXT TIME.")