Fix: number of guesses

This commit is contained in:
Grail Finder
2025-06-29 09:18:52 +03:00
parent 41124c51fa
commit 5b666e042a
7 changed files with 65 additions and 25 deletions

View File

@ -1,7 +1,7 @@
{{define "cardcounter"}} {{define "cardcounter"}}
<div class="flex justify-center"> <div class="flex justify-center space-x-2">
<p>Blue cards left: {{.BlueCounter}} </p> <p class="text-blue-400">Blue cards left: {{.BlueCounter}} </p>
<p>Red cards left: {{.RedCounter}} </p> <p class="text-red-400">Red cards left: {{.RedCounter}} </p>
<hr> <hr>
<p>Limit of cards to open: {{.ThisTurnLimit}} </p> <p>Limit of cards to open: {{.ThisTurnLimit}} </p>
<p>Opened this turn: {{.OpenedThisTurn}} </p> <p>Opened this turn: {{.OpenedThisTurn}} </p>

View File

@ -1,5 +1,5 @@
{{define "room"}} {{define "room"}}
<div id="interier" hx-get="/" hx-trigger="sse:roomupdate_{{.State.RoomID}}"> <div id="interier" hx-get="/" hx-trigger="sse:roomupdate_{{.State.RoomID}}" class=space-y-2>
<div id="meta"> <div id="meta">
<p>Hello {{.State.Username}};</p> <p>Hello {{.State.Username}};</p>
<p>Room created by {{.Room.CreatorName}};</p> <p>Room created by {{.Room.CreatorName}};</p>

View File

@ -51,7 +51,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
return return
} }
color, exists := fi.Room.WCMap[word] color, exists := fi.Room.WCMap[word]
log.Debug("got show-color request", "word", word, "color", color)
if !exists { if !exists {
abortWithError(w, "word is not found") abortWithError(w, "word is not found")
return return
@ -74,17 +73,20 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
// if opened card is of color of opp team, change turn // if opened card is of color of opp team, change turn
oppositeColor := fi.Room.GetOppositeTeamColor() oppositeColor := fi.Room.GetOppositeTeamColor()
fi.Room.OpenedThisTurn++ fi.Room.OpenedThisTurn++
if fi.Room.ThisTurnLimit > 0 { log.Debug("got show-color request", "word", word, "color", color,
if fi.Room.ThisTurnLimit >= fi.Room.OpenedThisTurn { "limit", fi.Room.ThisTurnLimit, "opened", fi.Room.OpenedThisTurn,
// end turn "team-turn", fi.Room.TeamTurn, "opposite-color", oppositeColor)
fi.Room.TeamTurn = oppositeColor if fi.Room.OpenedThisTurn >= fi.Room.ThisTurnLimit {
fi.Room.MimeDone = false log.Debug("reached limit", "room", fi.Room)
fi.Room.OpenedThisTurn = 0 // end turn
fi.Room.ThisTurnLimit = 0 fi.Room.TeamTurn = oppositeColor
} fi.Room.MimeDone = false
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
} }
switch string(color) { switch string(color) {
case "black": case "black":
log.Debug("opened black word", "room", fi.Room)
// game over // game over
fi.Room.IsRunning = false fi.Room.IsRunning = false
fi.Room.IsOver = true fi.Room.IsOver = true
@ -99,6 +101,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.ThisTurnLimit = 0 fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
case "white", string(oppositeColor): case "white", string(oppositeColor):
log.Debug("opened opposite color word", "room", fi.Room, "opposite-color", oppositeColor)
// end turn // end turn
fi.Room.TeamTurn = oppositeColor fi.Room.TeamTurn = oppositeColor
fi.Room.MimeDone = false fi.Room.MimeDone = false
@ -116,8 +119,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
WordColor: models.WordColorBlue, WordColor: models.WordColorBlue,
Action: models.ActionTypeGameOver, Action: models.ActionTypeGameOver,
} }
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
} }
if fi.Room.RedCounter == 0 { if fi.Room.RedCounter == 0 {
@ -131,8 +132,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
WordColor: models.WordColorRed, WordColor: models.WordColorRed,
Action: models.ActionTypeGameOver, Action: models.ActionTypeGameOver,
} }
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
} }
} }

View File

@ -269,7 +269,11 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) {
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
fi.Room.MimeDone = true fi.Room.MimeDone = true
fi.Room.ThisTurnLimit = uint8(guessLimitU64) + 1 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) notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num)
notifyBotIfNeeded(fi) notifyBotIfNeeded(fi)
if err := saveFullInfo(fi); err != nil { if err := saveFullInfo(fi); err != nil {

View File

@ -83,16 +83,34 @@ func (b *Bot) checkGuess(word string, room *models.Room) error {
room.ActionHistory = append(room.ActionHistory, action) room.ActionHistory = append(room.ActionHistory, action)
// if opened card is of color of opp team, change turn // if opened card is of color of opp team, change turn
oppositeColor := room.GetOppositeTeamColor() 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) { switch string(color) {
case "black": case "black":
// game over // game over
room.IsRunning = false room.IsRunning = false
room.IsOver = true room.IsOver = true
room.TeamWon = oppositeColor 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): case "white", string(oppositeColor):
// end turn // end turn
room.TeamTurn = oppositeColor room.TeamTurn = oppositeColor
room.MimeDone = false room.MimeDone = false
room.OpenedThisTurn = 0
room.ThisTurnLimit = 0
} }
// check if no cards left => game over // check if no cards left => game over
if room.BlueCounter == 0 { if room.BlueCounter == 0 {
@ -100,12 +118,30 @@ func (b *Bot) checkGuess(word string, room *models.Room) error {
room.IsRunning = false room.IsRunning = false
room.IsOver = true room.IsOver = true
room.TeamWon = "blue" 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 { if room.RedCounter == 0 {
// red won // red won
room.IsRunning = false room.IsRunning = false
room.IsOver = true room.IsOver = true
room.TeamWon = "red" 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 { if err := saveRoom(room); err != nil {
b.log.Error("failed to save room", "room", room) b.log.Error("failed to save room", "room", room)

View File

@ -83,7 +83,6 @@ type Room struct {
OpenedThisTurn uint8 // how many cards have been opened this turn OpenedThisTurn uint8 // how many cards have been opened this turn
WCMap map[string]WordColor WCMap map[string]WordColor
BotMap map[string]BotPlayer // key is bot name BotMap map[string]BotPlayer // key is bot name
Result uint8 // 0 for unknown; 1 is win for red; 2 if for blue;
BlueCounter uint8 BlueCounter uint8
RedCounter uint8 RedCounter uint8
RedTurn bool // false is blue turn RedTurn bool // false is blue turn
@ -97,8 +96,7 @@ type Room struct {
// //
Mark CardMark // card is marked Mark CardMark // card is marked
// needed for debug // needed for debug
LogJournal []string LogJournal []string
LastActionTS time.Time
} }
func (r *Room) RemovePlayer(username string) { func (r *Room) RemovePlayer(username string) {
@ -240,9 +238,9 @@ func (r *Room) WhichBotToMove() string {
func (r *Room) GetOppositeTeamColor() UserTeam { func (r *Room) GetOppositeTeamColor() UserTeam {
switch r.TeamTurn { switch r.TeamTurn {
case "red": case UserTeamRed:
return UserTeamBlue return UserTeamBlue
case "blue": case UserTeamBlue:
return UserTeamRed return UserTeamRed
} }
return UserTeamNone return UserTeamNone

View File

@ -20,6 +20,7 @@
- clear indication that model (llm) is thinking / answered; - clear indication that model (llm) is thinking / answered;
- different files for each supported lang; - different files for each supported lang;
- mark cards (instead of opening them (right click?); - mark cards (instead of opening them (right click?);
- on end of turn clear all the marks;
#### sse points #### sse points
- clue sse update; - clue sse update;
@ -40,11 +41,13 @@
- if mime joins another role, he stays as mime (before game start); + - if mime joins another role, he stays as mime (before game start); +
- guesser llm makes up words, likely the prompt should be more clear; + - guesser llm makes up words, likely the prompt should be more clear; +
- remove bot does not remove for player roles in the room; + - 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); - 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; - 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; - guesser bot no request after game restart;
- remove join as mime button if there is a mime already on that team (rewrite teampew templ); - remove join as mime button if there is a mime already on that team (rewrite teampew templ);
- openrouter 429 errors; - openrouter 429 errors;
- there is a clue window for a mime before game started; - 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;