

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

# 示例：使用显式排序以查找最佳对战游戏
<a name="match-examples-4"></a>

此示例设置了包含三个玩家的两个团队的简单对战游戏。它介绍了如何使用显式排序规则才能尽快找到最佳对战游戏。这些规则会为对战票证预排序，以根据特定的关键要求创建最佳对战游戏。此方案根据以下说明实现：
+ 创建两个玩家团队。
+ 每个团队只包含三个玩家。
+ 包含以下玩家属性：
  + 经验等级 (如果未提供，则默认为 50)。
  + 首选游戏模式 (可以列出多个值) (如果未提供，则默认为“coop”和“deathmatch”)。
  + 首选游戏地图，包括地图名称和首选权重 (如果未提供，则默认使用 `"defaultMap"` 和权重 100)。
+ 设置预排序：
  + 根据与基准点玩家相同的游戏地图的首选项来对玩家排序。玩家可以有多个最喜欢的游戏地图，因此本示例使用首选项值。
  + 根据玩家与基准点玩家的经验等级的接近程度对玩家排序。采用这种排序方式，所有玩家在所有团队中的经验等级会尽可能地接近。
+ 所有团队中的所有玩家必须至少选择一个共同的游戏模式。
+ 所有团队中的所有玩家必须至少选择一个共同的游戏地图。

使用此规则集的说明：
+ 游戏地图排序采用与 mapPreference 属性值进行比较的绝对排序。由于它是规则集中的第一个，此排序将首先执行。
+ 经验排序采用比较潜在玩家的技能级别与基准点玩家的技能的距离排序。
+ 排序按它们在规则集中的排列顺序执行。在这种情况下，玩家先按游戏地图首选项进行排序，然后按经验等级排序。

```
{
    "name": "multi_map_game",
    "ruleLanguageVersion": "1.0",
    "playerAttributes": [{
        "name": "experience",
        "type": "number",
        "default": 50
    }, {
        "name": "gameMode",
        "type": "string_list",
        "default": [ "deathmatch", "coop" ]
    }, {
        "name": "mapPreference",
        "type": "string_number_map",
        "default": { "defaultMap": 100 }
    }, {
        "name": "acceptableMaps",
        "type": "string_list",
        "default": [ "defaultMap" ]
    }],
    "teams": [{
        "name": "red",
        "maxPlayers": 3,
        "minPlayers": 3
    }, {
        "name": "blue",
        "maxPlayers": 3,
        "minPlayers": 3
    }],
    "rules": [{
        // We placed this rule first since we want to prioritize players preferring the same map
        "name": "MapPreference",
        "description": "Favor grouping players that have the highest map preference aligned with the anchor's favorite",
        // This rule is just for sorting potential matches.  We sort by the absolute value of a field.
        "type": "absoluteSort",
        // Highest values go first
        "sortDirection": "descending",
        // Sort is based on the mapPreference attribute.
        "sortAttribute": "mapPreference",
        // We find the key in the anchor's mapPreference attribute that has the highest value.
        // That's the key that we use for all players when sorting.
        "mapKey": "maxValue"
    }, {
        // This rule is second because any tie-breakers should be ordered by similar experience values
        "name": "ExperienceAffinity",
        "description": "Favor players with similar experience",
        // This rule is just for sorting potential matches.  We sort by the distance from the anchor.
        "type": "distanceSort",
        // Lowest distance goes first
        "sortDirection": "ascending",
        "sortAttribute": "experience"
    }, {
        "name": "SharedMode",
        "description": "The players must have at least one game mode in common",
        "type": "collection",
        "operation": "intersection",
        "measurements": [ "flatten(teams[*].players.attributes[gameMode])"],
        "minCount": 1
    }, {
        "name": "MapOverlap",
        "description": "The players must have at least one map in common",
        "type": "collection",
        "operation": "intersection",
        "measurements": [ "flatten(teams[*].players.attributes[acceptableMaps])"],
        "minCount": 1
    }]
}
```