diff --git a/game.py b/game.py index f420e7e..ebfd45f 100644 --- a/game.py +++ b/game.py @@ -15,12 +15,26 @@ class Player: self.word = "" self.ready = False self.selection = -1 + self.shuffle = [] + self.shuffleinv = [] players[self.id] = self def beginturn(self): self.word = "" self.ready = False self.selection = -1 + self.shuffle = list(range( len(self.game.cards) - 1)) # do not shuffle the last card (the skip turn card) + random.shuffle(self.shuffle) + self.shuffleinv = list(range(len(self.shuffle))) + for i in range(len(self.shuffle)): + self.shuffleinv[self.shuffle[i]] = i; + + def realindex(self, index): + return self.shuffle[index] if index >= 0 and index < len(self.shuffle) else index + def virtualindex(self, index): + return self.shuffleinv[index] if index >= 0 and index < len(self.shuffleinv) else index + def realselection(self): + return self.realindex(self.selection) def join(self, word): if not self.joined: @@ -45,7 +59,7 @@ class Player: def status(self): friend = self.game.players[1] if self.game.players[0] == self else self.game.players[0] friendId = None if friend.joined else friend.id - friendSelection = friend.selection if self.game.selected else -1 + friendSelection = self.virtualindex( friend.realselection() if self.game.selected else -1 ) percent = None turns = self.game.turn - self.game.skips @@ -55,7 +69,7 @@ class Player: cards = [] for i in range(0, len(self.game.cards)): - cards.append({ "index": i, "name": self.game.cards[i], "my": self.selection == i, "friends": friendSelection == i }) + cards.append({ "index": i, "name": self.game.cards[self.realindex(i)], "my": self.selection == i, "friends": friendSelection == i }) return { "vocabulary": self.game.vocabulary, @@ -147,10 +161,10 @@ class Game: if self.started and not self.selected and all(p.selection >= 0 for p in self.players): self.selected = True self.turnResult = 1 - if any(p.selection == len(self.cards) - 1 for p in self.players): + if any(p.realselection() == len(self.cards) - 1 for p in self.players): self.skips += 1 self.turnResult = 3 - elif self.players[0].selection == self.players[1].selection: + elif self.players[0].realselection() == self.players[1].realselection(): self.score += 1 self.turnResult = 2 else: