:3
This commit is contained in:
parent
71d34178f0
commit
b7b599e295
21
main.py
21
main.py
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from random import randint
|
from random import randint
|
||||||
from random import choice
|
|
||||||
|
|
||||||
|
|
||||||
class TicTacToe:
|
class TicTacToe:
|
||||||
"""
|
"""
|
||||||
@ -25,8 +23,15 @@ class TicTacToe:
|
|||||||
for x in range(1,10):
|
for x in range(1,10):
|
||||||
board.make_move(player1.token, player1.make_random_move(board.state))
|
board.make_move(player1.token, player1.make_random_move(board.state))
|
||||||
board.print()
|
board.print()
|
||||||
|
if board.isWin(player1.token):
|
||||||
|
print("Player 1 has won.")
|
||||||
|
break
|
||||||
|
|
||||||
board.make_move(player2.token, player2.make_random_move(board.state))
|
board.make_move(player2.token, player2.make_random_move(board.state))
|
||||||
board.print()
|
board.print()
|
||||||
|
if board.isWin(player2.token):
|
||||||
|
print("Player 2 has won.")
|
||||||
|
break
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -43,6 +48,18 @@ class Board:
|
|||||||
else:
|
else:
|
||||||
print("This field's taken.")
|
print("This field's taken.")
|
||||||
|
|
||||||
|
def isWin(self, token):
|
||||||
|
if((self.state[0] == token and self.state[1] == token and self.state[2] == token) or
|
||||||
|
(self.state[0] == token and self.state[4] == token and self.state[8] == token) or
|
||||||
|
(self.state[0] == token and self.state[3] == token and self.state[6] == token) or
|
||||||
|
(self.state[1] == token and self.state[4] == token and self.state[7] == token) or
|
||||||
|
(self.state[2] == token and self.state[5] == token and self.state[8] == token) or
|
||||||
|
(self.state[2] == token and self.state[4] == token and self.state[6] == token) or
|
||||||
|
(self.state[3] == token and self.state[4] == token and self.state[5] == token) or
|
||||||
|
(self.state[6] == token and self.state[7] == token and self.state[8] == token)):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def get_state():
|
def get_state():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user