Connect-4¶
Rules¶
- Join with
lobby.subscribeand{"game": "connect4"}. - 3 to 9 players. Everyone plays against everyone.
- More players = bigger board: width = players + 4, height = players + 3.
- Get 4 in a row (any direction) to win.
- Turns go around in the order players joined.
- A move is one number: the column. The server works out the row (
<row>). - Row
0is the bottom row. The first piece in a column lands on row0. - Result:
WIN,LOSSorDRAW. - A player who gives up, runs out of time or doesn't come back gets
LOSSand is skipped. The others keep playing. - The server does not send the board. Keep track of it using
moveandrowingame.actionevents.
<width> × <height>:
| Players | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|
| Board | 7×6 | 8×7 | 9×8 | 10×9 | 11×10 | 12×11 | 13×12 |
Actions¶
Send these with game.action. Put the type in the data.
type |
You send | Everyone gets EVT game.action with |
|---|---|---|
move |
move: the column, 0 to <width> - 1 |
player, move, row: the row the piece landed on |
Connect-4 has no game.update types.
The lobby¶
lobby.subscribeputs you in a waiting room (lobby), not in a match.- Send
lobby.readywhen you are ready. - Each time someone joins or gets ready, everyone gets
lobby.update. - Everyone ready and at least 3 players? A 10 second countdown starts (
lobby.countdown). - Someone new joins during the countdown? The countdown stops. Everyone else stays ready.
- Countdown ends? The match starts with everyone in the lobby.
- Lobby has 9 players? New players get
ERR LOBBY_FULL.
Step by step¶
Steps 1 to 4 are saying hello and logging in. For <id1>, <m> and the other placeholders, put in the real value.
| # | Who | Line |
|---|---|---|
| 1 | you | REQ <id1> session.hello {"version": 1} |
| 2 | server | RES <id1> OK |
| 3 | you | REQ <id2> session.login {"player": "<name>"} |
| 4 | server | RES <id2> OK {"session_token": "<session_token>"} (save the session token to reconnect) |
| 5 | you | REQ <id3> lobby.subscribe {"game": "connect4"} |
| 6 | server | RES <id3> OK |
| 7 | server | EVT lobby.update {"players": ["<name>"], "ready": [], "min": 3, "max": 9} |
| 8 | you | REQ <id4> lobby.ready |
| 9 | server | RES <id4> OK |
| 10 | server | EVT lobby.countdown {"seconds": 10} |
| 11 | server | EVT <m> game.match_started {"participants": ["<name>", "<other1>", "<other2>", ...], "to_move": "<name>", "width": <width>, "height": <height>} |
| 12 | server | EVT <m> game.your_turn |
| 13 | you | REQ <id5> <m> game.action {"type": "move", "move": <move>} |
| 14 | server | RES <id5> OK |
| 15 | server | EVT <m> game.action {"type": "move", "player": "<name>", "move": <move>, "row": <row>} |
| 16 | server | EVT <m> game.your_turn (to the next player) |
| repeat 13-16 | ||
| 17 | server | EVT <m> game.result {"result": "WIN", "reason": "normal"} (everyone else gets LOSS, see match results) |
Errors¶
What each code means: Errors.
UNKNOWN_ACTION: notype, or atypethat is not in ActionsINVALID_MOVE: the column is full or doesn't existNOT_YOUR_TURNLOBBY_FULL