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.
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
-
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.