Design Snake and Ladder (Low-Level Design)
Low-level design of Snake and Ladder: model snakes and ladders as a single Jump map (start to end), a parameterised Dice, players with positions, and a Game loop over a player queue with clean edge-case handling.
🟢 Low-Level Design · Case Study · Fresher-friendly → 🟠senior
"Design Snake & Ladder" is a friendly LLD warm-up — the rules are simple and everyone knows the game. The interview signal isn't the game logic (it's easy); it's whether you build a clean, extensible object model and handle the edge cases precisely. Let's design it well.
Step 1 — Requirements
- Functional: N×N board (say 100 cells); some cells have snakes (head → lower tail) or ladders (bottom → higher top); players roll a dice and move; landing on a snake/ladder jumps them; first to the last cell wins.
- Non-functional: configurable board size, dice count, and snake/ladder positions; support any number of players.
Step 2 — The classes
- Board — total cells + a map of Jumps (start → end); one map handles both snakes and ladders (ladder: end > start, snake: end < start).
- Dice — rolls 1..6 (parameterise count/faces so you can have 2 dice).
- Player — name + current position.
- Game — holds the board, dice, a queue of players, and runs the turn loop.
Step 3 — One insight: snakes and ladders are the same thing
🟠The neat modelling trick: don't make separate Snake and Ladder classes. Both are just a Jump from one cell to another — a ladder jumps up, a snake jumps down. Store them in a single Map<Integer,Integer> (start position → end position). After a move you do one lookup: if the landing cell is a jump start, teleport to its end.
int move(Player p, int roll) {
int dest = p.position + roll;
if (dest > board.size) return p.position; // must land exactly — overshoot = no move
dest = board.jumps.getOrDefault(dest, dest); // snake or ladder? one lookup
p.position = dest;
return dest;
}
Step 4 — The edge cases (where the marks are)
🔴 The logic is trivial; precision on edges is the signal:
- Overshoot rule: if a roll would take you past the final cell, you don't move (or bounce back, depending on the variant) — state your assumption.
- Exact finish: you win only by landing exactly on the last cell.
- Chained jumps: decide if a ladder can land you on a snake's head (usually resolve one jump only — say so).
- Roll-a-6 bonus turn: a common variant — mention whether you support it.
- Turn management: a queue of players rotates turns and extends to any number of players for free.
Step 5 — Keeping it extensible
🟠Parameterise the board size, dice count, and jump list (read from config) so the same engine plays a 10×10 or a custom board. Because snakes/ladders are just data in a map, adding or moving them needs zero code change. This "rules as data, engine stays fixed" idea is the same discipline you'd praise in the tic-tac-toe and chess designs.
The interview-ready walkthrough
"I model a Board as N cells plus a single Jump map (start → end) — snakes and ladders are the same thing, just up or down — so one lookup after each move handles both. A Dice (parameterised), Players with positions, and a Game that rotates a player queue and loops until someone lands exactly on the last cell. I'd be explicit about edge cases — overshoot, exact finish, chained jumps, roll-a-6 bonus — and keep board size / dice / jumps as config so the engine is fully reusable." Simple, correct, and extensible — exactly what this warm-up tests."
What to read next
- Design Tic-Tac-Toe · Design Chess — sibling board-game LLDs
- Design a Meeting Scheduler — next up
- OOD Basics — the responsibilities toolkit
- ← The complete System Design guide (hub)