Feat: guess limit
This commit is contained in:
		| @@ -112,18 +112,19 @@ func loadState(username string) (*models.UserState, error) { | ||||
| 	return resp, nil | ||||
| } | ||||
|  | ||||
| func loadBot(botName, roomID string) (*llmapi.Bot, error) { | ||||
| 	key := "botkey_" + roomID + botName | ||||
| 	data, err := memcache.Get(key) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	resp := &llmapi.Bot{} | ||||
| 	if err := json.Unmarshal(data, &resp); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return resp, nil | ||||
| } | ||||
| // not used | ||||
| // func loadBot(botName, roomID string) (*llmapi.Bot, error) { | ||||
| // 	key := "botkey_" + roomID + botName | ||||
| // 	data, err := memcache.Get(key) | ||||
| // 	if err != nil { | ||||
| // 		return nil, err | ||||
| // 	} | ||||
| // 	resp := &llmapi.Bot{} | ||||
| // 	if err := json.Unmarshal(data, &resp); err != nil { | ||||
| // 		return nil, err | ||||
| // 	} | ||||
| // 	return resp, nil | ||||
| // } | ||||
|  | ||||
| func getAllNames() []string { | ||||
| 	names := []string{} | ||||
|   | ||||
| @@ -84,6 +84,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 	fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) | ||||
| 	// if opened card is of color of opp team, change turn | ||||
| 	oppositeColor := fi.Room.GetOppositeTeamColor() | ||||
| 	fi.Room.OpenedThisTurn++ | ||||
| 	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 | ||||
| 	} | ||||
| 	switch string(color) { | ||||
| 	case "black": | ||||
| 		// game over | ||||
| @@ -96,38 +104,46 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 			WordColor:  "black", | ||||
| 			Action:     "game over", | ||||
| 		} | ||||
| 		fi.Room.OpenedThisTurn = 0 | ||||
| 		fi.Room.ThisTurnLimit = 0 | ||||
| 		fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) | ||||
| 	case "white", string(oppositeColor): | ||||
| 		// end turn | ||||
| 		fi.Room.TeamTurn = oppositeColor | ||||
| 		fi.Room.MimeDone = false | ||||
| 	} | ||||
| 	// check if no cards left => game over | ||||
| 	if fi.Room.BlueCounter == 0 { | ||||
| 		// blue won | ||||
| 		fi.Room.IsRunning = false | ||||
| 		fi.Room.IsOver = true | ||||
| 		fi.Room.TeamWon = "blue" | ||||
| 		action := models.Action{ | ||||
| 			Actor:      fi.State.Username, | ||||
| 			ActorColor: string(fi.State.Team), | ||||
| 			WordColor:  "blue", | ||||
| 			Action:     "game over", | ||||
| 		fi.Room.OpenedThisTurn = 0 | ||||
| 		fi.Room.ThisTurnLimit = 0 | ||||
| 		// check if no cards left => game over | ||||
| 		if fi.Room.BlueCounter == 0 { | ||||
| 			// blue won | ||||
| 			fi.Room.IsRunning = false | ||||
| 			fi.Room.IsOver = true | ||||
| 			fi.Room.TeamWon = "blue" | ||||
| 			action := models.Action{ | ||||
| 				Actor:      fi.State.Username, | ||||
| 				ActorColor: string(fi.State.Team), | ||||
| 				WordColor:  "blue", | ||||
| 				Action:     "game over", | ||||
| 			} | ||||
| 			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 { | ||||
| 		// red won | ||||
| 		fi.Room.IsRunning = false | ||||
| 		fi.Room.IsOver = true | ||||
| 		fi.Room.TeamWon = "red" | ||||
| 		action := models.Action{ | ||||
| 			Actor:      fi.State.Username, | ||||
| 			ActorColor: string(fi.State.Team), | ||||
| 			WordColor:  "red", | ||||
| 			Action:     "game over", | ||||
| 		if fi.Room.RedCounter == 0 { | ||||
| 			// red won | ||||
| 			fi.Room.IsRunning = false | ||||
| 			fi.Room.IsOver = true | ||||
| 			fi.Room.TeamWon = "red" | ||||
| 			action := models.Action{ | ||||
| 				Actor:      fi.State.Username, | ||||
| 				ActorColor: string(fi.State.Team), | ||||
| 				WordColor:  "red", | ||||
| 				Action:     "game over", | ||||
| 			} | ||||
| 			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 err := saveFullInfo(fi); err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
|   | ||||
| @@ -7,6 +7,7 @@ import ( | ||||
| 	"gralias/models" | ||||
| 	"html/template" | ||||
| 	"net/http" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| func HandleCreateRoom(w http.ResponseWriter, r *http.Request) { | ||||
| @@ -143,6 +144,8 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) { | ||||
| 	fi.Room.IsRunning = true | ||||
| 	fi.Room.IsOver = false | ||||
| 	fi.Room.TeamTurn = "blue" | ||||
| 	fi.Room.OpenedThisTurn = 0 | ||||
| 	fi.Room.ThisTurnLimit = 0 | ||||
| 	loadCards(fi.Room) | ||||
| 	fi.Room.UpdateCounter() | ||||
| 	fi.Room.TeamWon = "" | ||||
| @@ -226,6 +229,11 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	guessLimitU64, err := strconv.ParseUint(num, 10, 8) | ||||
| 	if err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	// validations === | ||||
| 	if fi.State.Team != models.UserTeam(fi.Room.TeamTurn) { | ||||
| 		err = errors.New("not your team's move") | ||||
| @@ -253,6 +261,7 @@ 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 | ||||
| 	notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) | ||||
| 	notifyBotIfNeeded(fi) | ||||
| 	if err := saveFullInfo(fi); err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder