> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 配對案例與設定範例

> PlayFab Matchmaking 佇列設定範例，涵蓋常見遊戲模式的技能型配對、區域選取、隊伍規則和屬性擴充。

## 概觀

佇列與規則系統提供彈性，可處理大量案例。以下是一些較常見的配對使用案例及其相關佇列的範例。您可以使用 PlayFab API 直接提交這些設定。\<!--the [Matchmaking Admin API](xref:titleid.playfabapi.com.multiplayer.matchmakingadmin).--> 您也可以使用 Game Manager UI 設定這些選項。

## 我的第一個佇列，或「快速配對」

每個遊戲都應該從這個簡單的佇列開始，以建立其基本流程。此佇列會將兩位玩家配對在一起，並包含一個選用規則，要求玩家傳入相同的組建字串才能配對。如果您未指定組建，玩家可以與此佇列中的其他玩家配對，而不論組建為何。

```json theme={null}
"MatchmakingQueue": {
    "Name": "MyFirstQueue",
    "MinMatchSize": 2,
    "MaxMatchSize": 2,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "StringEqualityRule",
            "Attribute": {
                "Path": "Build",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "BuildVersionRule"
        }
    ]
}
```

## 多種遊戲模式

遊戲通常有不同的玩法。如果這些玩家永遠不應彼此配對，將他們放在不同的佇列中可以最佳化效能。

```json theme={null}
{
    "MatchmakingQueue": {
        "Name": "FreeForAllQueue",
        "MinMatchSize": 4,
        "MaxMatchSize": 4,
        "ServerAllocationEnabled": false,
        "Rules": [
        ]
    }
}
```

```json theme={null}
{
    "MatchmakingQueue": {
        "Name": "CaptureTheFlagQueue",
        "MinMatchSize": 4,
        "MaxMatchSize": 4,
        "ServerAllocationEnabled": false,
        "Rules": [
        ]
    }
}
```

## 跨遊戲模式搜尋

如果玩家要跨遊戲模式與其他玩家配對，請使用單一佇列並建立集合交集規則。玩家可以指定多種遊戲模式，而此規則會將比賽限制為所有玩家至少有一種共同遊戲模式的比賽。

<Note>
  各模式所需的玩家人數必須相同，此功能才能正常運作。
</Note>

```json theme={null}
{
    "MatchmakingQueue": {
        "Name": "MultiGameModeSearchQueue",
        "MinMatchSize": 4,
        "MaxMatchSize": 4,
        "ServerAllocationEnabled": false,
        "Rules": [
        {
                "Type": "SetIntersectionRule",
                "MinIntersectionSize": 1,
                "Attribute": {
                    "Path": "GameMode",
                    "Source": "User"
                },
                "AttributeNotSpecifiedBehavior": "MatchAny",
                "Weight": 1,
                "Name": "GameModeRule"
            }
        ]
    }
}
```

## 具擴充功能的技能型混戰遊戲

常見的案例是嘗試根據*技能*將玩家配對在一起。在此範例中，佇列要求玩家的技能屬性差距在 0.2 以內，且此差距會隨時間增加到 0.5。對於等候超過 30 秒的票證，則允許任何技能差距。

此範例中的值假設可用技能的範圍介於 0 到 1 之間。請調整這些值，以符合您的遊戲用來追蹤玩家技能的值範圍，以及相較於配對速度對技能的重視程度。

此外，規則在 30 秒時變成選用，適用於寧可在技能不平衡的情況下進行遊戲，也不願完全無法遊玩的遊戲。對於不平衡的遊戲完全是負面體驗的遊戲，請調整 `SecondsUntilOptional`。如果完全移除此設定，規則會無限期地保持作用中。

```json theme={null}
"MatchmakingQueue": {
    "Name": "SkillBasedFreeForAllQueue",
    "MinMatchSize": 4,
    "MaxMatchSize": 4,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "DifferenceRule",
            "Difference": 0.2,
            "MergeFunction": "Average",
            "DefaultAttributeValue": 0.5,
            "Expansion": {
                "Delta": 0.1,
                "Limit": 0.5,
                "Type": "Linear",
                "SecondsBetweenExpansions": 5
            },
            "Attribute": {
                "Path": "Skill",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "UseDefault",
            "Weight": 1,
            "Name": "SkillRule",
            "SecondsUntilOptional": 30
        }
    ]
}
```

## 自訂擴充

您可以自訂擴充，在每個時間間隔中使用任意值。例如，您可能希望允許的技能差距一開始緩慢增加，之後隨時間更快速地增加。

```json theme={null}
"MatchmakingQueue": {
    "Name": "SkillBasedFreeForAllCustomExpansionQueue",
    "MinMatchSize": 4,
    "MaxMatchSize": 4,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "DifferenceRule",
            "Difference": 0.2,
            "MergeFunction": "Average",
            "DefaultAttributeValue": 0.5,
            "Expansion": {
                "DifferenceOverrides": [
                    0.025,
                    0.05,
                    0.1,
                    0.2,
                    0.3,
                    0.5
                ],
                "Type": "Custom",
                "SecondsBetweenExpansions": 5
            },
            "Attribute": {
                "Path": "Skill",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "UseDefault",
            "Weight": 1,
            "Name": "SkillRule",
            "SecondsUntilOptional": 30
        }
    ]
}
```

## 隨時間擴充玩家人數

有些遊戲偏好一開始就有滿員的比賽，但隨著時間經過，可能會接受越來越少的人數。其中一個範例是大逃殺風格的遊戲，其設計為最多 50 位玩家開始，但在配對逾時後可以用較少的玩家進行。

由於 `MinMatchSize` 和 `MaxMatchSize` 不包含擴充，您可以使用 `MatchTotalRule` 來修改比賽所需的玩家人數。每位玩家都將相關聯的屬性設為 1。此規則會加總這些值，以動態強制執行比賽所需的玩家人數。

<Note>
  如果您未指定 `MaxOverrides` 或 `MinOverrides` 陣列，則會改用規則原始的 `Max` 或 `Min` 值。
</Note>

```json theme={null}
"MatchmakingQueue": {
    "Name": "PlayerExpansionOverTime",
    "MinMatchSize": 8,
    "MaxMatchSize": 50,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "MatchTotalRule",
            "Attribute": {
                "Path": "PlayerCount",
                "Source": "User"
            },
            "Min": 8,
            "Max": 50,
            "Weight": 1,
            "Expansion": {
                "MinOverrides": [
                    50,
                    45,
                    40,
                    35,
                    25,
                    16,
                    8
                ],
                "Type": "Custom",
                "SecondsBetweenExpansions": 10
            },
            "Name": "PlayersRequiredRule",
            "SecondsUntilOptional": 60
        }
    ],
}
```

## 標準 4 對 4 技能型

PlayFab Matchmaking 支援以隊伍為導向的比賽。當您指定隊伍時，您在同一張票證中一起提交的玩家都會被分配到同一隊，不會被迫彼此對戰。

PlayFab Matchmaking 也支援各種隊伍規則，以協助確保隊伍之間的平衡。此範例適用於 4 對 4 比賽，可確保各隊伍之間的技能平衡。

```json theme={null}
"MatchmakingQueue": {
    "Name": "Standard4v4TeamsQueue",
    "MinMatchSize": 8,
    "MaxMatchSize": 8,
    "ServerAllocationEnabled": false,
    "Teams": [
        {
            "Name": "Red",
            "MinTeamSize": 4,
            "MaxTeamSize": 4
        },
        {
            "Name": "Blue",
            "MinTeamSize": 4,
            "MaxTeamSize": 4
        }
    ],
    "Rules": [
        {
            "Type": "TeamDifferenceRule",
            "Attribute": {
                "Path": "Skill",
                "Source": "User"
            },
            "Difference": 0.2,
            "DefaultAttributeValue": 0.5,
            "Expansion": {
                "Delta": 0.1,
                "Limit": 0.5,
                "Type": "Linear",
                "SecondsBetweenExpansions": 5
            },
            "Name": "TeamSkillRule",
            "SecondsUntilOptional": 30
        }
    ]
}
```

## 多人遊戲伺服器

佇列可以自動銜接 PlayFab 的多人遊戲伺服器功能，配置伺服器並將已配對的玩家清單提供給它。此佇列提供此類設定的最精簡範例，也就是 `ServerAllocationEnabled` 旗標，以及代表應啟動哪個伺服器組建的 `BuildId`。

當您將 `ServerAllocationEnabled` 旗標設為 `true` 時，也必須包含 `RegionSelectionRule`，以指出應在何處為每場比賽配置伺服器。

```json theme={null}
"MatchmakingQueue": {
    "Name": "MultiplayerServersQueue",
    "MinMatchSize": 24,
    "MaxMatchSize": 24,
    "ServerAllocationEnabled": true,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "RegionSelectionRule",
            "MaxLatency": 200,
            "Path": "Latency",
            "Weight": 1,
            "Name": "RegionSelectionRule"
        }
    ]
}
```

## 大型隊伍對戰 (12 對 12)

較大型的隊伍遊戲可能有額外的需求。在此範例中，佇列設定為建立多人遊戲伺服器，管理玩家人數這麼多的遊戲時通常需要這麼做。此設定與上一個範例類似。

除了技能之外，再新增另一個隊伍規則以促進隊伍相似度。每一方只允許一個大型隊伍，以避免常見的預組隊伍與一大群隨機玩家配對的情況。

```json theme={null}
"MatchmakingQueue": {
    "Name": "LargeTeamsQueue",
    "MinMatchSize": 24,
    "MaxMatchSize": 24,
    "ServerAllocationEnabled": true,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Teams": [
        {
            "Name": "Red",
            "MinTeamSize": 12,
            "MaxTeamSize": 12
        },
        {
            "Name": "Blue",
            "MinTeamSize": 12,
            "MaxTeamSize": 12
        }
    ],
    "Rules": [
        {
            "Type": "TeamTicketSizeSimilarityRule",
            "Name": "PreventLargePremadeVersusRandomsRule",
            "SecondsUntilOptional": 20
        },
        {
            "Type": "TeamDifferenceRule",
            "Attribute": {
                "Path": "Skill",
                "Source": "User"
            },
            "Difference": 0.1,
            "DefaultAttributeValue": 0.5,
            "Expansion": {
                "Delta": 0.1,
                "Limit": 0.5,
                "Type": "Linear",
                "SecondsBetweenExpansions": 5
            },
            "Name": "TeamSkillRule",
            "SecondsUntilOptional": 30
        },
        {
            "Type": "RegionSelectionRule",
            "MaxLatency": 200,
            "Path": "Latency",
            "Weight": 1,
            "Name": "RegionSelectionRule"
        }
    ]
}
```

## 大逃殺風格遊戲

大逃殺風格遊戲會將許多人放入同一個競技場。在此範例中，遊戲設定為四人一隊。目前，像這樣的隊伍案例最多允許 32 位玩家。此限制將在未來改善。

此範例也包含專用伺服器的多人遊戲伺服器設定資訊，對於玩家人數眾多的遊戲而言，這通常是必要的。此設定與上一個範例類似。

```json theme={null}
    "MatchmakingQueue": {
        "Name": "BattleRoyaleStyleQueueWithTeams",
        "MinMatchSize": 32,
        "MaxMatchSize": 32,
        "ServerAllocationEnabled": true,
        "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
        "Teams": [
            {
                "Name": "team1",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team2",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team3",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team4",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team5",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team6",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team7",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            },
            {
                "Name": "team8",
                "MinTeamSize": 4,
                "MaxTeamSize": 4
            }
        ],
        "Rules": [
            {
                "Type": "RegionSelectionRule",
                "MaxLatency": 200,
                "Path": "Latency",
                "Weight": 1,
                "Name": "RegionSelectionRule"
            }
        ]
    }
```

## 處理不對稱的跨平台遊玩偏好

由於玩家可以選擇不同的跨平台遊玩設定，配對偏好是不對稱的。啟用跨平台遊玩的玩家願意與任何平台配對，而停用跨平台遊玩的玩家只想與自己平台上的玩家配對。

您可以使用字串相等規則或集合交集規則，實作能處理此類不對稱情況的配對佇列。此範例使用字串相等。

如果玩家停用跨平台遊玩，用戶端會指定其 `DeviceType` (例如 `"xbox"`、`"playstation"`)，而規則會將其限制為同平台比賽。如果玩家啟用跨平台遊玩，用戶端會完全省略 `DeviceType` 屬性，而 `MatchAny` 的 `AttributeNotSpecifiedBehavior` 可讓其與任何平台配對。

<Note>
  當一群玩家一起提交票證時，服務會將該群組視為單一單位，不會將群組拆分到不同的比賽或隊伍。您的遊戲用戶端應在提交票證之前驗證群組組成。例如，如果某位玩家停用了跨平台遊玩，請在建立票證之前防止其加入跨平台群組。
</Note>

如果配對時間比預期長，請考慮為每個平台建立個別的佇列，並視需要搭配跨平台佇列以支援跨平台遊玩。

```json theme={null}
"MatchmakingQueue": {
    "Name": "CrossDeviceQueue",
    "MinMatchSize": 32,
    "MaxMatchSize": 32,
    "ServerAllocationEnabled": false,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "StringEqualityRule",
            "Attribute": {
                "Path": "DeviceType",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "CrossDeviceRule"
        }
    ]
}
```

## 主機/搜尋者或角色型需求

PlayFab Match 使用以票證為基礎的配對系統，不會事先選取遊戲主機。不過，它可以使用 `MatchTotalRule` 限制比賽中允許的主機數目，藉此模擬主機-搜尋者系統。

接著，票證可以藉由指定 1 來事先指出它是否為主機。每場比賽必須剛好包含一個主機。

<Note>
  如果主機數目遠超過搜尋者，或反之亦然，此不平衡可能會導致所有玩家的配對時間變慢。請考量您的配對設計所帶來的影響，確保任何特定子群體中都有足夠的玩家，以滿足您的配對規則和所需的平均配對時間。
</Note>

```json theme={null}
"MatchmakingQueue": {
    "Name": "HostSearcherQueue",
    "MinMatchSize": 8,
    "MaxMatchSize": 8,
    "ServerAllocationEnabled": false,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "MatchTotalRule",
            "Attribute": {
                "Path": "IsHost",
                "Source": "User"
            },
            "Min": 1,
            "Max": 1,
            "Weight": 1,
            "Name": "OneHostRule"
        }
    ]
}
```

遊戲可能有角色需求。例如，遊戲可能需要一位鼓手、兩位吉他手和一位主唱。或是一個坦克、兩個每秒傷害 (DPS) 和一個支援。遊戲可以使用 `MatchTotalRule` 來要求這些角色。

```json theme={null}
"MatchmakingQueue": {
    "Name": "RoleBasedQueue",
    "MinMatchSize": 4,
    "MaxMatchSize": 4,
    "ServerAllocationEnabled": false,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "MatchTotalRule",
            "Attribute": {
                "Path": "TankSelected",
                "Source": "User"
            },
            "Min": 1,
            "Max": 1,
            "Weight": 1,
            "Name": "TankRule"
        },
        {
            "Type": "MatchTotalRule",
            "Attribute": {
                "Path": "DPSSelected",
                "Source": "User"
            },
            "Min": 2,
            "Max": 2,
            "Weight": 1,
            "Name": "DPSRule"
        },
        {
            "Type": "MatchTotalRule",
            "Attribute": {
                "Path": "SupportSelected",
                "Source": "User"
            },
            "Min": 1,
            "Max": 1,
            "Weight": 1,
            "Name": "SupportRule"
        }
    ]
}
```

## 具有不同重要性的規則

規則透過限制哪些票證有資格彼此配對，以及選擇挑選這些票證的順序來引導配對。當有多個規則時，系統會將所有規則的限制都納入考量。不過，遊戲可能會讓某個規則的偏好優先套用於其餘符合資格的票證。

在此範例中，玩家必須在特定的技能和經驗等級範圍內。不過，如果有許多票證落在指定的技能和經驗範圍內，此佇列會偏好技能較接近的票證，而非經驗等級較接近的票證。

評估符合限制的票證時，技能差距的權重是經驗差距的*三倍*。

```json theme={null}
"MatchmakingQueue": {
    "Name": "WeightingQueue",
    "MinMatchSize": 4,
    "MaxMatchSize": 4,
    "ServerAllocationEnabled": false,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "DifferenceRule",
            "Difference": 1,
            "MergeFunction": "Average",
            "Attribute": {
                "Path": "skill",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 3,
            "Name": "SkillRule"
        },
        {
            "Type": "DifferenceRule",
            "Difference": 5,
            "MergeFunction": "Average",
            "Attribute": {
                "Path": "experience",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "ExperienceRule"
        }
    ]
}
```

## DLC 套件

透過各種 DLC 套件，玩家可以使用 `SetIntersectionRule` 選擇只尋找擁有相符 DLC 的其他玩家。每位玩家都會傳入其擁有的 DLC 套件，而比賽要求群組至少共用一個 DLC 套件。

<Note>
  30 秒後，此規則會變成選用，因此玩家可以在不共用 DLC 的情況下配對。
</Note>

```json theme={null}
"MatchmakingQueue": {
    "Name": "DlcQueue",
    "MinMatchSize": 4,
    "MaxMatchSize": 4,
    "ServerAllocationEnabled": false,
    "BuildId": "6a4d2760-4295-417e-b149-0a12e3570d94",
    "Rules": [
        {
            "Type": "SetIntersectionRule",
            "MinIntersectionSize": 1,
            "Attribute": {
                "Path": "DlcPacks",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "DlcRule",
            "SecondsUntilOptional": 30
        }
    ]
}
```

## 啟用統計資料

當您啟用統計資料時，您的遊戲可以顯示有關佇列的資訊。在玩家選擇想要遊玩的遊戲模式時，這項資訊有助於設定玩家的預期。

相反地，遊戲可能希望隱藏此資訊，原因可能是商業智慧考量，或是為了避免將玩家引導至高流量的佇列。

此佇列同時啟用檢視佇列中目前玩家人數的功能，以及票證配對所需的預估時間。

<Note>
  伺服器一律可以擷取此資訊。下列設定只控制是否也允許使用者進行此呼叫。
</Note>

```json theme={null}
"MatchmakingQueue": {
    "Name": "StatisticsEnabledQueue",
    "MinMatchSize": 8,
    "MaxMatchSize": 8,
    "ServerAllocationEnabled": false,
    "Rules": [],
    "StatisticsVisibilityToPlayers": {
        "ShowNumberOfPlayersMatching": true,
        "ShowTimeToMatch": true
    }
}
```


## Related topics

- [配對](/zh-TW/services/playfab/multiplayer/matchmaking/index.md)
- [配對的運作方式](/zh-TW/services/playfab/multiplayer/matchmaking/how-matchmaking-works.md)
- [了解配對中的規則權數](/zh-TW/services/playfab/multiplayer/matchmaking/rule-weights.md)
- [設定配對佇列](/zh-TW/services/playfab/multiplayer/matchmaking/config-queues.md)
- [設定傳回資料範例](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-return-data.md)
