This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Design Animal Chess game classes states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
##### Question
Design a simple Animal Chess game using object-oriented principles. Define piece classes (Elephant, Lion, Tiger, Leopard, Wolf, Dog, Cat, Rat) with their unique movements; model a 9×7 board with rivers, traps and dens; implement movement and capture logic; create an API to initialize, place pieces and display state; and supply test cases showing board setup, a lion capture, and a multi-move turn.
Quick Answer: This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Design Animal Chess game classes states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Design a Simple Animal Chess (Jungle/Dou Shou Qi) Engine
Context
You are to design and implement a minimal-but-correct engine for Animal Chess (also known as Jungle/Dou Shou Qi) using object-oriented principles. The engine should model the 9×7 board (with rivers, traps, and dens), define the animal pieces (Elephant, Lion, Tiger, Leopard, Wolf, Dog, Cat, Rat) with their movement and capture rules, and expose a small API to initialize a game, place pieces, compute moves, make moves, and display state. Include test cases that exercise board setup, a lion capture via a river jump, and a short multi-move sequence.
Make minimal, explicit assumptions if a rule is ambiguous.
Use inheritance and a common base class with owner, position, and rank.
Board
9 rows × 7 columns grid.
Terrain tiles:
Land
Rivers: two 3×2 blocks at rows 3–5 and columns 1–2 (left river), and columns 4–5 (right river) using 0-based indices.
Dens: top den at (0,3), bottom den at (8,3).
Traps: top traps at (0,2), (1,3), (0,4); bottom traps at (8,2), (7,3), (8,4).
Movement and Capture Rules
Orthogonal moves by one tile for all pieces except Lion/Tiger can jump across river along rank/file to the first non-river square if no rat blocks any intervening river square.
Only the Rat may enter river tiles.
Den and traps:
A player cannot enter their own den; entering the opponent’s den is a win.
Being on the opponent’s trap reduces a piece’s effective rank to 0 for capture comparisons.
Capture rules:
Normally, a piece can capture an enemy piece on its destination square if the attacker’s effective rank ≥ defender’s effective rank.
Special cases:
Rat(1) can capture Elephant(8) when the rat is on land. Elephant cannot capture Rat anywhere.
A rat in water cannot capture a piece on land; a piece on land cannot capture a rat in water (only a rat in the same water can capture that rat).
API
Initialize/reset game and board.
Place a piece on the board (validating terrain constraints, e.g., non-rats cannot be placed into rivers).
Compute legal moves for a piece.
Make a move (apply capture and win conditions).
Display the board state as ASCII.
Tests
Board setup demonstration (place multiple pieces and render).
A lion river-jump capture.
A short multi-move sequence of alternating turns (at least three moves) that exercises river movement and blocking.
Clarifying Questions to Ask Guidance
Clarify users, core use cases, read/write patterns, scale, latency, availability, and data retention.
State explicit assumptions before making sizing or architecture decisions.
Prioritize the functional path first, then address reliability, security, observability, and rollout.
What a Strong Answer Covers Guidance
A scoped requirements summary with concrete non-goals and success metrics.
API, data model, architecture, consistency, capacity, and operations.
Reasoned trade-offs among simple and scalable designs, including bottlenecks and failure modes.
A validation, monitoring, migration, and launch plan appropriate for the risk level.
Follow-up Questions Guidance
What breaks first at 10x traffic or data volume?
How would you degrade gracefully during dependency failures?
What metrics and alerts would prove the design is healthy after launch?