diff --git a/tictactoe.py b/tictactoe.py index 1f552474313d4e3d3118afc2612f7267e1ac632a..6199eca2455404145ea30f8fdabff3c6916b48ce 100644 --- a/tictactoe.py +++ b/tictactoe.py @@ -30,11 +30,24 @@ class TicTacToeError(Exception): """TicTacToe Error""" class TicTacToe(): - def __init__(self) -> None: - grid = [] - for _ in range(3): - grid.append([Player.undefined, Player.undefined, Player.undefined]) + def __init__(self, *args) -> None: + """ + Creates a new TicTacToe object. + A grid can be passed optionally as a list of ints or Player objects. + """ + if args: + grid = [] + for i in args[0]: + line = [] + for j in i: + line.append(self._get_player_from_int(j)) + grid.append(line) + else: + grid = [] + for _ in range(3): + grid.append([Player.undefined, Player.undefined, Player.undefined]) self.grid = np.array(grid) + print(self.grid) @staticmethod def _get_player_from_int(player:Player|int) -> Player: @@ -189,9 +202,9 @@ class TicTacToe(): if __name__ == "__main__": ttt = TicTacToe() - #ttt.add(1, 1, 1) - #ttt.print_grid() - #ttt.add(2, 1, 2) + ttt.add(1, 1, 1) + ttt.print_grid() + ttt.add(2, 1, 2) ttt.print_grid() current_player = Player.one while ttt.check_winner() == Player.undefined: