

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

# 範例：設定團隊層級需求和延遲限制
<a name="match-examples-3"></a>

此範例說明如何設置玩家隊伍，並針對每個隊伍而非每個玩家套用一組規則。範例中使用單一定義來建立三個勢均力敵的隊伍。範例中也會建立所有玩家的最大延遲。延遲最大值可隨時間放寬，以完成配對。此範例會列出下列指示：
+ 建立三個玩家隊伍。
  + 在每個隊伍中加入 3 到 5 個玩家。
  + 最終確定的隊伍，必須包含相同或幾乎相同的玩家人數 (落差在一個人以內)。
+ 加入下列的玩家屬性：
  + 玩家的技能等級 (如果未提供，預設為 10)。
  + 玩家的遊戲角色 (如果未提供，預設為「農夫」)。
+ 根據其技能等級是否接近配對中其他玩家的這項條件，來選擇玩家。
  + 確保每個隊伍的玩家平均技能值落差在 10 點之內。
+ 根據下列的「medic (醫生)」角色人數來限制隊伍：
  + 整個配對最多可有 5 個醫生 (medic)。
+ 僅限回報的延遲時間在 50 毫秒以內的配對玩家。
+ 如果未能快速完成配對，請放寬玩家延遲的要求，如下所示：
  + 超過 10 秒後，允許玩家的延遲值最高可到 100 ms。
  + 超過 20 秒後，允許玩家的延遲值最高可到 150 ms。

使用此規則集的注意事項：
+ 此規則集可確保隊伍根據玩家的技能均衡配對。為了評估 `FairTeamSkill` 規則，FlexMatch 會暫時性地在隊伍中新增候選玩家，並計算隊伍玩家的平均技能。然後，會與兩個隊伍中玩家的平均技能進行比較。如果不符規則，則不會將潛在的玩家加入配對。
+ 隊伍和配對層級的要求 (medic 的總人數) 會透過集合規則滿足。此規則類型需要所有玩家的角色屬性清單，並針對數目上限進行比對。利用 `flatten` 來建立所有隊伍中所有玩家的清單。
+ 根據延遲來進行評估時，請注意下列事項：
  + 延遲資料會在配對請求中提供，此請求是 Player (玩家) 物件的一部分。此資料並非玩家屬性，所以不需要列為屬性。若要取得準確的延遲測量，請使用 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
        }]
    }]
}
```