PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/Duolingo

Design Animal Chess game classes

Last updated: Mar 29, 2026

Quick Overview

This question evaluates object-oriented design, domain modeling, rule-based game logic, and stateful API design by requiring a piece class hierarchy, a 9×7 board representation with terrain effects, move-generation and capture rules, and test scenarios.

  • hard
  • Duolingo
  • System Design
  • Software Engineer

Design Animal Chess game classes

Company: Duolingo

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

##### 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 question evaluates object-oriented design, domain modeling, rule-based game logic, and stateful API design by requiring a piece class hierarchy, a 9×7 board representation with terrain effects, move-generation and capture rules, and test scenarios.

Duolingo logo
Duolingo
Aug 4, 2025, 10:55 AM
Software Engineer
Technical Screen
System Design
3
0

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

  1. 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.
  2. 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).
  3. 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).
  4. 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.
  5. 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.

Solution

Show

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Duolingo•More Software Engineer•Duolingo Software Engineer•Duolingo System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.