Skip to content
Snippets Groups Projects
Commit b9e2bb83 authored by Lukas Hoffleit's avatar Lukas Hoffleit
Browse files

Grid kann bei initialisierung uebergeben werden

parent bf27e523
Branches
No related tags found
No related merge requests found
......@@ -30,11 +30,24 @@ class TicTacToeError(Exception):
"""TicTacToe Error"""
class TicTacToe():
def __init__(self) -> None:
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment