> ## 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.

# Matchmaking 方案和配置示例

> 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]
>
> 要使此功能正常工作，各模式所需的玩家人数必须相同。

```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` 值。

```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
        }
    ],
}
```

## 标准 4v4 风格（基于技能）

PlayFab Matchmaking 支持面向团队的对局。指定团队后，你在同一票证中一起提交的玩家都会被分配到同一个团队，并且不会被强制相互对战。

PlayFab Matchmaking 还支持各种团队规则，以帮助确保团队平衡。此示例适用于 4v4 对局，可确保各团队之间的技能保持平衡。

```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]
>
> 当一组玩家一起提交票证时，服务会将该组视为一个单元，不会将该组拆分到不同的对局或团队中。你的游戏客户端应在提交票证之前验证组的构成。例如，如果某个玩家禁用了跨平台游戏，请在创建票证之前阻止其加入跨平台组。

如果匹配时间比预期长，请考虑为每个平台创建单独的队列，并根据需要创建跨平台队列以支持跨平台游戏。

```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]
>
> 如果主机数量远远超过搜索者数量（或反之），这种不平衡可能会导致所有玩家的匹配时间变慢。请考虑匹配设计的影响，以确保任何给定的子群体中都有足够的玩家来满足你的匹配规则和所需的平均匹配时间。

```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 即可匹配。

```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]
>
> 服务器始终可以检索此信息。以下配置仅控制是否也允许用户进行此调用。

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


## Related topics

- [匹配](/zh-CN/services/playfab/multiplayer/matchmaking/index.md)
- [匹配的工作原理](/zh-CN/services/playfab/multiplayer/matchmaking/how-matchmaking-works.md)
- [了解匹配中的规则权重](/zh-CN/services/playfab/multiplayer/matchmaking/rule-weights.md)
- [在游戏中显示队列统计信息](/zh-CN/services/playfab/multiplayer/matchmaking/display-statistics.md)
- [Wrapper 示例](/zh-CN/services/playfab/multiplayer/servers/wrapper-sample.md)
