xy 1 săptămână în urmă
părinte
comite
e7f0f0295b
1 a modificat fișierele cu 42 adăugiri și 3 ștergeri
  1. 42 3
      src/server/game/ludo/match_robot.go

+ 42 - 3
src/server/game/ludo/match_robot.go

@@ -56,16 +56,55 @@ func Scheduling() {
 					} else {
 						lack_num = 4 - len(room_info.Colors)
 					}
-					addRobot(room_info, lack_num)
+					addRobotsToRoom(room_info, lack_num)
 				}
 			}
 		}
 	}
 }
 
-func addRobot(room_info *msg.RoomInfo, num int) {
+func RemoveColorByColor(temp []msg.RoleType, color msg.RoleType) []msg.RoleType {
+	result := make([]msg.RoleType, 0, len(temp))
+	for _, item := range temp {
+		if item != color {
+			result = append(result, item)
+		}
+	}
+	return result
+}
+func getRoomLackColor(room_info *msg.RoomInfo) msg.RoleType {
+	var select_color msg.RoleType
+	if room_info.RoomType == msg.RoomType_SHUANG_REN {
+		if room_info.Colors[0].MColor == msg.RoleType_BLUE {
+			select_color = msg.RoleType_GREEN
+		} else {
+			select_color = msg.RoleType_BLUE
+		}
+	} else if room_info.RoomType == msg.RoomType_SIREN_REN {
+		var temp []msg.RoleType = make([]msg.RoleType, 4)
+		temp = append(temp, msg.RoleType_BLUE)
+		temp = append(temp, msg.RoleType_GREEN)
+		temp = append(temp, msg.RoleType_RED)
+		temp = append(temp, msg.RoleType_YELLOW)
+
+		for i := 0; i < len(room_info.Colors); i++ {
+			color_data := room_info.Colors[i]
+			temp = RemoveColorByColor(temp, color_data.MColor)
+		}
+		if len(temp) > 0 {
+			select_color = temp[0]
+		}
+	}
+	return select_color
+}
+
+func addRobotsToRoom(room_info *msg.RoomInfo, num int) {
 	for i := 0; i < num; i++ {
-		matchInfo := &msg.MatchLudo{}
+		matchInfo := &msg.MatchLudo{
+			RoomLevel:      room_info.RoomLevel,
+			SelectRoomType: room_info.RoomType,
+			SelectColor:    getRoomLackColor(room_info),
+		}
 		robot_user_id := fmt.Sprintf("robot_%d", i)
 		isFullPlayer, err_info := JoinRoom(room_info, matchInfo, robot_user_id)
 		if err_info == nil {