You are on page 1of 4

Promignis Technologies

contact@ignisletter.com

Tic Tac Toe over Websocket


OVERVIEW
Create a command-line based game of tic tac toe that can be played by two people over a
websocket connection. The technology used has to be Typescript.

DETAILS
1. The project will have 2 parts.
a. Server: It will receive & manage websocket connections and persist & update the
game state.
b. Client: It will connect to the server and will send the server commands to update
the game state.
2. The client will be called with two arguments, server address and unique name.
For example
node client.js -address 127.0.0.1:80 -name john_doe
3. If the name provided is not unique, and a connection with the same name already exists
on the server, the server should return a proper error message and close the connection.
4. If a successful connection is established, the server should ask the client to choose
between 3 options
a. Create a new game: If this is selected by the user then a new game is created and
the user is given the role of player 1. Server should associate a unique identifier
(uuid) with every game. The game can not start until player 2 joins so the user will
need to wait for another user to join.
Keep a limit of maximum 10 active games. If there are 10 games going on already,
the server should not create another new game. It should return an error message
and close the connection.
b. Join as player 2 in an existing game: If this option is selected, the server should
return the uuids of all existing games that are waiting for a player 2 to join. The
user can then send a uuid back to the server and the server should add the user
as player 2 to the associated game. If there are no games that are waiting for a
player 2, then take the user back to option selection state, so that the user can
choose option a or option c.
c. Be a spectator: If this option is selected, the server should return the uuids of all
existing games where both players have already joined. Once the user becomes a
spectator, the user will receive the updates about the game after every move that
the players make. A spectator can not do anything else.
5. Once a game has been created and player 2 joins the game, both users can start playing.
Player 1 plays the first move. It can pass a number between 1 and 9. Based on that input,
the game state is updated, and this update should be sent to player 2 and all the
spectators. Similarly, player 2 can play their move after player 1 and so on.
Note:
Assume that these numbers are arranged in a 3x3 grid this way:
1 23
456
789
You are free to decide how the game board will be rendered in the console. Any kind of
grid that can represent a tic tac toe board is fine.
6. Once a game is finished:
a. Send appropriate messages like “You won”, “You lost” or “It’s a draw” to the
appropriate player.
b. Send appropriate messages like “<player_name> won/lost” or “it’s a draw” to the
spectators.
c. Once all the messages have been sent, close the connection and remove the
game from the server.
7. Gracefully handle the situation where either player 1 or player 2 randomly disconnects. In
this case, send a proper message to the other player and spectators, close the
connection and remove the game from the server.
8. It will be a plus if the websocket connection is over TLS.
9. It will be a plus if the server can be put in a docker container, so that it can run on a
machine with no dependencies like node or npm installed.

REFERENCE SCREENS
Please refer to the below screens on how we expect the game to work. You don’t have to match
this user experience exactly, use them as guidelines.
User connects to the server

Player 1 and Player 2 playing the game


User watching the game as a spectator

SUBMISSION
Please commit all your code in a Public Github repository and share the link with us. If you have
further questions regarding the project requirements, feel free to contact us.

You might also like