To run and make changes to this game, read CONTRIBUTING.md
.
Stones is a simple turn-based game with a 2D board of n by m
tiles. Each player starts on the board with k
stones. During his turn, the player can move one of his stones to an adjacent tile if it is free, or taken by an enemy stone. If it is occupied by an enemy stone, this stone is removed from the board. The last player standing wins.
Each player is controlled by a logical processor. This processor receives information about the state of the board and the moves of each other player. Based on this information the processor computes its next step.
The game state is modelled by an n by m
nested array filled with an integer. -1
represents an empty tile, 0, 1, 2, 3, ..
represent players 0, 1, 2 or 3 respectively.
The game play is modelled by a number of messages of different types:
- The
GameStart [board]
message indicates the game is started with some initial state (k
tiles for each of player in certain positions). - The
TurnTo [playerId]
message indicates a player with a given id has the turn. - The
Move [playerId] [p0] [p1]
indicates a player moves a stone from positionp0
top1
. - The
Hit [playerId] [p0]
indicates a player loses a stone at pointp0
. - The
PlayerLost [playerId]
indicates a player has lost all his stones. - The
PlayerWon [playerId]
indicates a player is the only one left, thus wins.
Each player's logical unit is contained in a class that implements a PlayerInterface
. This interface has three methods:
- The
initialize(chat)
method is called at the start and provides the player with a chatbox where he can send messages to, as a way of logging. - The
update(message, newGameState)
method takes any message of the above types and a new state object that can be used for reasoning. Within this method the player can update his own state for example to determine a strategy. - The
getNextMove()
method asks the Player object for its next move. AMove
message should be returned, which is then sent to all players (including this player).
The game flows through the following steps:
- Create an instance (
new PlayerX()
) of the selected players for this game and callinitialize
on them. - Create a board with some stones for each player.
- Call
player.update
withGameStart
to each player (starting from player 1) with the created board. - For each turn (starting at player 1), we call the player
p
:- Send
TurnTo p
to all players in order. - Call
player.getNextMove()
on playerp
, thereby receiving a move fromp0
top1
- Verify the move and crash the game if invalid.
- If player
x
's stone is atp1
sendHit x p1
to all players. - Check if player
x
has any stone left, if not sendPlayerLost x
. - Send
Move p p0 p1
to all players. - If player
x
has lost check ifp
is the only player left. If so, sendPlayerWon p
and end the game. - Otherwise, continue the turn for the next player.
- Send