Design Animal Chess Game Classes
Design and implement a minimal, correct engine for Animal Chess (also known as Jungle/Dou Shou Qi) using object-oriented principles. The engine should model the 9x7 board, including terrain like rivers, traps, and dens. Define the animal pieces (Elephant, Lion, Tiger, Leopard, Wolf, Dog, Cat, Rat) with their specific movement and capture rules. Expose a small API to initialize a game, place pieces, compute legal moves, make moves, and display the board state. Include test cases for board setup, a lion capture via a river jump, and a short multi-move sequence.
Make minimal, explicit assumptions if a rule is ambiguous.
Requirements:
- Pieces and Ranks: Define classes for Elephant(8), Lion(7), Tiger(6), Leopard(5), Wolf(4), Dog(3), Cat(2), Rat(1). Use inheritance and a common base class with owner, position, and rank.
- Board: A 9x7 grid with Land, Rivers (specific blocks), Dens (top at (0,3), bottom at (8,3)), and Traps (specific locations).
- Movement and Capture Rules:
- Orthogonal moves by one tile for most pieces.
- Lion/Tiger can jump across rivers if no rat blocks intervening river squares.
- Only Rat can enter river tiles.
- Den and Traps: Cannot enter own den; entering opponent's den wins. Being on opponent's trap reduces effective rank to 0 for capture.
- Capture: Attacker's effective rank >= defender's effective rank.
- Special Cases: Rat(1) captures Elephant(8) on land; Elephant cannot capture Rat. Rat in water cannot capture land piece, and vice-versa.
- API: Initialize/reset game, place piece (validate terrain), compute legal moves, make move (apply capture/win), display board state (ASCII).
- Tests: Board setup, lion river-jump capture, short multi-move sequence exercising river movement and blocking.
AI interview prep
Core dilemma
Balancing the complexity of representing diverse piece movement/capture rules and board terrain within a clean, extensible object-oriented structure, while ensuring correctness and testability for a niche game.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design Animal Chess Game Classes
Design and implement a minimal, correct engine for Animal Chess (also known as Jungle/Dou Shou Qi) using object-oriented principles. The engine should model the 9x7 board, including terrain like rivers, traps, and dens. Define the animal pieces (Elephant, Lion, Tiger, Leopard, Wolf, Dog, Cat, Rat) with their specific movement and capture rules. Expose a small API to initialize a game, place pieces, compute legal moves, make moves, and display the board state. Include test cases for board setup, a lion capture via a river jump, and a short multi-move sequence.
Make minimal, explicit assumptions if a rule is ambiguous.
Requirements:
- Pieces and Ranks: Define classes for Elephant(8), Lion(7), Tiger(6), Leopard(5), Wolf(4), Dog(3), Cat(2), Rat(1). Use inheritance and a common base class with owner, position, and rank.
- Board: A 9x7 grid with Land, Rivers (specific blocks), Dens (top at (0,3), bottom at (8,3)), and Traps (specific locations).
- Movement and Capture Rules:
- Orthogonal moves by one tile for most pieces.
- Lion/Tiger can jump across rivers if no rat blocks intervening river squares.
- Only Rat can enter river tiles.
- Den and Traps: Cannot enter own den; entering opponent's den wins. Being on opponent's trap reduces effective rank to 0 for capture.
- Capture: Attacker's effective rank >= defender's effective rank.
- Special Cases: Rat(1) captures Elephant(8) on land; Elephant cannot capture Rat. Rat in water cannot capture land piece, and vice-versa.
- API: Initialize/reset game, place piece (validate terrain), compute legal moves, make move (apply capture/win), display board state (ASCII).
- Tests: Board setup, lion river-jump capture, short multi-move sequence exercising river movement and blocking.