forked from coxmediagroup/Tic-Tac-Toe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
36 lines (30 loc) · 1.06 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
#!/usr/bin/python
from Board import Board
from Evaluation import Evaluation
from AI import AI
from View import View
class Game:
def __init__(self):
self.board = Board()
self.evaluation = Evaluation(self.board)
self.view = View(self.board)
def __finish(self, computerPlayer):
if self.evaluation.winner() == computerPlayer:
print "Computer player wins"
elif self.evaluation.isTie():
print "Tie game"
else:
print "Human player wins"
def run(self):
startPlayer = self.view.inputStartPlayer()
computerPlayer = 'X' if startPlayer == 2 else 'O'
ai = AI(computerPlayer, self.board)
while self.evaluation.winner() == None and not self.evaluation.isTie():
self.view.displayBoard()
if self.board.getPlayer() == computerPlayer:
ai.makeMove()
else:
move = self.view.inputMove()
self.board.move(move)
self.view.displayBoard()
self.__finish(computerPlayer)