develop #2

Merged
swarga merged 10 commits from develop into master 2020-12-25 04:59:51 +01:00
Showing only changes of commit 24213bb713 - Show all commits

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):
Review

Ten cały blok kodu możnaby sprowadzić do:

  1. Gracz wykonuje ruch.
  2. Sprawdzamy, czy mamy wygranego (remis).
  3. Zmieniamy gracza.
  4. Wracamy do 1.
Ten cały blok kodu możnaby sprowadzić do: 1. Gracz wykonuje ruch. 2. Sprawdzamy, czy mamy wygranego (remis). 3. Zmieniamy gracza. 4. Wracamy do 1.
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():