

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 示例：设置团队级要求和延迟限制
<a name="match-examples-3"></a>

此示例说明如何设置玩家团队，并为每个团队应用规则集，而不是为每个玩家应用规则集。它使用单个定义创建三个平均的对战团队。它还会设置所有玩家的最大延迟。随着时间的推移可以放宽延迟最大值以完成对战游戏。此方案规定了以下说明：
+ 创建三个玩家团队。
  + 每个团队包含三到五个玩家。
  + 最终团队必须包含数量相同或基本相同的玩家 (一个团队中)。
+ 包含以下玩家属性：
  + 玩家的技能水平（如果未提供，则默认为 10）。
  + 玩家的人物角色 (如果未提供，则默认为“peasant”)。
+ 选择与对战游戏中其他玩家技能水平相当的玩家。
  + 确保每个团队的平均玩家技能在 10 点以内。
+ 将团队数量限制为“medic”角色的以下数量：
  + 整个对战游戏最多可以包含 5 个医生。
+ 仅匹配报告 50 毫秒或更少延迟的玩家。
+ 如果对战游戏未快速填满，则放宽玩家的延迟要求，如下所示：
  + 10 秒之后，允许将玩家的延迟时间值增加到 100 毫秒。
  + 20 秒之后，允许将玩家的延迟时间值增加到 150 毫秒。

使用此规则集的说明：
+ 规则集可确保根据玩家技能构建对战团队。为评估 `FairTeamSkill` 规则，FlexMatch 会暂时将潜在玩家加入团队并计算团队中玩家的平均技能。然后，它将规则与两个团队中的玩家平均技能进行比较。如果规则失败，则不会将潜在玩家添加到对战游戏。
+ 团队和对战游戏级别的要求 (医生总数) 通过一组规则实现。此规则类型会获取所有玩家的角色属性列表，并针对最大数量进行检查。使用 `flatten` 为所有团队中的所有玩家创建列表。
+ 根据延迟进行评估时，请注意以下几点：
  + 延迟数据在对战请求中作为玩家对象的一部分提供。它不是玩家属性，因此无需列出。要获得准确的延迟测量值，请使用 Amazon GameLift Servers 的 UDP ping 信标。这些端点使您能够测量玩家设备与每个潜在托管位置之间的实际 UDP 网络延迟，从而比使用 ICMP ping 更准确地做出放置决策。有关使用 UDP ping 信标测量延迟的更多信息，请参阅 [UDP ping 信标](https://docs.aws.amazon.com/gameliftservers/latest/developerguide/reference-udp-ping-beacons.html)。
  + 对战构建器按区域评估延迟。延迟高于最大延迟的任何区域都将被忽略。要让对战游戏接受，玩家必须至少有一个区域的延迟低于最大延迟。
  + 如果对战请求忽略一个或多个玩家的延迟数据，则会拒绝所有对战游戏的请求。

```
{
    "name": "three_team_game",
    "ruleLanguageVersion": "1.0",
    "playerAttributes": [{
        "name": "skill",
        "type": "number",
        "default": 10
    },{
        "name": "character",
        "type": "string_list",
        "default": [ "peasant" ]
    }],
    "teams": [{
        "name": "trio",
        "minPlayers": 3,
        "maxPlayers": 5,
        "quantity": 3
    }],
    "rules": [{
        "name": "FairTeamSkill",
        "description": "The average skill of players in each team is within 10 points from the average skill of players in the match",
        "type": "distance",
        // get players for each team, and average separately to produce list of 3
        "measurements": [ "avg(teams[*].players.attributes[skill])" ],
        // get players for each team, flatten into a single list, and average to produce overall average
        "referenceValue": "avg(flatten(teams[*].players.attributes[skill]))",
        "maxDistance": 10 // minDistance would achieve the opposite result
    }, {
        "name": "CloseTeamSizes",
        "description": "Only launch a game when the team sizes are within 1 of each other.  e.g. 3 v 3 v 4 is okay, but not 3 v 5 v 5",
        "type": "distance",
        "measurements": [ "max(count(teams[*].players))"],
        "referenceValue": "min(count(teams[*].players))",
        "maxDistance": 1
    }, {
        "name": "OverallMedicLimit",
        "description": "Don't allow more than 5 medics in the game",
        "type": "collection",
        // This is similar to above, but the flatten flattens everything into a single
        // list of characters in the game.
        "measurements": [ "flatten(teams[*].players.attributes[character])"],
        "operation": "contains",
        "referenceValue": "medic",
        "maxCount": 5
    }, {
        "name": "FastConnection",
        "description": "Prefer matches with fast player connections first",
        "type": "latency",
        "maxLatency": 50
    }],
    "expansions": [{
        "target": "rules[FastConnection].maxLatency",
        "steps": [{
            "waitTimeSeconds": 10,
            "value": 100
        }, {
            "waitTimeSeconds": 20,
            "value": 150
        }]
    }]
}
```