-
Notifications
You must be signed in to change notification settings - Fork 4
/
Game.py
72 lines (55 loc) · 1.61 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
65
66
67
68
69
70
71
72
import random
import sys
from Engine import Engine
from Board import Board
class Game(object):
"""Handles the operations of a Game"""
def __init__(self, position=None):
super(Game, self).__init__()
self.board = Board(position)
self.engine = Engine(self.board, depth=7)
def input_move(self):
idx = None
while True:
try:
idx = int(input())
except:
print("Invalid Move")
continue
else:
break
if idx == 99:
sys.exit()
return idx
def human_move(self):
moves = self.board.generate_move_list()
self.board.show()
print("Please choose one move from the list.")
print('\n'.join("%d. %s" % (i, str(move)) for i, move in enumerate(moves)))
self.board.make_move(moves[self.input_move()])
def make_random_move(self):
move_list = self.board.generate_move_list()
# pick a random move
move = random.choice(move_list)
# make the move
self.board.make_move(move)
return move
def play():
game = Game()
while not game.board.winner:
game.human_move()
if game.board.winner:
break
game.engine.make_best_move()
game.board.show()
print(game.board.winner)
def ai_vs_ai():
game = Game('TGGGT/G3G/G3G/G3G/TGGGT g g8 c0 - -')
# move_num = 1
while not game.board.winner:
# print(move_num)
# move_num += 1
game.engine.make_best_move()
game.board.show()
return game.board.winner
play()