

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

# 示例：创建两个势均力敌的玩家团队
<a name="match-examples-1"></a>

此示例说明如何按照以下说明设置两个势均力敌的玩家对战团队。
+ 创建两个玩家团队。
  + 每个团队包含四到八个玩家。
  + 最终团队必须具有相同数量的玩家。
+ 附上玩家的技能水平 (如果未提供，则默认为 10)。
+ 选择与其他玩家技能水平相当的玩家。确保这两个团队的平均玩家技能在 10 点以内。
+ 如果未能快速填充对战游戏，则放宽玩家技能要求以在合理的时间内完成对战游戏。
  + 5 秒之后，扩大搜索范围以允许创建平均玩家技能在 50 点以内的团队。
  + 15 秒之后，扩大搜索范围以允许创建平均玩家技能在 100 点以内的团队。

使用此规则集的说明：
+ 此示例允许创建包含 4 到 8 位玩家的任何规模的团队 (但两个团队的规模必须相同)。对于在有效规模范围内的团队，对战构建器会尽量尝试匹配允许的最大玩家数量。
+ `FairTeamSkill` 规则集可确保根据玩家技能构建对战团队。要对每个新的潜在玩家评估此规则，FlexMatch, 会暂时将玩家加入团队并计算平均值。如果规则失败，则不会将潜在玩家添加到对战游戏。
+ 由于这两个团队具有相同的结构，您可以选择仅创建一个团队定义，并将团队数量设置为“2”。在这种情况下，如果您将团队命名为“aliens”，那么为您的团队分配的名称将为“aliens\$11”和“aliens\$12”。

```
{
    "name": "aliens_vs_cowboys",
    "ruleLanguageVersion": "1.0",
    "playerAttributes": [{
        "name": "skill",
        "type": "number",
        "default": 10
    }],
    "teams": [{
        "name": "cowboys",
        "maxPlayers": 8,
        "minPlayers": 4
    }, {
        "name": "aliens",
        "maxPlayers": 8,
        "minPlayers": 4
    }],
    "rules": [{
        "name": "FairTeamSkill",
        "description": "The average skill of players in each team is within 10 points from the average skill of all players in the match",
        "type": "distance",
        // get skill values for players in each team and average separately to produce list of two numbers
        "measurements": [ "avg(teams[*].players.attributes[skill])" ],
        // get skill values for players in each team, flatten into a single list, and average to produce an overall average
        "referenceValue": "avg(flatten(teams[*].players.attributes[skill]))",
        "maxDistance": 10 // minDistance would achieve the opposite result
    }, {
        "name": "EqualTeamSizes",
        "description": "Only launch a game when the number of players in each team matches, e.g. 4v4, 5v5, 6v6, 7v7, 8v8",
        "type": "comparison",
        "measurements": [ "count(teams[cowboys].players)" ],
        "referenceValue": "count(teams[aliens].players)",
        "operation": "=" // other operations: !=, <, <=, >, >=
    }],
    "expansions": [{
        "target": "rules[FairTeamSkill].maxDistance",
        "steps": [{
            "waitTimeSeconds": 5,
            "value": 50
        }, {
            "waitTimeSeconds": 15,
            "value": 100
        }]
    }]
}
```