Object-Oriented Design: Jigsaw Puzzle
Design an object-oriented model for a jigsaw puzzle game.
Requirements
-
The puzzle consists of a set of
pieces
that can be assembled into a final
board
(e.g., an
R x C
grid).
-
Each piece has
4 sides
(top/right/bottom/left) that must match adjacent pieces when placed.
-
Pieces can be
rotated
(0°, 90°, 180°, 270°).
-
The system should support:
-
Initializing a puzzle from a collection of pieces.
-
Placing/removing a piece on the board.
-
Validating whether a placement is legal (in-bounds, cell empty, and sides match neighbors).
-
Checking whether the puzzle is solved.
Clarifications (state assumptions if needed)
-
You may assume a rectangular puzzle where each piece occupies one cell in a grid.
-
You may represent side “matching” using IDs/keys (e.g.,
tab#42
matches
blank#42
) or a comparable abstraction.
Deliverables
-
Propose core classes, key fields, and methods.
-
Explain how rotation affects side matching.
-
Discuss extensibility (e.g., different board shapes, irregular pieces, multiplayer, UI separation).