Before you start
Snake and Ladder is a turn-management + rule-checking exercise. Small enough for one interview slot. Enough detail to reveal design choices around game state.
The interesting decisions
Turn order. How do you know who's next? Rotate an index, or store a next-player pointer? Both work; argue which fits.
When does the turn ADVANCE? After every roll (including no-move overshoots)? Only on successful moves? What about after a win? Standard rule: rotate after every roll except after a win.
Snake / ladder resolution. The
fromfield in the roll result: is it the position BEFORE the roll, or the head/bottom you landed on? The tests pinfrom= pre-move position (before the die was applied). Your design.md should say why — usually because callers want to see the full transition, not just the snake/ladder jump.Game-over state. One flag, or figure it out from the positions? An explicit flag is cheaper.
The pattern question
Is there a pattern from modules 1-3 that fits here? Think before answering:
- State? — Game has two states (playing, ended). One boolean is enough. State pattern for two states is overkill.
- Strategy? — Dice rolling? We take the value as input. Nothing to strategize.
- Command? — Rolls as first-class objects for replay? Neat but out of scope.
- Observer? — Notify a UI on turn change? Not needed for MVP.
If your answer is "no pattern fits, plain classes are right", say so and defend it. That's a valid, interview-quality answer.
The rules discipline
- No player past 100 (enforced by the "overshoot = no move" rule)
- All positions in 0..100 (follows from the rule above
- starting at 0)
- No mutation after winner (guard at the top of roll)
Each has a clear place to enforce it. Your design.md should name them.