-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplay.py
More file actions
59 lines (49 loc) · 1.32 KB
/
play.py
File metadata and controls
59 lines (49 loc) · 1.32 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
#!/usr/bin/env python
"""
play noughts and crosses against a random agent or human opposition
"""
from engine import *
from value_network import *
from noughts_crosses import *
class User:
def query_print(self, board):
printBoard = []
for i in range(9):
if board[i] == players[0]:
printBoard.append("X")
elif board[i] == players[1]:
printBoard.append("O")
else:
printBoard.append("\033[93m" + str(i+1) + "\033[0;0m")
print """
| |
%s | %s | %s
___|___|___
| |
%s | %s | %s
___|___|___
| |
%s | %s | %s
| |
""" % tuple(printBoard)
def minimax(self, board, player):
self.query_print(board)
index = input("Type the number of the square to move ")
board[index-1] = player
return board
def self_play(engines):
'engines is a list of engines and engines[0] moves first'
board = initialBoard
player = players[0]
index = 0
while evaluate(board) is None:
board = engines[index].minimax(board, player)
player = next_player(player)
index = int(not index)
#print(board)
#pretty_print(board)
return evaluate(board)
if __name__ == "__main__":
e = Engine(optimal, 9, 0.7)
u = User()
self_play([e, u])