morpion: add: Frontend checks, QOL changes and winning conditions
This commit is contained in:
@ -18,6 +18,10 @@ class TicTacToeGame(AGame):
|
||||
|
||||
self.players: list[TicTacToePlayer] = [TicTacToePlayer(player, None, self, ["x", "o"][i]) for i, player in enumerate(players)]
|
||||
|
||||
self.time = -1
|
||||
|
||||
self.turn = 'x'
|
||||
|
||||
self._map = [[-1 for _ in range(9)] for _ in range(9)]
|
||||
|
||||
def _everbody_is_here(self):
|
||||
@ -44,14 +48,15 @@ class TicTacToeGame(AGame):
|
||||
|
||||
if (self.checkMove(newmove, player)):
|
||||
self._map[newmove.get("targetMorpion")][newmove.get("targetCase")] = newmove.get("sign")
|
||||
player.currentMorpion = int(newmove.get("targetMorpion"))
|
||||
player.currentMorpion = int(newmove.get("targetCase"))
|
||||
self.turn = newmove.get("sign")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def checkMove(self, newmove, player):
|
||||
print(int(newmove.get("targetMorpion")), player.currentMorpion)
|
||||
if (int(newmove.get("targetMorpion")) != player.currentMorpion):
|
||||
if (int(newmove.get("targetMorpion")) != player.currentMorpion or newmove.get("sign") != self.turn):
|
||||
return False
|
||||
|
||||
if (self._map[newmove.get("targetMorpion")][newmove.get("targetCase")] != -1):
|
||||
@ -62,16 +67,16 @@ class TicTacToeGame(AGame):
|
||||
def checkWin(self):
|
||||
for tab in self._map:
|
||||
for i in range(3):
|
||||
if tab[i] == tab[i + 3] == tab[i + 6]:
|
||||
if tab[i] != -1 and tab[i] == tab[i + 3] and tab[i + 3] == tab[i + 6]:
|
||||
return tab[i]
|
||||
for i in range(0, 9, 3):
|
||||
if tab[i] == tab[i + 1] == tab[i + 2]:
|
||||
if tab[i] != -1 and tab[i] == tab[i + 1] and tab[i + 1] == tab[i + 2]:
|
||||
return tab[i]
|
||||
if tab[0] == tab[4] == tab[8]:
|
||||
if tab[0] != -1 and tab[0] == tab[4] and tab[4] == tab[8]:
|
||||
return tab[0]
|
||||
if tab[6] == tab[4] == tab[2]:
|
||||
if tab[6] != -1 and tab[6] == tab[4] and tab[4] == tab[2]:
|
||||
return tab[6]
|
||||
return None
|
||||
return False
|
||||
|
||||
|
||||
def _spectator_join(self, user_id: int, socket: WebsocketConsumer):
|
||||
|
Reference in New Issue
Block a user