From 2751b6b9dce8ce87ba5cafb5fdcd08595a93c6eb Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 7 Jul 2025 12:32:23 +0300 Subject: [PATCH] Fix: limit 0 because of too early call of notifybot --- handlers/game.go | 5 +++-- llmapi/main.go | 16 +++++++++++++++- models/main.go | 2 +- todos.md | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/handlers/game.go b/handlers/game.go index 4d03808..05851ea 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -345,12 +345,13 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { fi.Room.OpenedThisTurn = 0 StartTurnTimer(fi.Room.ID, fi.Room.Settings.RoundTime) log.Debug("given clue", "clue", clue, "limit", fi.Room.ThisTurnLimit) - notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) - notifyBotIfNeeded(fi.Room) + // notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) + notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, clue+num) if err := saveFullInfo(r.Context(), fi); err != nil { abortWithError(w, err.Error()) return } + notifyBotIfNeeded(fi.Room) } func HandleRenotifyBot(w http.ResponseWriter, r *http.Request) { diff --git a/llmapi/main.go b/llmapi/main.go index 6cf55aa..6568e1f 100644 --- a/llmapi/main.go +++ b/llmapi/main.go @@ -60,6 +60,12 @@ func (b *Bot) checkGuess(word string, room *models.Room) error { return fmt.Errorf("fn: checkGuess; %s does not exists", word) } room.RevealSpecificWord(word) + if err := repo.WordCardReveal(context.Background(), word, room.ID); err != nil { + b.log.Error("failed to reveal word in db", "word", word, "color", + color, "exists", exists, "limit", room.ThisTurnLimit, + "opened", room.OpenedThisTurn) + return err + } room.UpdateCounter() action := models.Action{ RoomID: room.ID, @@ -156,6 +162,7 @@ func (b *Bot) checkGuess(word string, room *models.Room) error { b.log.Error("failed to create action", "error", err, "action", action) return err } + if err := repo.RoomUpdate(ctx, room); err != nil { // nolint: errcheck tx.Rollback() @@ -288,7 +295,7 @@ func (b *Bot) BotMove() { if err != nil { b.log.Warn("failed to parse could_be", "bot_resp", tempMap, "bot_name", b.BotName) } - entry := fmt.Sprintf("also considered this: %v", couldBe) + entry := fmt.Sprintf("%s guessed: %s; also considered this: %v", b.BotName, guess, couldBe) lj := models.Journal{ Entry: entry, Username: b.BotName, @@ -306,9 +313,16 @@ func (b *Bot) BotMove() { b.log.Error("unexpected role", "role", b.Role, "resp-map", tempMap) return } + // just incase, get the room once more + room, err = repo.RoomGetExtended(context.Background(), b.RoomID) + if err != nil { + b.log.Error("bot loop", "error", err) + return + } if botName := room.WhichBotToMove(); botName != "" { b.log.Debug("notifying bot", "name", botName) SignalChanMap[botName] <- true + b.log.Debug("after sending the signal", "name", botName) } } diff --git a/models/main.go b/models/main.go index bb17982..8d79035 100644 --- a/models/main.go +++ b/models/main.go @@ -294,7 +294,7 @@ func getGuesser(m map[string]BotPlayer, team UserTeam) string { func (r *Room) WhichBotToMove() string { fmt.Println("looking for bot to move", "team-turn:", r.TeamTurn, "mime-done:", r.MimeDone, "bot-map:", r.BotMap, "is_running:", r.IsRunning, - "blueMime:", r.BlueTeam.Mime, "redMime:", r.RedTeam.Mime) + "blueMime:", r.BlueTeam.Mime, "redMime:", r.RedTeam.Mime, "card-limit:", r.ThisTurnLimit, "opened:", r.OpenedThisTurn) if !r.IsRunning { return "" } diff --git a/todos.md b/todos.md index 6374d60..cf5c7c7 100644 --- a/todos.md +++ b/todos.md @@ -86,3 +86,4 @@ - start new game satrted timer for a mime; (feature? in other cases mime has no timer); - timer ended and went to 300; - mime sees the clue input out of turn; +- there is a problem of two timers, they both could switch turn, but it is not easy to stop them from llmapi or handlers.