by Lukas Akermann, October 2018
This is a Java server for the connect four challenge.
Download and extract the latest release.
Start the server inside a docker container:
docker-compose up
Start the server without docker:
java -jar connect-four-challenge-server.jar
Open http://localhost:8080 in your browser.
There are two profiles to alter the behaviour of the server:
-
default
Each game must be scheduled via the user interface.
The response to the player is delayed by 3 seconds after the game has ended.
-
train
The games are scheduled automatically.
Immediate response after the game has ended.
Use the train
profile with docker:
docker-compose -f docker-compose.train.yml up
Use the train
profile without docker:
java -Dspring.profiles.active=train -jar connect-four-challenge-server.jar
The whole communication ist REST based. For more details about REST have a look at the following documentation:
Endpoint | Description | Link |
---|---|---|
POST /api/v1/players/join |
Join a game and get a game id | Details |
GET /api/v1/players/games/{gameId} |
Get the current game state | Details |
POST /api/v1/players/games/{gameId} |
Drop a disc in a column and get the current game state | Details |
Join a scheduled game (you can't join multiple games at the same time).
HTTP POST to /api/v1/players/join
.
{
"playerId": "<Alice>"
}
value | description |
---|---|
playerId | unique player id |
No game scheduled:
{}
Scheduled game:
{
"gameId": "80dfa415-fbdf-451e-803e-0b9928bd6821"
}
Receive the state of a running or finished game.
HTTP GET to /api/v1/players/games/{gameId}
.
The current game state.
Drop a disc in a column.
HTTP POST to /api/v1/players/games/{gameId}
.
{
"playerId": "Alice",
"column": 1
}
value | description |
---|---|
playerId | unique player id |
column | column number, first column is column 1 |
The current game state.
{
"currentPlayerId": "Bob",
"players": [
{
"playerId": "Alice",
"disc": "RED"
},
{
"playerId": "Bob",
"disc": "YELLOW"
}
],
"board": [
["EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"],
["EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"],
["EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"],
["EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"],
["EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"],
["EMPTY","RED", "EMPTY","EMPTY","EMPTY","EMPTY","EMPTY"]
],
"finished": false
}
value | description |
---|---|
currentPlayerId | current player id |
players[0].playerId | first player id |
players[0].disc | first player disc color, RED or YELLOW |
players[1].playerId | second player id |
players[1].disc | second player disc color, RED or YELLOW |
board | list of cells, EMPTY, RED or YELLOW |
finished | true = game is finished, false = game is running |
winner | null = game is running or draw, player id = game winner |