1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# Picture Puzzle
<img src="puzzle.png" />
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 STL** — `std::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:
```bash
sudo apt install fltk1.3-dev
git clone https://git.scratko.xyz/picture-puzzle
cd picture-puzzle
make
./main
```
## For Windows platform
- Requires FLTK for Windows.
- Prebuilt x86_64 executable available here:
<a href="https://scratko.xyz/games/puzzle.exe" target="_blank">Download Windows
version</a>
|