From 5b666e042ab23d3c55ca52ae3cc4273441898b91 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 29 Jun 2025 09:18:52 +0300 Subject: [PATCH] Fix: number of guesses --- components/cardcounter.html | 6 +++--- components/room.html | 2 +- handlers/elements.go | 25 ++++++++++++------------- handlers/game.go | 6 +++++- llmapi/main.go | 36 ++++++++++++++++++++++++++++++++++++ models/main.go | 8 +++----- todos.md | 7 +++++-- 7 files changed, 65 insertions(+), 25 deletions(-) diff --git a/components/cardcounter.html b/components/cardcounter.html index 15c1579..b7d7401 100644 --- a/components/cardcounter.html +++ b/components/cardcounter.html @@ -1,7 +1,7 @@ {{define "cardcounter"}} -
-

Blue cards left: {{.BlueCounter}}

-

Red cards left: {{.RedCounter}}

+
+

Blue cards left: {{.BlueCounter}}

+

Red cards left: {{.RedCounter}}


Limit of cards to open: {{.ThisTurnLimit}}

Opened this turn: {{.OpenedThisTurn}}

diff --git a/components/room.html b/components/room.html index 826273b..257ff1f 100644 --- a/components/room.html +++ b/components/room.html @@ -1,5 +1,5 @@ {{define "room"}} -
+

Hello {{.State.Username}};

Room created by {{.Room.CreatorName}};

diff --git a/handlers/elements.go b/handlers/elements.go index 4d07bcc..0494ad9 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -51,7 +51,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { return } color, exists := fi.Room.WCMap[word] - log.Debug("got show-color request", "word", word, "color", color) if !exists { abortWithError(w, "word is not found") return @@ -74,17 +73,20 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { // if opened card is of color of opp team, change turn oppositeColor := fi.Room.GetOppositeTeamColor() fi.Room.OpenedThisTurn++ - if fi.Room.ThisTurnLimit > 0 { - if fi.Room.ThisTurnLimit >= fi.Room.OpenedThisTurn { - // end turn - fi.Room.TeamTurn = oppositeColor - fi.Room.MimeDone = false - fi.Room.OpenedThisTurn = 0 - fi.Room.ThisTurnLimit = 0 - } + log.Debug("got show-color request", "word", word, "color", color, + "limit", fi.Room.ThisTurnLimit, "opened", fi.Room.OpenedThisTurn, + "team-turn", fi.Room.TeamTurn, "opposite-color", oppositeColor) + if fi.Room.OpenedThisTurn >= fi.Room.ThisTurnLimit { + log.Debug("reached limit", "room", fi.Room) + // end turn + fi.Room.TeamTurn = oppositeColor + fi.Room.MimeDone = false + fi.Room.OpenedThisTurn = 0 + fi.Room.ThisTurnLimit = 0 } switch string(color) { case "black": + log.Debug("opened black word", "room", fi.Room) // game over fi.Room.IsRunning = false fi.Room.IsOver = true @@ -99,6 +101,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { fi.Room.ThisTurnLimit = 0 fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) case "white", string(oppositeColor): + log.Debug("opened opposite color word", "room", fi.Room, "opposite-color", oppositeColor) // end turn fi.Room.TeamTurn = oppositeColor fi.Room.MimeDone = false @@ -116,8 +119,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { WordColor: models.WordColorBlue, Action: models.ActionTypeGameOver, } - fi.Room.OpenedThisTurn = 0 - fi.Room.ThisTurnLimit = 0 fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) } if fi.Room.RedCounter == 0 { @@ -131,8 +132,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { WordColor: models.WordColorRed, Action: models.ActionTypeGameOver, } - fi.Room.OpenedThisTurn = 0 - fi.Room.ThisTurnLimit = 0 fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) } } diff --git a/handlers/game.go b/handlers/game.go index cb5fc92..328e188 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -269,7 +269,11 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.MimeDone = true fi.Room.ThisTurnLimit = uint8(guessLimitU64) + 1 - log.Debug("given clue", "clue", clue, "limit", guessLimitU64) + if guessLimitU64 == 0 { + fi.Room.ThisTurnLimit = 9 + } + fi.Room.OpenedThisTurn = 0 + log.Debug("given clue", "clue", clue, "limit", fi.Room.ThisTurnLimit) notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) notifyBotIfNeeded(fi) if err := saveFullInfo(fi); err != nil { diff --git a/llmapi/main.go b/llmapi/main.go index ae4da2e..5e24b37 100644 --- a/llmapi/main.go +++ b/llmapi/main.go @@ -83,16 +83,34 @@ func (b *Bot) checkGuess(word string, room *models.Room) error { room.ActionHistory = append(room.ActionHistory, action) // if opened card is of color of opp team, change turn oppositeColor := room.GetOppositeTeamColor() + if room.OpenedThisTurn >= room.ThisTurnLimit { + // end turn + room.TeamTurn = oppositeColor + room.MimeDone = false + room.OpenedThisTurn = 0 + room.ThisTurnLimit = 0 + } switch string(color) { case "black": // game over room.IsRunning = false room.IsOver = true room.TeamWon = oppositeColor + room.OpenedThisTurn = 0 + room.ThisTurnLimit = 0 + action := models.Action{ + Actor: b.BotName, + ActorColor: string(b.Team), + WordColor: models.WordColorBlack, + Action: models.ActionTypeGameOver, + } + room.ActionHistory = append(room.ActionHistory, action) case "white", string(oppositeColor): // end turn room.TeamTurn = oppositeColor room.MimeDone = false + room.OpenedThisTurn = 0 + room.ThisTurnLimit = 0 } // check if no cards left => game over if room.BlueCounter == 0 { @@ -100,12 +118,30 @@ func (b *Bot) checkGuess(word string, room *models.Room) error { room.IsRunning = false room.IsOver = true room.TeamWon = "blue" + room.OpenedThisTurn = 0 + room.ThisTurnLimit = 0 + action := models.Action{ + Actor: b.BotName, + ActorColor: string(b.Team), + WordColor: models.WordColorBlack, + Action: models.ActionTypeGameOver, + } + room.ActionHistory = append(room.ActionHistory, action) } if room.RedCounter == 0 { // red won room.IsRunning = false room.IsOver = true room.TeamWon = "red" + room.OpenedThisTurn = 0 + room.ThisTurnLimit = 0 + action := models.Action{ + Actor: b.BotName, + ActorColor: string(b.Team), + WordColor: models.WordColorBlack, + Action: models.ActionTypeGameOver, + } + room.ActionHistory = append(room.ActionHistory, action) } if err := saveRoom(room); err != nil { b.log.Error("failed to save room", "room", room) diff --git a/models/main.go b/models/main.go index d34d90b..d133767 100644 --- a/models/main.go +++ b/models/main.go @@ -83,7 +83,6 @@ type Room struct { OpenedThisTurn uint8 // how many cards have been opened this turn WCMap map[string]WordColor BotMap map[string]BotPlayer // key is bot name - Result uint8 // 0 for unknown; 1 is win for red; 2 if for blue; BlueCounter uint8 RedCounter uint8 RedTurn bool // false is blue turn @@ -97,8 +96,7 @@ type Room struct { // Mark CardMark // card is marked // needed for debug - LogJournal []string - LastActionTS time.Time + LogJournal []string } func (r *Room) RemovePlayer(username string) { @@ -240,9 +238,9 @@ func (r *Room) WhichBotToMove() string { func (r *Room) GetOppositeTeamColor() UserTeam { switch r.TeamTurn { - case "red": + case UserTeamRed: return UserTeamBlue - case "blue": + case UserTeamBlue: return UserTeamRed } return UserTeamNone diff --git a/todos.md b/todos.md index 8d3f445..3987743 100644 --- a/todos.md +++ b/todos.md @@ -20,6 +20,7 @@ - clear indication that model (llm) is thinking / answered; - different files for each supported lang; - mark cards (instead of opening them (right click?); +- on end of turn clear all the marks; #### sse points - clue sse update; @@ -40,11 +41,13 @@ - if mime joins another role, he stays as mime (before game start); + - guesser llm makes up words, likely the prompt should be more clear; + - remove bot does not remove for player roles in the room; + -- 0 should mean without limit; +- guesser did not have same number of guesses (move ended after 1 guess); show how much guesses left on the page (red after blue); + +- 0 should mean without limit; + - sse hangs / fails connection which causes to wait for cards to open a few seconds (on local machine) (did not reoccur so far); - invite link gets cutoff; -- guesser did not have same number of guesses (move ended after 1 guess); show how much guesses left on the page (red after blue); - guesser bot no request after game restart; - remove join as mime button if there is a mime already on that team (rewrite teampew templ); - openrouter 429 errors; - there is a clue window for a mime before game started; +- retry call to llm (if 400|429|4xx); +- when llm guesses the word it is not removed from a pool of words making it keep guessing it;