From 9644a51f9f032b72463625fc686bbe977461addd Mon Sep 17 00:00:00 2001 From: Paulina Nowak Date: Sun, 20 Dec 2020 21:46:22 +0100 Subject: [PATCH] +class Board --- main.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c312c81..3ad5f86 100644 --- a/main.py +++ b/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)