Jump to a problem, path or page
Jump to a problem, path or page
01 · Frame the problem
Design a two-player grid battleship engine. Ships occupy straight contiguous cells, cannot overlap and remain hidden from the opponent. Repeated shots are invalid and must not consume a turn.
The domain engine must enforce placement, turns and terminal rules while preserving hidden information. Analyse what each player's view is allowed to reveal, not just whether the renderer hides the opponent's board.
02 · Find the design pressure
Begin with explicit placement/play/finished phases and private board ownership. Mutating cells during partial validation leaves illegal fleets. Commit a complete valid placement or shot transition and produce scoped public snapshots afterward.
03 · Define success
04 · Identify the correctness boundary
Validate fleet placement fully before committing a board, including shape, bounds and overlap. During play, a shot identity and turn transition commit together. Public views expose only permitted results; copying the opponent's full board and hiding it in the renderer still leaks secret state to callers.
05 · Make it concrete
A ship crossing the board edge is rejected without placing its valid prefix. A repeated shot cannot consume a second turn or register a second hit. When the last intact ship cell is hit, the game becomes terminal and the opponent view reveals only the information allowed by that terminal-state policy.