# Game Center से online खेल के लिए players मिलाएँ

> किसी एजेंट को बताएँ कि आपके गेम के players को online कैसे मिलाया जाए। वह Game Center matchmaking queue और rules सेट करता है, उन्हें काल्पनिक players से test करता है, और गेम को उनसे जोड़ता है।

Source: https://air.build/hi/docs/app-store/match-players-for-multiplayer/

जब कोई player online गेम शुरू करता है, तो Game Center उसके लिए दूसरे players ढूँढता है। matchmaking rules से आप तय कर सकते हैं कि कौन किसके साथ खेले, जैसे वे players जिन्होंने एक ही mode चुना हो या जिनकी skill मिलती-जुलती हो। Apple का GameKit लेख setup समझाता है। rules एक rule set में रखे जाते हैं और rule set एक queue से जुड़ा होता है। match माँगते समय गेम उस queue का नाम देता है, और Game Center rules से सबसे अच्छे matches ढूँढता है। लेख यह real-time games के लिए बताता है, जिनमें players एक ही समय पर खेलते हैं। देखें [Finding players using matchmaking rules](https://developer.apple.com/documentation/gamekit/finding-players-using-matchmaking-rules)।

rules ज़रूरी नहीं हैं। backward compatibility पर Apple का लेख कहता है कि जो match requests किसी queue का नाम नहीं देतीं, वे एक default queue में जाती हैं, जिसे Apple classic matchmaking कहता है। rules की ज़रूरत तभी है जब आप तय करना चाहें कि कौन किसके साथ खेले।

> [!NOTE]
> AirBuild में Game Center की कोई screen नहीं है। आप प्रोजेक्ट की चैट में किसी एजेंट से कहते हैं, और वह `asc game-center matchmaking` इस्तेमाल करता है ([asc: ऐप और App Store लिस्टिंग](https://air.build/hi/docs/cli/asc-apps/#game-center) में `game-center` के नीचे दिया गया)। नतीजा देखने के लिए, एजेंट से पूछें।

## शुरू करने से पहले

- गेम का अपना code Game Center matchmaking इस्तेमाल करे। queue और उसके rules तब तक कुछ नहीं करते जब तक गेम उसे match requests न भेजे।
- गेम में Game Center चालू हो, App Store Connect record हो और आपका Apple Developer अकाउंट हो। देखें [Game Center leaderboards और achievements जोड़ें](https://air.build/hi/docs/app-store/add-game-center-leaderboards/)। free Apple ID से sign किए गए install में Game Center नहीं होता, इसलिए उसमें online खेल काम नहीं करेगा।

अगर आपके गेम में अभी online खेल नहीं है, तो पहले अपने एजेंट से उसे जोड़ने को कहें, जैसे:

```text
Add online races against up to 3 other players, using Game Center matchmaking to find them.
```

## बताएँ कि players कैसे मिलाए जाएँ

प्रोजेक्ट की चैट में बताएँ कि कितने लोग साथ खेलते हैं और क्या तय करता है कि कौन किसके साथ खेले, जैसे:

```text
Set up Game Center matchmaking for Fox Run: 2 to 4 players per race. Only match players who picked the same track, and put players with similar best scores together. If someone waits more than 20 seconds, allow a bigger score gap.
```

rules सिर्फ़ वही इस्तेमाल कर सकते हैं जो गेम हर match request के साथ भेजता है। ऐसी चीज़ें बताएँ जो गेम जानता है, जैसे player का चुना हुआ mode, track या level, या कोई score जो वह रखता है।

1. एजेंट `asc game-center matchmaking rule-sets create` से एक rule set बनाता है, जिसमें हर match के कम से कम और ज़्यादा से ज़्यादा players होते हैं।
2. आपने जो बताया, उसे वह `asc game-center matchmaking rules create` से rules में बदलता है। हर rule का एक प्रकार होता है, नीचे की table से, और एक expression जिसे Game Center match requests पर जाँचता है।
3. अगर players teams में खेलते हैं, तो वह `asc game-center matchmaking teams create` से teams जोड़ता है, हर एक के कम से कम और ज़्यादा से ज़्यादा players के साथ।
4. वह `asc game-center matchmaking queues create` से rule set के लिए queue बनाता है। गेम का code queue को उसके reference name से ढूँढता है।
5. वह काल्पनिक players से rules test करता है। नीचे "Rules test करें" देखें।
6. वह गेम का code बदलता है ताकि हर match request queue का नाम दे और वह भेजे जो rules जाँचते हैं, जैसे track और best score।
7. वह चैट में बताता है कि उसने क्या बनाया। इसे कभी भी फिर देखने के लिए, पूछें "गेम में कौन-सी matchmaking queues और rules हैं?"। एजेंट उन्हें `asc game-center matchmaking queues list` और `asc game-center matchmaking rules list` से पढ़ता है।

Apple queue और rule set के ऐसे नाम माँगता है जो आपके organization में unique हों, जैसे `com.example.mygame.GameSettingsQueue`। `asc` queues और rule sets पूरी Apple team के लिए दिखाता है, एक गेम के लिए नहीं, इसलिए गेम के नाम वाले नाम उन्हें अलग रखते हैं।

### Rules के प्रकार

Apple का [Matchmaking rules](https://developer.apple.com/documentation/gamekit/matchmaking-rules) लेख चार प्रकार बताता है। Game Center उन्हें इस क्रम में लागू करता है:

| प्रकार | यह क्या जाँचता है | Apple का उदाहरण |
| --- | --- | --- |
| `COMPATIBLE` | दो match requests साथ खेल सकती हैं या नहीं: हाँ या नहीं। | गेम का version 2.0 या उसके बाद का है। |
| `DISTANCE` | दो requests कितनी मिलती-जुलती हैं, 0.0 (सबसे ज़्यादा मिलती) से 1.0 (सबसे कम मिलती) तक। सबसे ज़्यादा मिलती-जुलती पहले साथ रखी जाती हैं। | players के बीच कम network delay। |
| `MATCH` | संभावित match की अनुमति है या नहीं: हाँ या नहीं। | 0 और 5 के बीच skill range। |
| `TEAM` | संभावित match की teams कोई शर्त पूरी करती हैं या नहीं: हाँ या नहीं। | teams के बीच कुल skill का अंतर 1 से कम। |

players जितना ज़्यादा इंतज़ार करें, rule को उतना ढीला करने के लिए एजेंट उसे ऐसे `MATCH` rule के रूप में लिखता है जिसकी value इस पर बदलती है कि request कितनी देर से इंतज़ार कर रही है। Apple का [Finding players using matchmaking rules](https://developer.apple.com/documentation/gamekit/finding-players-using-matchmaking-rules) बताता है कि कैसे।

### क्या तय करें

अगर आपकी कोई पसंद है, तो इन्हें अपने अनुरोध में बताएँ।

| विकल्प | यह क्या है |
| --- | --- |
| हर match में players | कम से कम और ज़्यादा से ज़्यादा। Apple का लेख कहता है कि Game Center पहले सबसे ज़्यादा players वाले matches ढूँढता है। |
| कौन किसके साथ खेले | एक match के players के लिए क्या एक जैसा, या क़रीब, होना चाहिए। |
| इंतज़ार | player जितना ज़्यादा इंतज़ार करे, rules ढीले होते हैं या नहीं, और कितनी देर बाद। |
| Teams | कितनी teams, और हर team में कम से कम और ज़्यादा से ज़्यादा players। |

## Rules test करें

players के rules इस्तेमाल करने से पहले, एजेंट से उन्हें आज़माने को कहें, जैसे:

```text
Test the matchmaking rules with six made-up players: four on the forest track with close scores, and two on the desert track.
```

एजेंट काल्पनिक match requests एक फ़ाइल में लिखता है और `asc game-center matchmaking rule-set-tests create --file` चलाता है। Apple का API reference कहता है कि rule set test, rule set को sample match requests पर लागू करता है। देखें [Test a Rule Set](https://developer.apple.com/documentation/appstoreconnectapi/post-v1-gamecentermatchmakingrulesettests)। जवाब दिखाता है कि कौन-सी requests साथ रखी गईं, और किस team में। एजेंट बताता है कि यह वैसा ही है या नहीं जैसा आपने बताया था।

असली match आज़माने के लिए:

1. अपने एजेंट से बदलाव वाला build upload करवाएँ। देखें [TestFlight से बीटा शेयर करें](https://air.build/hi/docs/app-store/test-with-testflight/#upload-a-new-build)।
2. उसे TestFlight से किसी ऐसे डिवाइस पर install करें जिस पर आपका गेम चलता है, जैसे iPhone, iPad या Mac, और इतने testers invite करें कि हर match के कम से कम players पूरे हो जाएँ। देखें [TestFlight से बीटा शेयर करें](https://air.build/hi/docs/app-store/test-with-testflight/#invite-testers)।
3. लगभग एक ही समय पर online खेल शुरू करें, हर कोई Game Center में sign in हो।

अगर players उस तरह साथ नहीं रखे जाते जैसी आपको उम्मीद थी, तो एजेंट को बताएँ कि किसने खेला, हर एक ने क्या चुना, और क्या हुआ।

## Ship करें

- queue, rule set और rules App Review में नहीं जाते। वे उन items में नहीं हैं जिन्हें `asc review items add` submission में डाल सकता है। Apple का लेख rules को Game Center server पर upload करने के बारे में बताता है।
- गेम का वह code जो इन्हें इस्तेमाल करता है, नए version के साथ players तक पहुँचता है। देखें [अपने ऐप का अपडेट ship करें](https://air.build/hi/docs/app-store/ship-an-update/)। अगर यह Game Center के साथ गेम का पहला अपडेट है, तो version में भी Game Center चालू होना चाहिए: देखें [Game Center leaderboards और achievements जोड़ें](https://air.build/hi/docs/app-store/add-game-center-leaderboards/#ship-them)।

## देखें matching कैसी चल रही है

उदाहरण के लिए पूछें:

```text
How many match requests found a match this week, and how many gave up or expired?
```

एजेंट `asc game-center matchmaking metrics queue-requests` इस्तेमाल करता है, जो queue की requests को नतीजे के हिसाब से गिनता है: `MATCHED`, `CANCELED` या `EXPIRED`। किसी एक rule के लिए, वह `asc game-center matchmaking metrics rule-errors` जैसे rule metrics ला सकता है। अगर बहुत सी requests expire होती हैं, तो आप एजेंट से rules ढीले करने को कह सकते हैं।

## Rules बदलें या हटाएँ

बताएँ कि क्या बदलना है। एजेंट इस्तेमाल करता है:

| इसके लिए | Command |
| --- | --- |
| हर match के कम से कम या ज़्यादा से ज़्यादा players बदलें | `asc game-center matchmaking rule-sets update` |
| कोई rule क्या जाँचता है, या उसका विवरण बदलें | `asc game-center matchmaking rules update` |
| कोई rule जोड़ें या हटाएँ | `asc game-center matchmaking rules create` या `delete` |
| किसी team में कितने players हैं, यह बदलें | `asc game-center matchmaking teams update` |
| queue के लिए दूसरा rule set इस्तेमाल करें | `asc game-center matchmaking queues update --rule-set-id` |

- `rules update` किसी rule का प्रकार नहीं बदल सकता। उसके लिए एजेंट rule मिटाकर नया बनाता है।
- `asc` किसी queue का नाम नहीं बदल सकता, और गेम का code queue का नाम इस्तेमाल करता है।
- जो rule कुछ नया जाँचता है, वह तभी काम करता है जब गेम उसे भेजे, जिसके लिए गेम का नया version चाहिए।
- queue, rule set, rule या team मिटाने के लिए `--confirm` चाहिए, इसलिए एजेंट पहले आपसे पूछता है। `asc` में मिटाई गई चीज़ वापस लाने का कोई command नहीं है।

## सवाल

**मैंने rules सेट किए, लेकिन players उनके हिसाब से नहीं मिलाए जाते।**

Game Center rules सिर्फ़ उन match requests के लिए इस्तेमाल करता है जो queue का नाम देती हैं। एजेंट से जाँचने को कहें कि गेम का code queue का नाम इस्तेमाल करता है और वह भेजता है जो rules जाँचते हैं, और पक्का करें कि सब उस code वाला build खेल रहे हैं।

**क्या गेम के अलग-अलग versions वाले players साथ खेल सकते हैं?**

Apple इसे multiplayer compatibility कहता है। आप इसे वेब पर App Store Connect में गेम के हर version के लिए सेट करते हैं: `asc` इसे दिखा सकता है (`asc game-center app-versions compatibility list`) लेकिन सेट नहीं कर सकता। Apple का [Add multiplayer compatibility](https://developer.apple.com/help/app-store-connect/configure-game-center/add-multiplayer-compatibility) देखें।

**मेरे गेम में पहले से बिना rules के online खेल था। क्या पुराने और नए versions आपस में खेल सकते हैं?**

Apple का लेख कहता है कि Game Center बिना rules वाले versions के players को queue का नाम देने वाले versions के players से नहीं मिलाता, जब तक queue classic matchmaking के लिए गेम की bundle ID न रखे। एजेंट से उसे `asc game-center matchmaking queues update --classic-bundle-ids` से जोड़ने को कहें। Apple का [Creating matchmaking rules for backward compatibility](https://developer.apple.com/documentation/gamekit/creating-matchmaking-rules-for-backward-compatibility) देखें।

**क्या मेरे दो games के players आपस में मिलाए जा सकते हैं?**

Apple का backward-compatibility लेख कहता है कि Game Center group, leaderboards और achievements के साथ, games के बीच matchmaking भी शेयर करता है। देखें [अपने गेम्स के बीच leaderboards और achievements शेयर करें](https://air.build/hi/docs/app-store/share-game-center-between-your-games/), और एजेंट को बताएँ कि कौन-से games आपस में खेलें।

**क्या यह पुराने iPhones पर काम करता है?**

Apple का GameKit reference वह setting, जिससे match request queue का नाम देती है ([queueName](https://developer.apple.com/documentation/gamekit/gkmatchrequest/queuename)), iOS और iPadOS 17.2 से बताता है। अपने एजेंट से पूछें कि पुराने versions वाले players के लिए गेम क्या करता है।
