Start by clarifying the rules and scope, then outline a class design that separates concerns (Board, Cell, Piece hierarchy, Game). Walk through the core logic for movement, capture, and win conditions, and finish with a brief test plan covering initialization, a capture, and a multi-move turn.
Pro tip: Emphasize extensibility and testability: use dependency injection for the board and pieces, and write tests that simulate full turns to catch edge cases like illegal moves and win detection.
Ask about board size, piece types, movement rules, and win conditions to ensure alignment. Confirm whether the API should support undo or only forward moves.
Define classes: Board (9x7 grid of Cells), Cell (type: land, water, trap, den), Piece (abstract with rank, position, and move validation), and Game (turn management, win detection). Use inheritance for piece types (e.g., Elephant, Lion).
For each piece, implement canMoveTo(destination) considering board boundaries, cell types (e.g., only rats enter water), and capture rules (rank comparison, special cases like rat captures elephant).
Game class alternates turns, validates moves, updates board, and checks win conditions: a piece reaches opponent's den or opponent has no legal moves. Return appropriate status from move execution.
Test board initialization (correct piece placement), a capture move (e.g., tiger captures cat), and a multi-move turn simulation (alternating moves until win). Use assertions to verify state after each move.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.