Fix: show color; add bot [WIP]

This commit is contained in:
Grail Finder
2025-05-20 13:10:09 +03:00
parent 24f940f175
commit 2342c56aed
11 changed files with 267 additions and 36 deletions

View File

@ -260,5 +260,8 @@ func loadCards(room *models.Room) {
fmt.Println("failed to load cards", "error", err)
}
room.Cards = cards
room.WCMap = make(map[string]models.WordColor)
for _, card := range room.Cards {
room.WCMap[card.Word] = card.Color
}
}

View File

@ -2,6 +2,7 @@ package handlers
import (
"errors"
"golias/llmapi"
"golias/models"
"html/template"
"net/http"
@ -55,7 +56,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
abortWithError(w, "wait for the clue")
return
}
color, exists := roundWords[word]
color, exists := fi.Room.WCMap[word]
log.Debug("got show-color request", "word", word, "color", color)
if !exists {
abortWithError(w, "word is not found")
@ -63,7 +64,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
}
cardword := models.WordCard{
Word: word,
Color: models.StrToWordColor(color),
Color: color,
Revealed: true,
}
fi.Room.RevealSpecificWord(word)
@ -71,14 +72,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: color,
WordColor: string(color),
Action: "guessed",
Word: word,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
// if opened card is of color of opp team, change turn
oppositeColor := fi.Room.GetOppositeTeamColor()
switch color {
switch string(color) {
case "black":
// game over
fi.Room.IsRunning = false
@ -122,3 +123,21 @@ func HandleActionHistory(w http.ResponseWriter, r *http.Request) {
}
tmpl.ExecuteTemplate(w, "actionhistory", fi.Room.ActionHistory)
}
func HandleAddBot(w http.ResponseWriter, r *http.Request) {
// get team; // get role; make up a name
team := r.URL.Query().Get("team")
role := r.URL.Query().Get("role")
fi, err := getFullInfoByCtx(r.Context())
if err != nil {
abortWithError(w, err.Error())
return
}
bot, err := llmapi.NewBot(role, team, "bot1", fi.Room.ID, cfg)
if err != nil {
abortWithError(w, err.Error())
return
}
bot.StartBot()
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
}

View File

@ -25,8 +25,8 @@ func init() {
}))
memcache = cache.MemCache
cfg = config.LoadConfigOrDefault("")
Notifier = broker.NewBroker()
go Notifier.Listen()
Notifier = broker.Notifier
// go Notifier.Listen()
}
var roundWords = map[string]string{