sasa
This commit is contained in:
parent
9644a51f9f
commit
5944ed9a4e
34
main.py
34
main.py
@ -11,13 +11,20 @@ from random import choice
|
||||
|
||||
|
||||
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):
|
||||
self.state = list(" "*9)
|
||||
|
||||
|
||||
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"
|
||||
|
||||
print(board)
|
||||
|
||||
def make_move(self, token, field):
|
||||
@ -26,38 +33,33 @@ class TicTacToe:
|
||||
else:
|
||||
print("This field's taken.")
|
||||
|
||||
def get_state():
|
||||
pass
|
||||
|
||||
def get_action():
|
||||
pass
|
||||
|
||||
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
|
||||
return
|
||||
|
||||
|
||||
player = Player("X")
|
||||
player1 = Player("O")
|
||||
player1 = Player("X")
|
||||
player2 = Player("O")
|
||||
|
||||
game = TicTacToe()
|
||||
game.print()
|
||||
game.run()
|
||||
|
||||
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)
|
||||
# make_move(state, "O", 3)
|
||||
# print_board(state)
|
||||
# make_move(state, "X", 0)
|
||||
# print_board(state)
|
Loading…
Reference in New Issue
Block a user