

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

# 示例：在所有玩家之间比较属性
<a name="match-examples-6"></a>

此示例说明如何在一组玩家之间比较玩家属性。

此示例规则集描述了一个具有以下特征的对战游戏：
+ 团队结构：两个单人游戏团队
+ 玩家属性：
  + *gameMode*：玩家选择的游戏类型 (如果未提供，则默认设置为“基于次序”)。
  + *gameMap*：玩家选择的游戏世界 (如果未提供，则默认设置为 1)。
  + *character*：玩家选择的角色（无默认值，表示玩家必须指定角色）。
+ 对战游戏规则：匹配的玩家必须满足以下要求：
  + 玩家必须选择相同的游戏模式。
  + 玩家必须选择相同的游戏地图。
  + 玩家必须选择不同的角色。

使用此规则集的说明：
+ 为了实施该对战游戏规则，此示例使用比较规则来检查所有玩家的属性值。对于游戏模式和地图，该规则验证值是相同的。对于角色，该规则验证值是不同的。
+ 此示例使用一个玩家定义与数量属性来创建两个玩家团队。为团队分配了下列名称：“player\$11”和“player\$12”。

```
{
    "name": "",
    "ruleLanguageVersion": "1.0",

    "playerAttributes": [{
        "name": "gameMode",
        "type": "string",
        "default": "turn-based"
    }, {
        "name": "gameMap",
        "type": "number",
        "default": 1
    }, {
        "name": "character",
        "type": "number"
    }],

    "teams": [{
        "name": "player",
        "minPlayers": 1,
        "maxPlayers": 1,
        "quantity": 2
    }],

    "rules": [{
        "name": "SameGameMode",
        "description": "Only match players when they choose the same game type",
        "type": "comparison",
        "operation": "=",
        "measurements": ["flatten(teams[*].players.attributes[gameMode])"]
    }, {
        "name": "SameGameMap",
        "description": "Only match players when they're in the same map",
        "type": "comparison",
        "operation": "=",
        "measurements": ["flatten(teams[*].players.attributes[gameMap])"]
    }, {
        "name": "DifferentCharacter",
        "description": "Only match players when they're using different characters",
        "type": "comparison",
        "operation": "!=",
        "measurements": ["flatten(teams[*].players.attributes[character])"]
    }]
}
```