This commit is contained in:
Paulina Nowak 2020-12-23 20:21:46 +01:00
parent 9644a51f9f
commit 5944ed9a4e

34
main.py
View File

@ -11,13 +11,20 @@ from random import choice
class TicTacToe: class TicTacToe:
"""
uruchamia program, gracze wykonuja na zmiane ruchy,
az do osiagniecia wygranej przez jednego z nich
"""
def run(self):
class Board:
def __init__(self): def __init__(self):
self.state = list(" "*9) self.state = list(" "*9)
def print(self): def print(self):
board = ""+ self.state[0] +"|"+self.state[1] +"|"+self.state[2] +" \n-|-|-\n"+self.state[3] +"|"+self.state[4] +"|"+self.state[5] +"\n-|-|-\n"+self.state[6] +"|"+self.state[7] +"|"+self.state[8] +"\n" board = ""+ self.state[0] +"|"+self.state[1] +"|"+self.state[2] +" \n-|-|-\n"+self.state[3] +"|"+self.state[4] +"|"+self.state[5] +"\n-|-|-\n"+self.state[6] +"|"+self.state[7] +"|"+self.state[8] +"\n"
print(board) print(board)
def make_move(self, token, field): def make_move(self, token, field):
@ -26,38 +33,33 @@ class TicTacToe:
else: else:
print("This field's taken.") print("This field's taken.")
def get_state():
pass
def get_action():
pass
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):
sequence = ["X", "O"]
emptyField = True emptyField = True
while emptyField: while emptyField:
field = state[randint(0,8)] field = state[randint(0,8)]
if field == " ": if field == " ":
state[field] = choice(sequence) return
emptyField = False
player = Player("X") player1 = Player("X")
player1 = Player("O") player2 = Player("O")
game = TicTacToe() game = TicTacToe()
game.print() game.run()
for x in range(1,10): for x in range(1,10):
player.make_random_move(game.state) player.make_random_move(game.state)
game.print() game.print()
player1.make_random_move(game.state) player1.make_random_move(game.state)
game.print() game.print()
# make_move(state, "X", 0)
# print_board(state)
# make_move(state, "O", 3)
# print_board(state)
# make_move(state, "X", 0)
# print_board(state)