-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplay.py
44 lines (36 loc) · 1.13 KB
/
play.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
from agent import Agent
import mnk
import tensorflow as tf
import model
import sys
board = mnk.Board(3, 3, 3)
#assert len(sys.argv) == 2, "Please specify which model you would like to play against (ex: python3 play.py models/PedrosModel).\n Tab complete works!"
#model = model.Model((3, 3, 3), sys.argv[1])
model = model.Model((3, 3, 3), "new_model")
print("\n\n" + str(board))
current_player = input("\nWho plays first (Me/AI)? ")
ai_side = [-1, 1][current_player == "AI"]
agent = Agent(model, ai_side)
while board.who_won() == 2:
if current_player == 'Me':
played = False
while not played:
move = int(input("What is your move (1-9)? "))
x = (move - 1) % 3
y = 2 - ((move - 1) // 3)
try:
board.move(x, y)
played = True
except:
print("Invalid move! Try again")
current_player = "AI"
else:
board.move(*agent.action(board))
current_player = "Me"
print(board)
if board.who_won() == 0:
print("Tie Game!")
elif current_player == "Me":
print("AI Wins!")
else:
print("You Win!")