58 lines
1.2 KiB
Python
58 lines
1.2 KiB
Python
from Player import Player
|
|
from Board import Board
|
|
|
|
"""
|
|
Gracz wykonuje ruch.
|
|
Sprawdzamy, czy mamy wygranego (remis).
|
|
Zmieniamy gracza.
|
|
Wracamy do 1.
|
|
`while noWinner():
|
|
player.make_move()
|
|
isWin()
|
|
swapPlayers()
|
|
`
|
|
|
|
Coś takiego
|
|
|
|
Twój kod dwa razy robi rzeczy
|
|
|
|
Zamiast zamienić gracza
|
|
|
|
I zrobić to raz
|
|
|
|
Linie 20-27 sa te same co 29-36
|
|
|
|
Tylko tam jest player 2
|
|
"""
|
|
|
|
class TicTacToe:
|
|
def __init__(self):
|
|
self.player1 = Player("X", "Player 1")
|
|
self.player2 = Player("O", "Player 2")
|
|
|
|
def run(self):
|
|
self.board = Board()
|
|
while True:
|
|
if len(self.board.empty_fields) == 0:
|
|
self.board.print()
|
|
print("It's a draw.")
|
|
break
|
|
|
|
self.board.make_move(self.player1.token, self.player1.choose_random_field(self.board.empty_fields))
|
|
if self.board.is_win(self.player1.token):
|
|
self.board.print()
|
|
print(self.player1.name + " has won.\n")
|
|
break
|
|
|
|
if len(self.board.empty_fields) == 0:
|
|
self.board.print()
|
|
print("It's a draw.")
|
|
break
|
|
|
|
self.board.make_move(self.player2.token, self.player2.choose_random_field(self.board.empty_fields))
|
|
if self.board.is_win(self.player2.token):
|
|
self.board.print()
|
|
print(self.player2.name + " has won.\n")
|
|
break
|
|
|