Enha: simplier guesser prompt; player team-role recovery
This commit is contained in:
		| @@ -58,6 +58,9 @@ | |||||||
|     {{end}} |     {{end}} | ||||||
|     </ul> |     </ul> | ||||||
|   </div> |   </div> | ||||||
|  |   <div sse-swap="journal_{{.Room.ID}}"> | ||||||
|  |     sse div | ||||||
|  |   <div> | ||||||
|   <div id="cardtable"> |   <div id="cardtable"> | ||||||
|     {{template "cardtable" .Room}} |     {{template "cardtable" .Room}} | ||||||
|   </div> |   </div> | ||||||
|   | |||||||
| @@ -275,6 +275,24 @@ func listBots() map[string]map[string]string { | |||||||
| 	return resp | 	return resp | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // get players | ||||||
|  | func listPlayers() map[string]map[string]string { | ||||||
|  | 	cacheMap := memcache.GetAll() | ||||||
|  | 	resp := make(map[string]map[string]string) | ||||||
|  | 	// no way to know if room is public until unmarshal -_-; | ||||||
|  | 	for key, value := range cacheMap { | ||||||
|  | 		if strings.HasPrefix(key, models.CacheStatePrefix) { | ||||||
|  | 			playerMap := make(map[string]string) | ||||||
|  | 			if err := json.Unmarshal(value, &playerMap); err != nil { | ||||||
|  | 				log.Warn("failed to unmarshal player", "error", err) | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  | 			resp[playerMap["Username"]] = playerMap | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return resp | ||||||
|  | } | ||||||
|  |  | ||||||
| func notify(event, msg string) { | func notify(event, msg string) { | ||||||
| 	Notifier.Notifier <- broker.NotificationEvent{ | 	Notifier.Notifier <- broker.NotificationEvent{ | ||||||
| 		EventName: event, | 		EventName: event, | ||||||
| @@ -317,3 +335,34 @@ func recoverBot(bm map[string]string) error { | |||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func recoverPlayers() { | ||||||
|  | 	players := listPlayers() | ||||||
|  | 	for playerName, playerMap := range players { | ||||||
|  | 		if err := recoverPlayer(playerMap); err != nil { | ||||||
|  | 			log.Warn("failed to recover player", "playerName", playerName, "error", err) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func recoverPlayer(pm map[string]string) error { | ||||||
|  | 	// check if room still exists | ||||||
|  | 	room, err := getRoomByID(pm["RoomID"]) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return fmt.Errorf("no such room: %s; err: %w", pm["RoomID"], err) | ||||||
|  | 	} | ||||||
|  | 	log.Debug("recovering player", "player", pm) | ||||||
|  | 	role, team, ok := room.GetPlayerByName(pm["Username"]) | ||||||
|  | 	if !ok { | ||||||
|  | 		return fmt.Errorf("failed to find player %s in the room %v", pm["Username"], room) | ||||||
|  | 	} | ||||||
|  | 	// pm["Role"] = string(role) | ||||||
|  | 	// pm["Team"] = string(team) | ||||||
|  | 	us := &models.UserState{ | ||||||
|  | 		Username: pm["Username"], | ||||||
|  | 		RoomID:   pm["RoomID"], | ||||||
|  | 		Team:     team, | ||||||
|  | 		Role:     role, | ||||||
|  | 	} | ||||||
|  | 	return saveState(pm["Username"], us) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -96,7 +96,7 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { | |||||||
| 			abortWithError(w, err.Error()) | 			abortWithError(w, err.Error()) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 		room.PlayerList = append(room.PlayerList, fi.State.Username) | 		// room.PlayerList = append(room.PlayerList, fi.State.Username) | ||||||
| 		fi.State.RoomID = room.ID | 		fi.State.RoomID = room.ID | ||||||
| 		fi.Room = room | 		fi.Room = room | ||||||
| 		fi.List = nil | 		fi.List = nil | ||||||
|   | |||||||
| @@ -204,7 +204,7 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | |||||||
| 		// abortWithError(w, err.Error()) | 		// abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	room.PlayerList = append(room.PlayerList, fi.State.Username) | 	// room.PlayerList = append(room.PlayerList, fi.State.Username) | ||||||
| 	fi.State.RoomID = room.ID | 	fi.State.RoomID = room.ID | ||||||
| 	fi.Room = room | 	fi.Room = room | ||||||
| 	fi.List = nil | 	fi.List = nil | ||||||
|   | |||||||
| @@ -31,6 +31,8 @@ func init() { | |||||||
| 	// bot loader | 	// bot loader | ||||||
| 	// check the rooms if it has bot_{digits} in them, create bots if have | 	// check the rooms if it has bot_{digits} in them, create bots if have | ||||||
| 	recoverBots() | 	recoverBots() | ||||||
|  | 	// if player has a roomID, but no team and role, try to recover | ||||||
|  | 	recoverPlayers() | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandlePing(w http.ResponseWriter, r *http.Request) { | func HandlePing(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -85,7 +87,7 @@ func HandleExit(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if len(exitedRoom.PlayerList) == 0 || creatorLeft { | 	if creatorLeft { | ||||||
| 		removeRoom(exitedRoom.ID) | 		removeRoom(exitedRoom.ID) | ||||||
| 		// TODO: notify users if creator left | 		// TODO: notify users if creator left | ||||||
| 		// and throw them away | 		// and throw them away | ||||||
|   | |||||||
							
								
								
									
										153
									
								
								llmapi/main.go
									
									
									
									
									
								
							
							
						
						
									
										153
									
								
								llmapi/main.go
									
									
									
									
									
								
							| @@ -24,7 +24,7 @@ var ( | |||||||
| 	MimePrompt = `we are playing alias;\nyou are a mime (player who gives a clue of one noun word and number of cards you expect them to open) of the %s team (people who would guess by your clue want open the %s cards);\nplease return your clue, number of cards to open and what words you mean them to find using that clue in json like:\n{\n\"clue\": \"one-word-noun\",\n\"number\": \"number-from-0-to-9\",\n\"words_I_mean_my_team_to_open\": [\"this\", \"that\", ...]\n}\nthe team who openes all their cards first wins.\nplease return json only.\nunopen Blue cards left: %d;\nunopen Red cards left: %d;\nhere is the game info in json:\n%s` | 	MimePrompt = `we are playing alias;\nyou are a mime (player who gives a clue of one noun word and number of cards you expect them to open) of the %s team (people who would guess by your clue want open the %s cards);\nplease return your clue, number of cards to open and what words you mean them to find using that clue in json like:\n{\n\"clue\": \"one-word-noun\",\n\"number\": \"number-from-0-to-9\",\n\"words_I_mean_my_team_to_open\": [\"this\", \"that\", ...]\n}\nthe team who openes all their cards first wins.\nplease return json only.\nunopen Blue cards left: %d;\nunopen Red cards left: %d;\nhere is the game info in json:\n%s` | ||||||
| 	// TODO: simplify; bot gets confused; so show it only unrevealed cards and last clue (maybe older clues as well); | 	// TODO: simplify; bot gets confused; so show it only unrevealed cards and last clue (maybe older clues as well); | ||||||
| 	GuesserPrompt       = `we are playing alias;\nyou are to guess words of the %s team (you want open %s cards) by given clue and a number of meant guesses;\nplease return your guesses and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guesses\": [\"word1\", \"word2\", ...],\n\"could_be\": [\"this\", \"that\", ...]\n}\nthe team who openes all their cards first wins.\nplease return json only.\nunopen Blue cards left: %d;\nunopen Red cards left: %d;\nhere is the cards (and other info), you need to choose revealed==false words:\n%s` | 	GuesserPrompt       = `we are playing alias;\nyou are to guess words of the %s team (you want open %s cards) by given clue and a number of meant guesses;\nplease return your guesses and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guesses\": [\"word1\", \"word2\", ...],\n\"could_be\": [\"this\", \"that\", ...]\n}\nthe team who openes all their cards first wins.\nplease return json only.\nunopen Blue cards left: %d;\nunopen Red cards left: %d;\nhere is the cards (and other info), you need to choose revealed==false words:\n%s` | ||||||
| 	GuesserSimplePrompt = `we are playing game of alias;\n you were given a clue: \"%s\";\nnumber of words you can open with that clue is:%s;\nplease return your guesses and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guesses\": [\"word1\", \"word2\", ...],\n\"could_be\": [\"this\", \"that\", ...]\n}\nhere is the words that left:\n%s` | 	GuesserSimplePrompt = `we are playing game of alias;\n you were given a clue: \"%s\";\nplease return your guess and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guess\": "most_relevant_word_to_the_clue",\n\"could_be\": [\"this\", \"that\", ...]\n}\nhere is the words that left:\n%s` | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type DSResp struct { | type DSResp struct { | ||||||
| @@ -103,11 +103,79 @@ func convertToSliceOfStrings(value any) ([]string, error) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (b *Bot) checkGuesses(tempMap map[string]any, room *models.Room) error { | ||||||
|  | 	guesses, err := convertToSliceOfStrings(tempMap["guesses"]) | ||||||
|  | 	if err != nil { | ||||||
|  | 		b.log.Warn("failed to parse bot given guesses", "mimeResp", tempMap, "bot_name", b.BotName) | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	for _, word := range guesses { | ||||||
|  | 		if err := b.checkGuess(word, room); err != nil { | ||||||
|  | 			// log error | ||||||
|  | 			b.log.Warn("failed to check guess", "mimeResp", tempMap, "bot_name", b.BotName, "guess", word) | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (b *Bot) checkGuess(word string, room *models.Room) error { | ||||||
|  | 	color, exists := room.WCMap[word] | ||||||
|  | 	b.log.Debug("bot trying to open card", "word", word, "color", | ||||||
|  | 		color, "exists", exists) | ||||||
|  | 	if !exists { | ||||||
|  | 		return fmt.Errorf("fn: checkGuess; %s does not exists", word) | ||||||
|  | 	} | ||||||
|  | 	room.RevealSpecificWord(word) | ||||||
|  | 	room.UpdateCounter() | ||||||
|  | 	action := models.Action{ | ||||||
|  | 		Actor:      b.BotName, | ||||||
|  | 		ActorColor: b.Team, | ||||||
|  | 		WordColor:  string(color), | ||||||
|  | 		Action:     "guessed", | ||||||
|  | 		Word:       word, | ||||||
|  | 	} | ||||||
|  | 	room.ActionHistory = append(room.ActionHistory, action) | ||||||
|  | 	// if opened card is of color of opp team, change turn | ||||||
|  | 	oppositeColor := room.GetOppositeTeamColor() | ||||||
|  | 	switch string(color) { | ||||||
|  | 	case "black": | ||||||
|  | 		// game over | ||||||
|  | 		room.IsRunning = false | ||||||
|  | 		room.IsOver = true | ||||||
|  | 		room.TeamWon = oppositeColor | ||||||
|  | 	case "white", string(oppositeColor): | ||||||
|  | 		// end turn | ||||||
|  | 		room.TeamTurn = oppositeColor | ||||||
|  | 		room.MimeDone = false | ||||||
|  | 	} | ||||||
|  | 	// check if no cards left => game over | ||||||
|  | 	if room.BlueCounter == 0 { | ||||||
|  | 		// blue won | ||||||
|  | 		room.IsRunning = false | ||||||
|  | 		room.IsOver = true | ||||||
|  | 		room.TeamWon = "blue" | ||||||
|  | 	} | ||||||
|  | 	if room.RedCounter == 0 { | ||||||
|  | 		// red won | ||||||
|  | 		room.IsRunning = false | ||||||
|  | 		room.IsOver = true | ||||||
|  | 		room.TeamWon = "red" | ||||||
|  | 	} | ||||||
|  | 	if err := saveRoom(room); err != nil { | ||||||
|  | 		b.log.Error("failed to save room", "room", room) | ||||||
|  | 		err = fmt.Errorf("fn: checkGuess, failed to save room; err: %w", err) | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
| // StartBot | // StartBot | ||||||
| func (b *Bot) StartBot() { | func (b *Bot) StartBot() { | ||||||
| 	for { | 	for { | ||||||
| 		select { | 		select { | ||||||
| 		case <-SignalChanMap[b.BotName]: | 		case <-SignalChanMap[b.BotName]: | ||||||
|  | 			botJournalName := models.NotifyJournalPrefix + b.RoomID | ||||||
| 			b.log.Debug("got signal", "bot-team", b.Team, "bot-role", b.Role) | 			b.log.Debug("got signal", "bot-team", b.Team, "bot-role", b.Role) | ||||||
| 			// get room cards and actions | 			// get room cards and actions | ||||||
| 			room, err := getRoomByID(b.RoomID) | 			room, err := getRoomByID(b.RoomID) | ||||||
| @@ -118,14 +186,26 @@ func (b *Bot) StartBot() { | |||||||
| 			// form prompt | 			// form prompt | ||||||
| 			prompt := b.BuildPrompt(room) | 			prompt := b.BuildPrompt(room) | ||||||
| 			b.log.Debug("got prompt", "prompt", prompt) | 			b.log.Debug("got prompt", "prompt", prompt) | ||||||
|  | 			broker.Notifier.Notifier <- broker.NotificationEvent{ | ||||||
|  | 				EventName: botJournalName, | ||||||
|  | 				Payload:   prompt, | ||||||
|  | 			} | ||||||
| 			// call llm | 			// call llm | ||||||
| 			llmResp, err := b.CallLLM(prompt) | 			llmResp, err := b.CallLLM(prompt) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
|  | 				broker.Notifier.Notifier <- broker.NotificationEvent{ | ||||||
|  | 					EventName: botJournalName, | ||||||
|  | 					Payload:   "failed to get bot resp", | ||||||
|  | 				} | ||||||
| 				b.log.Error("bot loop", "error", err) | 				b.log.Error("bot loop", "error", err) | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			tempMap, err := b.LLMParser.ParseBytes(llmResp) | 			tempMap, err := b.LLMParser.ParseBytes(llmResp) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
|  | 				broker.Notifier.Notifier <- broker.NotificationEvent{ | ||||||
|  | 					EventName: botJournalName, | ||||||
|  | 					Payload:   "failed to parse bot resp", | ||||||
|  | 				} | ||||||
| 				b.log.Error("bot loop", "error", err, "resp", string(llmResp)) | 				b.log.Error("bot loop", "error", err, "resp", string(llmResp)) | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| @@ -154,60 +234,24 @@ func (b *Bot) StartBot() { | |||||||
| 				} | 				} | ||||||
| 				room.ThisTurnLimit = uint8(guessLimitU64) | 				room.ThisTurnLimit = uint8(guessLimitU64) | ||||||
| 			case models.UserRoleGuesser: | 			case models.UserRoleGuesser: | ||||||
| 				guesses, err := convertToSliceOfStrings(tempMap["guesses"]) | 				// // deprecated | ||||||
| 				if err != nil { | 				// if err := b.checkGuesses(tempMap, room); err != nil { | ||||||
| 					b.log.Warn("failed to parse bot given guesses", "mimeResp", tempMap, "bot_name", b.BotName) | 				// 	b.log.Warn("failed to check guess", "mimeResp", tempMap, "bot_name", b.BotName) | ||||||
| 					continue | 				// 	continue | ||||||
|  | 				// } | ||||||
|  | 				guess, ok := tempMap["guess"].(string) | ||||||
|  | 				if !ok || guess == "" { | ||||||
|  | 					b.log.Warn("failed to parse guess", "mimeResp", tempMap, "bot_name", b.BotName) | ||||||
| 				} | 				} | ||||||
| 				for _, word := range guesses { | 				if err := b.checkGuess(guess, room); err != nil { | ||||||
| 					color, exists := room.WCMap[word] | 					b.log.Warn("failed to check guess", "mimeResp", tempMap, "bot_name", b.BotName, "guess", guess) | ||||||
| 					b.log.Debug("bot trying to open card", "word", word, "color", |  | ||||||
| 						color, "exists", exists) |  | ||||||
| 					if !exists { |  | ||||||
| 						continue |  | ||||||
| 					} |  | ||||||
| 					room.RevealSpecificWord(word) |  | ||||||
| 					room.UpdateCounter() |  | ||||||
| 					action := models.Action{ |  | ||||||
| 						Actor:      b.BotName, |  | ||||||
| 						ActorColor: b.Team, |  | ||||||
| 						WordColor:  string(color), |  | ||||||
| 						Action:     "guessed", |  | ||||||
| 						Word:       word, |  | ||||||
| 					} |  | ||||||
| 					room.ActionHistory = append(room.ActionHistory, action) |  | ||||||
| 					// if opened card is of color of opp team, change turn |  | ||||||
| 					oppositeColor := room.GetOppositeTeamColor() |  | ||||||
| 					switch string(color) { |  | ||||||
| 					case "black": |  | ||||||
| 						// game over |  | ||||||
| 						room.IsRunning = false |  | ||||||
| 						room.IsOver = true |  | ||||||
| 						room.TeamWon = oppositeColor |  | ||||||
| 					case "white", string(oppositeColor): |  | ||||||
| 						// end turn |  | ||||||
| 						room.TeamTurn = oppositeColor |  | ||||||
| 						room.MimeDone = false |  | ||||||
| 					} |  | ||||||
| 					// check if no cards left => game over |  | ||||||
| 					if room.BlueCounter == 0 { |  | ||||||
| 						// blue won |  | ||||||
| 						room.IsRunning = false |  | ||||||
| 						room.IsOver = true |  | ||||||
| 						room.TeamWon = "blue" |  | ||||||
| 					} |  | ||||||
| 					if room.RedCounter == 0 { |  | ||||||
| 						// red won |  | ||||||
| 						room.IsRunning = false |  | ||||||
| 						room.IsOver = true |  | ||||||
| 						room.TeamWon = "red" |  | ||||||
| 					} |  | ||||||
| 					if err := saveRoom(room); err != nil { |  | ||||||
| 						b.log.Error("failed to save room", "room", room) |  | ||||||
| 						continue |  | ||||||
| 					} |  | ||||||
| 				} | 				} | ||||||
| 				b.log.Info("mime resp log", "guesserResp", tempMap) | 				b.log.Info("mime resp log", "guesserResp", tempMap) | ||||||
|  | 				couldBe, err := convertToSliceOfStrings(tempMap["could_be"]) | ||||||
|  | 				if err != nil { | ||||||
|  | 					b.log.Warn("failed to parse could_be", "bot_resp", tempMap, "bot_name", b.BotName) | ||||||
|  | 				} | ||||||
|  | 				room.LogJournal = append(room.LogJournal, fmt.Sprintf("%s also considered this: %v", b.BotName, couldBe)) | ||||||
| 				eventName = models.NotifyRoomUpdatePrefix + room.ID | 				eventName = models.NotifyRoomUpdatePrefix + room.ID | ||||||
| 				eventPayload = "" | 				eventPayload = "" | ||||||
| 			default: | 			default: | ||||||
| @@ -262,7 +306,7 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool) | |||||||
| 	if role == "mime" && room.IsRunning && !recovery { | 	if role == "mime" && room.IsRunning && !recovery { | ||||||
| 		return nil, errors.New("cannot join after game started") | 		return nil, errors.New("cannot join after game started") | ||||||
| 	} | 	} | ||||||
| 	room.PlayerList = append(room.PlayerList, name) | 	// room.PlayerList = append(room.PlayerList, name) | ||||||
| 	bp := models.BotPlayer{ | 	bp := models.BotPlayer{ | ||||||
| 		Role: models.StrToUserRole(role), | 		Role: models.StrToUserRole(role), | ||||||
| 		Team: models.StrToUserTeam(team), | 		Team: models.StrToUserTeam(team), | ||||||
| @@ -343,6 +387,9 @@ func (b *Bot) BuildSimpleGuesserPrompt(room *models.Room) string { | |||||||
| 	clue := room.ActionHistory[len(room.ActionHistory)-1].Word | 	clue := room.ActionHistory[len(room.ActionHistory)-1].Word | ||||||
| 	number := room.ActionHistory[len(room.ActionHistory)-1].Number | 	number := room.ActionHistory[len(room.ActionHistory)-1].Number | ||||||
| 	words := make([]string, len(room.Cards)) | 	words := make([]string, len(room.Cards)) | ||||||
|  | 	for i, card := range room.Cards { | ||||||
|  | 		words[i] = card.Word | ||||||
|  | 	} | ||||||
| 	return fmt.Sprintf(GuesserSimplePrompt, clue, number, words) | 	return fmt.Sprintf(GuesserSimplePrompt, clue, number, words) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,4 +13,5 @@ var ( | |||||||
| 	NotifyRoomListUpdate   = "roomlistupdate" | 	NotifyRoomListUpdate   = "roomlistupdate" | ||||||
| 	NotifyRoomUpdatePrefix = "roomupdate_" | 	NotifyRoomUpdatePrefix = "roomupdate_" | ||||||
| 	NotifyBacklogPrefix    = "backlog_" | 	NotifyBacklogPrefix    = "backlog_" | ||||||
|  | 	NotifyJournalPrefix    = "journal_" | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -58,10 +58,10 @@ type Room struct { | |||||||
| 	ID        string    `json:"id" db:"id"` | 	ID        string    `json:"id" db:"id"` | ||||||
| 	CreatedAt time.Time `json:"created_at" db:"created_at"` | 	CreatedAt time.Time `json:"created_at" db:"created_at"` | ||||||
| 	// RoomName     string    `json:"room_name"` | 	// RoomName     string    `json:"room_name"` | ||||||
| 	RoomPass       string `json:"room_pass"` | 	RoomPass    string `json:"room_pass"` | ||||||
| 	RoomLink       string | 	RoomLink    string | ||||||
| 	CreatorName    string   `json:"creator_name"` | 	CreatorName string `json:"creator_name"` | ||||||
| 	PlayerList     []string `json:"player_list"` | 	// PlayerList     []string `json:"player_list"` | ||||||
| 	ActionHistory  []Action | 	ActionHistory  []Action | ||||||
| 	TeamTurn       UserTeam | 	TeamTurn       UserTeam | ||||||
| 	RedTeam        Team | 	RedTeam        Team | ||||||
| @@ -88,6 +88,26 @@ type Room struct { | |||||||
| 	LogJournal []string | 	LogJournal []string | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (r *Room) GetPlayerByName(name string) (role UserRole, team UserTeam, found bool) { | ||||||
|  | 	if r.RedTeam.Mime == name { | ||||||
|  | 		return "mime", "red", true | ||||||
|  | 	} | ||||||
|  | 	if r.BlueTeam.Mime == name { | ||||||
|  | 		return "mime", "blue", true | ||||||
|  | 	} | ||||||
|  | 	for _, guesser := range r.RedTeam.Guessers { | ||||||
|  | 		if guesser == name { | ||||||
|  | 			return "guesser", "red", true | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	for _, guesser := range r.BlueTeam.Guessers { | ||||||
|  | 		if guesser == name { | ||||||
|  | 			return "guesser", "blue", true | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return "", "", false | ||||||
|  | } | ||||||
|  |  | ||||||
| func (r *Room) CanStart() error { | func (r *Room) CanStart() error { | ||||||
| 	if r.IsRunning { | 	if r.IsRunning { | ||||||
| 		return errors.New("cannot start; game is already running") | 		return errors.New("cannot start; game is already running") | ||||||
| @@ -230,10 +250,10 @@ func (rr *RoomReq) CreateRoom(creator string) *Room { | |||||||
| 	roomID := xid.New().String() | 	roomID := xid.New().String() | ||||||
| 	return &Room{ | 	return &Room{ | ||||||
| 		// RoomName: , | 		// RoomName: , | ||||||
| 		RoomPass:    rr.RoomPass, | 		RoomPass:  rr.RoomPass, | ||||||
| 		ID:          roomID, | 		ID:        roomID, | ||||||
| 		CreatedAt:   time.Now(), | 		CreatedAt: time.Now(), | ||||||
| 		PlayerList:  []string{creator}, | 		// PlayerList:  []string{creator}, | ||||||
| 		CreatorName: creator, | 		CreatorName: creator, | ||||||
| 		BotMap:      make(map[string]BotPlayer), | 		BotMap:      make(map[string]BotPlayer), | ||||||
| 	} | 	} | ||||||
| @@ -249,7 +269,7 @@ type FullInfo struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (f *FullInfo) ExitRoom() *Room { | func (f *FullInfo) ExitRoom() *Room { | ||||||
| 	f.Room.PlayerList = utils.RemoveFromSlice(f.State.Username, f.Room.PlayerList) | 	// f.Room.PlayerList = utils.RemoveFromSlice(f.State.Username, f.Room.PlayerList) | ||||||
| 	f.Room.RedTeam.Guessers = utils.RemoveFromSlice(f.State.Username, f.Room.RedTeam.Guessers) | 	f.Room.RedTeam.Guessers = utils.RemoveFromSlice(f.State.Username, f.Room.RedTeam.Guessers) | ||||||
| 	f.Room.BlueTeam.Guessers = utils.RemoveFromSlice(f.State.Username, f.Room.BlueTeam.Guessers) | 	f.Room.BlueTeam.Guessers = utils.RemoveFromSlice(f.State.Username, f.Room.BlueTeam.Guessers) | ||||||
| 	if f.Room.RedTeam.Mime == f.State.Username { | 	if f.Room.RedTeam.Mime == f.State.Username { | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								todos.md
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								todos.md
									
									
									
									
									
								
							| @@ -16,6 +16,7 @@ | |||||||
| - gameover to backlog; | - gameover to backlog; | ||||||
| - ended turn action to backlog; | - ended turn action to backlog; | ||||||
| - clear indication that model (llm) is thinking / answered; | - clear indication that model (llm) is thinking / answered; | ||||||
|  | - instead of guessing all words at ones, ask only for 1 word to be open. | ||||||
|  |  | ||||||
| #### sse points | #### sse points | ||||||
| - clue sse update; | - clue sse update; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder