Game modules

In order to create a new game for this platform, two tasks must be completed.

First, a module must be created for the game. This is a java class which performs server-side logic for the game: tracking the current game environment and validating player turns. Many of the requests common to all games (logging in, finding players etc.) are dealt with by the common server, so only a few implementations are required of the module.

Secondly, a game client must be created which observes the HTTP/REST API calls detailed here. This client should communicate with the server and should offer a more natural interface for playing the game.

The game module defines two JSON structures -- the events and the environment.

Java class

You must create a new java class which extends Game. There are four abstract methods which must be implemented. They are detailed here.

Environment

The environment is a JSON object which encodes all the information about the current state of the session. In chess, that would be all the pieces currently on the board, along with some extra information needed to implement the rules (such as whether or not a player has castled, whether or not a pawn completed a double-move on its last movement, an entire history of "repeatable" positions to detect draws). In noughts and crosses it's a little more simple, the environment would encode the mark currently in each cell.

The server should not inspect past events in order to deduce its logic. If a game needs information about its history, like chess, then that information must be encoded in its environment.

The environment is available via Session::getEnvironment.

Methods to implement in Java

getEnvironmentForPlayer

public abstract JsonObject getEnvironmentForPlayer(Session session, Player player);

The current environment of a session should contain all the information about a session, however, that may sometimes contain information which should be hidden to a player. In Wodka, for example, a player should only know about the cards in their hand, and the current sets in play.

When a client requests a session's environment, it will come via this method in order that any player-specific redaction may occur.

setupGame

public abstract Pair<JSONObject, List<Player>> setupGame(List<Player> players, JSONObject options);

When a session is created, this method will determine the initial environment.

The return value is a pair consisting of the initial environment, and a set of players whose turn it currently is.

doTurn

public abstract Pair<JsonObject, List<Player>> doTurn(Session session, Player player, JsonObject turn);

This is the real meat of the server-side logic. Whenever a player posts a turn, it goes through this method.

Guarantees going into this method:

You should return two values: the new environment of the session (if unchanged, you should just return the same environment again), and a list of players who will now be current.

There are two methods which you may need to call from this method: