back to scratko.xyz
aboutsummaryrefslogtreecommitdiff

Picture Puzzle

A desktop sliding puzzle game similar to the standard widget in Windows 7. Written in modern C++17 with FLTK for the graphical interface, it provides a lightweight, cross-platform experience with fast compilation and responsive UI.

The goal is simple: rearrange the tiles to restore the original image, moving one piece at a time.


Features

Image Handling

  • Upload an image in any format and resolution — the program will:
    • Resize it to fit the puzzle grid (300x300).
    • Slice it into 3x3 tiles.
    • Save tiles into a dedicated resources/ subdirectory.
  • Uses stb_image, stb_image_resize, and stb_image_write for image loading, resizing, and saving.

Built-in Embedded Image

  • Both Linux and Windows builds include a fully embedded image (Toucan) directly inside the executable.
  • The embedded image is stored in resources.o as a static byte array.
  • A C-language image converter tool is included, which:
    • Takes a PNG image.
    • Generates a resources.cpp file containing the image bytes.
  • This allows shipping the game as a single executable without requiring external image files.
  • The embedded Toucan image serves as the default puzzle; users can still load their own images.

Puzzle Gameplay

  • Standard 3×3 sliding puzzle with one empty tile.
  • Random shuffling with solvability check to ensure the puzzle can be completed.
  • Option to load:
    • Built-in embedded image.
    • External images from resources/ folder or user upload.

Automatic Puzzle Solver

  • A* search algorithm implementation.
  • Uses Manhattan distance as the heuristic (g(n) + W(n)).
  • Shows a step-by-step animation of the optimal solution.

Cross-Platform

  • Works on Linux and Windows.
  • On both platforms, distributed as a single executable with embedded resources.

Technologies Used

  • C++17 STLstd::unique_ptr, std::shared_ptr, priority_queue, unordered_set, filesystem, algorithm.
  • FLTK — lightweight GUI library.
  • stb_image / stb_image_resize / stb_image_write — image processing.
  • A* algorithm for optimal pathfinding.
  • Custom hashing and equality comparison for puzzle states.
  • Custom C-based resource generator for embedding binary image data into the executable.

Building

Linux

Install FLTK development package:

sudo apt install fltk1.3-dev
git clone https://git.scratko.xyz/picture-puzzle
cd picture-puzzle
make
./main

For Windows platform