Game Services | Turn-Based Multiplayer: Introduction

IMPORTANT: as of March 31, 2020 Google has discontinued the Play Games Services multiplayer APIs. Therefore the Turn-Based Multiplayer feature is now only available on iOS Game Center platform.

In a turn-based multiplayer match, the players take turn asynchronously, meaning they don't need to be simultaneously connected to the match to play it together. Instead, the game uses a store-and-forward approach; one player takes a turn before passing the next play to another player. The players continue to take turns until the match ends with only one player able to make changes to the game at a time.

Turn-based matches have many useful characteristics that make them great for implementing board games and other similar styles of games; for example:

  • Players don't need to be playing the game at the same time to be matched and play together, which makes it easier for a player to find opponents for a turn-based match.

  • A player can participate in multiple matches simultaneously. A game loads whichever match the player is interested in viewing or advancing.

  • A match can be created with less than a full complement of players, even a single player. Other players are added as needed.

When you implement turn-based matches in your game, the list of players, the data for matches, and other details are all stored on the underlying platform, which is Game Center (iOS) or Google Play Games (Android). These platforms primarily responsible for storing data. You are responsible for providing the game logic that uses this infrastructure. In particular, you define:

  • What data must be stored

  • When the match data needs to be updated (by a player taking turn)

  • When play passes to another player

Game Center and Google Play Games offer all the necessary networking and notification infrastructure for turn-based multiplayer games, for free. These platforms expose very different sets of API for accessing their multiplayer infrastructures. Easy Mobile unified these APIs, solve their discrepancies and provide you a common API that works consistently across the two platforms so you only need to write your multiplayer code once for both platforms.

The table below summarizes the specifications of the Turn-Based multiplayer services offered by Game Center and Google Play Games.

Spec Game Center Google Play Games
Min players per match 2 2
Max players per match 16 8
Max match data size 64 KB 128 KB
Seats Filling Invitation or automatch Invitation or automatch
Turn Order Developer defined Developer defined
Invitation Form Messages (iMessage app) Notifications

Turn-Based Multiplayer Game Basics

Turn-Based Match

A turn-based match is a gaming session with multiple participants who take consecutive turns to update the game data during the match. A matches is initiated by a player and then other players join via invitations or auto-matching.

A turn-based multiplayer match contains these key properties:

  • Participants. A user can become a participant in a turn-based match by initiating a match, joining a match by accepting an invitation, or being auto-matched into a game.

  • Match data. Game-specific data for this match. As a match progresses, the current player can modify and store the game data on Game Center or Google Play Games servers, which is called taking turn. The other participants can then retrieve and update this data on their turn. The game data is stored on the servers as a binary blob (byte array) and its size must not exceed the limit imposed by the underlying platform. Your game is responsible for interpreting the meaning of this data.

  • Match state. A match can fall into one of multiple states (see table below), depending on participant and game actions during the match. The state of a match is managed by Game Center and Google Play Games services. Your game can check the match state to determine whether a match can proceed, whether players can join by auto-match, and if the match is over (and if it completed normally or ended because of some user action).

Participants

The participants in a turn-based match can fall into one of these categories:

  • Initiating player: an initiating player who starts a turn-based match can invite other players to join the match, or request to be auto-matched to random users. The initiating player can also request a mix of the two (for example, invite a specific friend, and get two auto-matched players).

  • Auto-matched players: auto-matched players do not need to be socially connected to the other players. Auto-matched players do not receive notifications to join a match; from their perspective, it appears as though they are individually initiating the match.

  • Invited players: users who are invited to a match will receive invitation messages/notifications on their device. Once a user accepts a match invitation, that user is joined to the match as a participant.

On Google Play Games platform, auto-matched participants will appear as anonymous players to each other (even if they are known to each other).

A participant in a turn-based match has a status. You should check this status and update your game UI accordingly, as well as you should check it when specifying the player to take the next turn or determining the match outcome. The following table lists the possible statuses of a participant:

Status Description
NotInvitedYet [Google Play Games only] The participant has not yet been sent an invitation (which will be sent upon the invitee's first turn).
Matching [Game Center only] The participant represents an unfilled position in the match that Game Center promises to fill when needed (when the participant's first turn comes).
Invited The participant has been sent an invitation to join the match.
Declined The participant declined the invitation to join the match. When a participant declines an invitation to join a match, the match is automatically terminated.
Joined The participant has joined the match.
Unresponsive [Google Play Games] The participant did not respond to the match in the allotted time.
Left [Google Play Games] The participant previously joined and now left the match.
Done The participant has exited the match. Your game should set a match outcome for this participant.
Unknown The participant is in an unexpected state.

Match Data

Match data is stored as a binary blob (byte array), and your game is responsible for encoding and interpreting the meaning of this data. This data is typically updated when a player takes turn, such that it reflects the updated match progress. When a match is first created the match data is empty (null) and it should be initialized to something meaningful to your game when the first player takes turn.

The maximum match data size allowed on Game Center and Google Play Games platforms is 64 KB and 128 KB, respectively.

Since the data size is limited, you need to be creative and encode your game’s data so that it fills as little space as possible. In general, the match data needs to store enough information so that your game can display the current state of the match. If the player is the current player, then the match data should also store enough data so that your game knows what kind of turn the player may take. Read about some strategies suggested by the Game Center Programming Guide.

Match State

The following table lists the possible states of a turn-based match:

Match State Description
Active Indicates that the match is being played and your game can letmatch participants take their turns.
Matching This state indicates that there are still empty auto-match slots available and your game is waiting for an auto-matched player to join. Your game cannot let other match participants take turns while the match is in this state.
Ended Indicates that a match has been played to completion (for example, a player has won the match). Once a player signals that the game is finished, a notification is sent to all match participants to inform them that the match is over. Players have a chance to save their final game data but may not modify the game state further.
Cancelled [Google Play Games only] Indicates that a match ended before its normal completion. This might occur, for example, if a user who was invited to the match declined the invitation.
Expired [Google Play Games only] Indicates that a match has expired. A match expires when a user does not respond to an invitation or turn notification for two weeks. A match also expires in one day if there is an empty auto-match slot available but Google Play games services cannot find a user to auto-match.
Deleted [Google Play Games only] The match was deleted.
Unknown The match status is unknown.

Match Initialization

Matchmaker UI vs Programmatic Matchmaking

The turn-based multiplayer API provides a built-in matchmaker UI in which the initiating player can invite their friends or select a number of auto-match opponents into a match. It's also possible to create a turn-based match programmatically without any UI with all opponents being auto-matched (aka create quick match).

Specifying Number of Players

When initiating a turn-based multiplayer match, you must specify the number of players that you want to allow in your match. These players can join via invitations or auto-matching.

The maximum number of players that can join a turn-based match on Game Center and Google Play Games platforms is 16 and 8, respectively. The minimum number of players is 2. Note that these numbers include the player who is initiating the match.

Variant

Optionally, you might want to ensure that only players who are interested in a specific type of game variant are auto-matched to the turn-based match. For example, in a board game, you can auto-match players who only want to play a match that requires a specific skill level. If there are different versions of your app, you can also use variants to ensure that only players who are on compatible versions are auto-matched.

Exclusive BitMask

If your game has various roles and you want to auto-match players who are interested in playing specific exclusive roles in a game, you can specify this using an exclusiveBitMask while setting up the match.

Turn-Taking

The basic flow for turn-taking is as follows:

  1. If the local player initiated a match, check to see if the game data is null. If so, the client should initialize this data as needed by your game. For example, you might need to initialize the starting positions for players in a strategy game or initialize the first hand for players in a card game.

  2. Let the current player perform their normal turn, which normally means updating the match data.

  3. Update the match by calling the TakeTurn() method, passing the following data:

    • The updated data the match, after the current player performs the turn.
    • The player to take the next turn.
  4. Repeat steps 2-3 until the match is completed, or until the game ends some other way.

Specifying the order of play

The order of play is determined by the design of your game. The turn-based multiplayer API provided by Easy Mobile allows your game to flexibly specify the order of play during a match.

When updating the match, your game can assign one of these players to take the next turn:

  • The current player who just took a turn.

  • Another player who has already joined the match (by invited or auto-matched).

  • An invited or auto-match player who has not joined the match; in this case, the match is suspended until a player joins and takes turn.

For example, in a 2-player turn-based match, your game might randomly pick one player to take the first turn, then subsequently switch to the other player for the next turn, and so on.

Turn-Based Match Events

A player involved in a turn-based match receives notifications for following types of events:

  • Match invitation: players receive a message via the iMessage app (Game Center) or a notification (Google Play Games) when they have been invited to join a match and are assigned to play their first turn by the game.

  • Turn event: players receive this notification when they have already joined the match and the game assigns them to be the next player to take turn.

  • Match events: players that are joined to the same match receive these notifications whenever a match event occurs (for example, when a match is ended).

Demo Scenes

Our multiplayer API demo scenes are located at folder Assets/EasyMobile/Demo/Scenes/Modules and include 5 scenes:

  • GameServicesDemo_Multiplayer: the entry point for other multiplayer demo scenes.
  • GameServicesDemo_Multiplayer_RacingGame: a 2-player car racing game demonstrating the Real-Time multiplayer API.
  • GameServicesDemo_Multiplayer_RealTimeKitchenSink: a kitchen sink demo for the Real-Time multiplayer API.
  • GameServicesDemo_Multiplayer_TicTacToe: a 2-player Tic Tac Toe game demonstrating the Turn-Based multiplayer API.
  • GameServicesDemo_Multiplayer_TurnBasedKitchenSink: a kitchen sink demo for the Turn-Based multiplayer API.

If you're trying our multiplayer API using the demo app, build these 5 scenes only so that the necessary delegates can be registered and run properly.

results matching ""

    No results matching ""