Feat: which bot to move
This commit is contained in:
		| @@ -47,6 +47,11 @@ type Action struct { | ||||
| 	Number     string // for clue | ||||
| } | ||||
|  | ||||
| type BotPlayer struct { | ||||
| 	Role UserRole // gueeser | mime | ||||
| 	Team UserTeam | ||||
| } | ||||
|  | ||||
| type Room struct { | ||||
| 	ID        string    `json:"id" db:"id"` | ||||
| 	CreatedAt time.Time `json:"created_at" db:"created_at"` | ||||
| @@ -56,12 +61,13 @@ type Room struct { | ||||
| 	CreatorName   string   `json:"creator_name"` | ||||
| 	PlayerList    []string `json:"player_list"` | ||||
| 	ActionHistory []Action | ||||
| 	TeamTurn      string | ||||
| 	TeamTurn      UserTeam | ||||
| 	RedTeam       Team | ||||
| 	BlueTeam      Team | ||||
| 	Cards         []WordCard | ||||
| 	WCMap         map[string]WordColor | ||||
| 	Result        uint8 // 0 for unknown; 1 is win for red; 2 if for blue; | ||||
| 	BotMap        map[string]BotPlayer // key is bot name | ||||
| 	Result        uint8                // 0 for unknown; 1 is win for red; 2 if for blue; | ||||
| 	BlueCounter   uint8 | ||||
| 	RedCounter    uint8 | ||||
| 	RedTurn       bool // false is blue turn | ||||
| @@ -73,19 +79,48 @@ type Room struct { | ||||
| 	RoundTime int32  `json:"round_time"` | ||||
| 	// ProgressPct uint32 `json:"progress_pct"` | ||||
| 	IsOver  bool | ||||
| 	TeamWon string // blue | red | ||||
| 	TeamWon UserTeam // blue | red | ||||
| } | ||||
|  | ||||
| func (r *Room) GetOppositeTeamColor() string { | ||||
| // WhichBotToMove returns bot name that have to move or empty string | ||||
| func (r *Room) WhichBotToMove() string { | ||||
| 	if !r.IsRunning { | ||||
| 		return "" | ||||
| 	} | ||||
| 	switch r.TeamTurn { | ||||
| 	case "red": | ||||
| 		return "blue" | ||||
| 	case "blue": | ||||
| 		return "red" | ||||
| 	case UserTeamBlue: | ||||
| 		if !r.MimeDone { | ||||
| 			_, ok := r.BotMap[r.BlueTeam.Mime] | ||||
| 			if ok { | ||||
| 				return r.BlueTeam.Mime | ||||
| 			} | ||||
| 		} | ||||
| 		// check gussers | ||||
| 	case UserTeamRed: | ||||
| 		if !r.MimeDone { | ||||
| 			_, ok := r.BotMap[r.RedTeam.Mime] | ||||
| 			if ok { | ||||
| 				return r.RedTeam.Mime | ||||
| 			} | ||||
| 		} | ||||
| 		// check gussers | ||||
| 	default: | ||||
| 		// how did we got here? | ||||
| 		return "" | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| func (r *Room) GetOppositeTeamColor() UserTeam { | ||||
| 	switch r.TeamTurn { | ||||
| 	case "red": | ||||
| 		return UserTeamBlue | ||||
| 	case "blue": | ||||
| 		return UserTeamRed | ||||
| 	} | ||||
| 	return UserTeamNone | ||||
| } | ||||
|  | ||||
| func (r *Room) UpdateCounter() { | ||||
| 	redCounter := uint8(0) | ||||
| 	blueCounter := uint8(0) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder