From 4006112580f1b67750975775faa47ceb3fd3050f Mon Sep 17 00:00:00 2001
From: Ivan Mahonin <bh@icystar.com>
Date: Jul 15 2024 09:39:03 +0000
Subject: keep unused word


---

diff --git a/game.py b/game.py
index ebfd45f..fe9c431 100644
--- a/game.py
+++ b/game.py
@@ -20,7 +20,6 @@ class Player:
         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)
@@ -41,7 +40,7 @@ class Player:
             del players[self.id]
             self.id = str(uuid.uuid4())
             players[self.id] = self
-            self.word = str(word).strip()
+            self.word = " ".join(str(word).split()) # replace all whitespace character sequences to single space
             self.joined = True
             self.game.playerJoin()
 
@@ -93,6 +92,7 @@ class Player:
             "me": {
                 "id": self.id,
                 "name": self.name,
+                "word": self.word,
                 "selection": self.selection,
                 "selected": self.selection >= 0,
                 "ready": self.ready },
@@ -169,6 +169,10 @@ class Game:
                 self.turnResult = 2
             else:
                 self.turnResult = 1
+            if self.turnResult != 3:
+                for p in self.players:
+                    if p.word == self.word:
+                        p.word = ""
 
     def playerReady(self):
         if self.started and self.selected and all(p.ready for p in self.players):
diff --git a/tpl/playerpage.tpl b/tpl/playerpage.tpl
index 0525a88..3dd3704 100644
--- a/tpl/playerpage.tpl
+++ b/tpl/playerpage.tpl
@@ -20,7 +20,7 @@
     <div class="waiting">waiting for the friend</div>
 {else}{if:selected}
     <form id="ready" method="POST" action="{:prefix}/{:me.id}/ready">
-    <input type="text" name="word" autocomplete="off" placeholder="here you may suggest your word for the next turn" size=40 value="" />
+    <input type="text" name="word" autocomplete="off" placeholder="here you may suggest your word for the next turn" size=40 value="{:me.word}" />
     <input type="submit" name="submit" value="next turn" />
     </form>
 {endif}{endif}