

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 範例：比較所有玩家的屬性
<a name="match-examples-6"></a>

此範例說明如何在一組玩家之間比較玩家的屬性。

範例規則集利用下列的角色來說明配對：
+ 隊伍結構：兩個單一玩家的隊伍
+ 玩家屬性：
  + *gameMode* (遊戲模式)：玩家所選擇的遊戲類型 (如果未提供，預設為「回合制」)。
  + *gameMap* (遊戲地圖)：玩家所選擇的遊戲世界 (如果未提供，預設為 1)。
  + *character* (角色)：玩家所選擇的角色 (無預設值表示玩家必須指定角色)。
+ 配對規則：配對的玩家必須符合下列要求：
  + 玩家必須選擇相同的遊戲模式。
  + 玩家必須選擇相同的遊戲地圖。
  + 玩家必須選擇不同的角色。

使用此規則集的注意事項：
+ 為了實行配對規則，此範例使用比較規則來檢查所有玩家的屬性值。針對遊戲模式和地圖，該規則會驗證值是否相同。針對角色，該規則會驗證值是否不同。
+ 此範例使用一個有數量屬性的玩家定義來建立這兩個玩家隊伍。隊伍會獲得以下名稱：「player\_1」和「player\_2」。

```
{
    "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])"]
    }]
}
```