develop #1
24
main.py
24
main.py
@ -17,6 +17,16 @@ class TicTacToe:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
player1 = Player("X")
|
||||||
|
player2 = Player("O")
|
||||||
|
|
||||||
|
board = Board()
|
||||||
|
|
||||||
|
for x in range(1,10):
|
||||||
|
board.make_move(player1.token, player1.make_random_move(board.state))
|
||||||
|
board.print()
|
||||||
|
board.make_move(player2.token, player2.make_random_move(board.state))
|
||||||
|
board.print()
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -42,24 +52,20 @@ class Board:
|
|||||||
class Player:
|
class Player:
|
||||||
def __init__(self, token):
|
def __init__(self, token):
|
||||||
self.token = token
|
self.token = token
|
||||||
|
|
||||||
|
|
||||||
def make_random_move(self, state):
|
def make_random_move(self, state):
|
||||||
|
|
||||||
emptyField = True
|
emptyField = True
|
||||||
while emptyField:
|
while emptyField:
|
||||||
field = state[randint(0,8)]
|
randomField = randint(0,8)
|
||||||
|
field = state[randomField]
|
||||||
if field == " ":
|
if field == " ":
|
||||||
|
|||||||
return
|
return randomField
|
||||||
|
|
||||||
|
|
||||||
player1 = Player("X")
|
|
||||||
player2 = Player("O")
|
|
||||||
|
|
||||||
game = TicTacToe()
|
game = TicTacToe()
|
||||||
game.run()
|
game.run()
|
||||||
|
|
||||||
for x in range(1,10):
|
|
||||||
player.make_random_move(game.state)
|
|
||||||
game.print()
|
|
||||||
player1.make_random_move(game.state)
|
|
||||||
game.print()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
Do zaktualizowania.