Design a Board Game Framework
🎲 What is a board game framework? It is the shared engine behind a games site. It seats players at a table, checks that the right person is moving, rejects illegal moves, notices when someone has won, and records every move. Each game only brings its own rules: how a token moves in Ludo, what a skip card does in Uno.
Single games like tic-tac-toe test whether you can model one set of rules. This prompt tests something else: can you find the line between what every game shares and what each game owns, and draw it so a new game is one new class? Interviewers ask it in several forms: "design Ludo", "design Uno", "design a game arena where people play in rooms and can watch replays". They are the same design. Ludo and Uno are the two games we plug in, and the arena with rooms and replays is the layer that hosts them. We build all three, and the practice tests run both games through the same arena.
Requirements
"Design a framework for turn-based games. We want to launch Ludo and Uno first, and more games later. People play online in rooms, and they can replay a finished game move by move."
The word to focus on is "framework". The interviewer is not asking for the best Ludo; they want to see where the rules of a game end and the machinery around it starts.
Clarifying Questions
You: Which rules do Ludo and Uno need? The full rule books are long.
Interviewer: Simplified versions. Ludo: each player has two tokens, you need a six to bring a token onto the board, landing on someone sends them home, a six gives another turn, and you must land exactly on the finish. Uno: number cards plus skip, reverse and draw two. No wild cards.
You: Does every game take turns in seat order?
Interviewer: No. In Ludo a six lets you go again, and in Uno a skip or a reverse changes who is next.
You: Dice and shuffled decks are random. How do we test that?
Interviewer: Pass the random part in when the room is created: the dice rolls for Ludo, the deck order for Uno. In production a random source fills it.
You: How does a room start? Do players join one by one?
Interviewer: For now a room is created with all of its players and starts right away. A lobby comes later.
You: What should a replay show?
Interviewer: The table as it looked after any number of moves: the token positions, or the top card and how many cards each player holds.
You: What happens with an illegal move, or a move from the wrong player?
Interviewer: Reject it and change nothing. The player tries again.
You: Many rooms at once, many requests at once?
Interviewer: Many rooms, but assume one request at a time for now.
The second question is the one that shapes the design. If you assume "next player is the next seat", you will put that line in the framework, and both launch games will break it on day one.
💡 Interview tip: In a framework question, ask what differs between the first two use cases before you design anything. Every difference is a decision the framework must hand to the plug-in. Here: who moves next, what a legal move is, what the table looks like, and when the game ends.
Final Requirements
- The arena hosts many rooms. A room has an id, a game, 2 to 4 players in seat order, and a setup list (the dice rolls or the deck order).
- In a room, only the player whose turn it is may move. An illegal move, a move out of turn or a move after the game ended is rejected and changes nothing.
- Each game decides what a legal move is, what it does, who moves next, what the table shows and who has won.
- Ludo: two tokens per player, all at home at the start. The shared track is a ring of 24 squares, and seat
ienters at square6 * i. A home token needs a six to enter. A token on the track moves forward by the roll and must land exactly on the finish (24 steps after its start). Landing on a square with other players' tokens sends them home. A six gives another turn. If no token can use the roll, the turn passes by itself. The first player with both tokens finished wins. - Uno: five cards each, dealt one at a time; the next card starts the discard pile. A card is a color (
R,G,B,Y) and a symbol (0-9,Sskip,Rreverse,Ddraw two). A player plays a card that matches the top card's color or symbol, or draws one card, which ends the turn. Skip jumps the next player, reverse flips the direction, draw two makes the next player draw two cards and lose their turn. A player who plays their last card wins at once. - Anyone can see whose turn it is, the winner, and the current table.
- A room can show the table as it was after any number of its moves (a replay).
- Adding a game must not change the arena or the rooms.
Out of scope
- Lobbies, matchmaking and players joining one at a time (Extensibility covers the lobby).
- Chat, ratings, and accounts.
- Wild cards, Ludo safe squares and the other rules we left out.
- Several requests at once (Extensibility).