Knowledgebase
OpenFeint 2.5 - Turn-Based Multiplayer Implementation Guide
OpenFeint Turn-Based Multiplayer Game Implementation Guide
The OpenFeint Turn-Based Multiplayer System is designed to make multiplayer game making easier.
- Use OpenFeint's server expertise, instead of having to administrate your own
- Simple event-driven interface for move receipt
- Multislot lobby allows the player to be in several games at once
- Matchmaking
- Push notifications keep the player involved even when offline
- Handles issue of player dropouts
- A game can consist of up to 65535 moves.
- A move can contain up to 16K of data that can contain any information you wish
- At the moment, only 2 player games are supported, future plans will increase that number
- In order to make use of the offline capabilities, the game engine must be written to be completely deterministic. The configuration, creation options, a random seed and a list of moves must be sufficient to allow the current game state to be built. A random seed will be generated by the server when a game is created, either use that with the built-in random number generator (a simple Linear Congruential) or use it to seed your own. When a player returns to a given game, the moves will be returned in server order.
Anomaly -a special move type that is requested by a player other than the current player. Used to handle player drop-outs mostly. Anomalies require a reason that the server should accept them.
Game - an interaction between different players with a state defined by an initial state consisting of a configuration string, game options and a generated seed and a series of moves.
Lobby - a list of slots that contains current game information. This allows the player to be offline in several games at once, if that is desired.
Move - a change of state requested by a client. Moves can contain arbitrary data, signal end of turn, end of game, or a player's resignation. Moves can be generated by a player if the current game state allows them to enter moves or you can request the server enter a move using anomalies.
Slot - represents a single potential or actual game to the lobby.
Type of games
The system can support several different types of multiplayer game
1) Sequential turn - Example Chess. In this version, only one player is making moves at any given time and only one player is allowed to make moves at any time. This is the easiest to program as the order of moves is strictly determined.
2) Simultaneous Turn - Gated. Example Roshambo (rock-paper-scissors). In this game mode, the players are allowed to make moves at the same time, when all players have made moves the game state is updated.. This requires some work on the part of the game logic so that move order does not affect the game state and no one is allowed to make more moves than is valid. For Battleship, each player is allowed to make all the moves in their salvo. The game logic does not allow the player to shoot more times than allowed by salvo, and since the player shots are all evaulated at once, there isn't a problem where turn order is a difficultly.
3) Simultaneous Turn - Interruptable. Example Magic: The Gathering. In this version, the players can actually affect each other's play. This is by far the hardest type to program, because interactions between the player moves can be difficult to reconcile. For instance, suppose a game allows you to attack a piece in range. You make that move, on your client it appears you are attacking the piece. Unfortunately, the other player is online and has moved out of range. Thus on their machine, it does not register as a strike. To help avoid this, you can specify that a move is given with delay. This move should not be applied to the game state until the server echoes it back as a regular move. That way, it will be in the order sent to all the clients. For the shot, when the player triggers the shot, nothing happens until the server returns a message at which point the logic can determine if there's a hit. The other client will have to display the shot attempt at the time of receipt, so there will be a slight visual difference.
It may be tempting to try to create a pseudo-realtime game using this system, but that is not recommended. It's recommended for things like in head-to-head games where achieving a certain result causes an effect on the opponent (like clearing blocks in Tetris hurting the opponent)
4) Free-for-all. Example Super Puzzle Fighter. The game state is not completely controlled by the server. In this game type, the offline capabilities cannot be used. The game moves instead are used to send snapshots of the current state back and forth. There is no direct interaction between the players, although sending a move can send a message that affects that player's state. In this case, the victory goes to the first player who claims it. To do something like Super Puzzle Fighter, when an attack is made, that move will trigger the cascade when it is received. The system can also send updates back and forth.
Samples
The samples are shipped as folders with the specific classes for that sample. These must be added to a standard OpenFeint project of at least version 2.4.7. The OpenFeintMultiplayer folder should also exist at the top level. The application Key and Secret can be found by registering at the regular OpenFeint developer site. http://www.openfeint.com/developers.
Battleship
The Battleship GameManager can be used as an example of writing a multiplayer engine. It can be considered a Controller, with the internal GameGrid containing the Model. The work of changing the user input into moves is handled in the BattleShipGameViewController. These moves are send to the GameManager along with moves received from the network. The manager handles the question of what is a valid move in the current state and tests for game completion.
MPSampleApp
This sample shows the use of several of the more advanced systems. From a multiple slot lobby, you can enter up to 6 games at once. When a slot is selected, you can enter that game, make some moves (press U,D,L,R). In addition, this sample shows how to challenge a friend, allow rematches, and handle push notifications. Moves to the right are sent using the move with delay. Note that this is an older sample and reflects an earlier version of the API, but it remains here to show those particular features.

