+class Board
This commit is contained in:
parent
89c4a92d72
commit
9644a51f9f
29
main.py
29
main.py
@ -6,6 +6,9 @@
|
||||
| |
|
||||
|
||||
"""
|
||||
from random import randint
|
||||
from random import choice
|
||||
|
||||
|
||||
class TicTacToe:
|
||||
def __init__(self):
|
||||
@ -23,12 +26,34 @@ class TicTacToe:
|
||||
else:
|
||||
print("This field's taken.")
|
||||
|
||||
class Player:
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
|
||||
def make_random_move(self, state):
|
||||
sequence = ["X", "O"]
|
||||
|
||||
emptyField = True
|
||||
while emptyField:
|
||||
field = state[randint(0,8)]
|
||||
if field == " ":
|
||||
state[field] = choice(sequence)
|
||||
emptyField = False
|
||||
|
||||
|
||||
player = Player("X")
|
||||
player1 = Player("O")
|
||||
|
||||
game = TicTacToe()
|
||||
game.print()
|
||||
|
||||
game.make_move("X", 0)
|
||||
game.print()
|
||||
for x in range(1,10):
|
||||
player.make_random_move(game.state)
|
||||
game.print()
|
||||
player1.make_random_move(game.state)
|
||||
game.print()
|
||||
|
||||
|
||||
|
||||
# make_move(state, "X", 0)
|
||||
# print_board(state)
|
||||
|
Loading…
Reference in New Issue
Block a user