diff --git a/game.py b/game.py index fe9c431..92b1c58 100644 --- a/game.py +++ b/game.py @@ -13,6 +13,7 @@ class Player: self.id = str(uuid.uuid4()) self.joined = False self.word = "" + self.wordused = False self.ready = False self.selection = -1 self.shuffle = [] @@ -20,6 +21,7 @@ class Player: players[self.id] = self def beginturn(self): + self.wordused = self.word and self.word == self.game.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) @@ -93,6 +95,7 @@ class Player: "id": self.id, "name": self.name, "word": self.word, + "wordused": self.wordused, "selection": self.selection, "selected": self.selection >= 0, "ready": self.ready }, @@ -129,6 +132,8 @@ class Game: self.cards.append(skipname) w0 = self.players[0].word w1 = self.players[1].word + w0u = self.players[0].wordused + w1u = self.players[1].wordused if not w0 and not w1: self.word = random.choice(self.words) self.wordSource = "choosen by random" @@ -141,16 +146,16 @@ class Game: elif w0 == w1: self.word = w0 self.wordSource = "suggested by both players" - elif random.randrange(0, 1): + elif w0u < w1u or (w0u == w1u and random.randrange(2)): self.word = w0 self.wordSource = "suggested by player1 (player2 may be lucky next time)" else: self.word = w1 self.wordSource = "suggested by player2 (player1 may be lucky next time)" - self.players[0].beginturn() - self.players[1].beginturn() self.turnResult = 0 self.selected = False + for p in self.players: + p.beginturn() def playerJoin(self): if not self.started and all(p.joined for p in self.players):