This commit is contained in:
Paulina Nowak 2020-12-24 06:27:20 +01:00
parent a3ad4bf7ac
commit 24213bb713

View File

@ -13,9 +13,9 @@ class TicTacToe:
def __init__(self): def __init__(self):
self.player1 = Player("X", "Player 1") self.player1 = Player("X", "Player 1")
self.player2 = Player("O", "Player 2") self.player2 = Player("O", "Player 2")
self.board = Board()
def run(self): def run(self):
self.board = Board()
while True: while True:
self.board.make_move(self.player1.token, self.player1.choose_random_field(self.board.empty_fields)) self.board.make_move(self.player1.token, self.player1.choose_random_field(self.board.empty_fields))
self.board.print() self.board.print()
@ -54,6 +54,9 @@ class Board:
(self.state[6] == token and self.state[7] == token and self.state[8] == token)): (self.state[6] == token and self.state[7] == token and self.state[8] == token)):
print(name + " has won.") print(name + " has won.")
return True return True
if len(self.empty_fields) == 0:
print("It's a draw.")
return True
return False return False
def get_state(): def get_state():