Bug 504917 - Shuffling has the chance of generating a solved puzzle
Summary: Shuffling has the chance of generating a solved puzzle
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Fifteen Puzzle widget (other bugs)
Version First Reported In: 6.3.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-28 15:59 UTC by Jan Bidler
Modified: 2025-05-29 22:00 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.4.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Bidler 2025-05-28 15:59:36 UTC
SUMMARY
Shuffling the pieces has the chance of generating a solved puzzle. Which defeats the point of shuffling.

STEPS TO REPRODUCE
1. Set grid size to 2
2. Click on the "shuffle" button until you have a grid that goes [1], [2], [3], [ ]

OBSERVED RESULT
A solved grid.

EXPECTED RESULT
No solved grid. If for some reason the internal random generator generated a solved grid, it should automatically reshuffle the board.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.3.5
KDE Frameworks Version: 6.14.0
Qt Version: 6.9.0
Kernel Version: 6.14.6-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 1600 Six-Core Processor
Memory: 15.6 GiB of RAM
Graphics Processor: AMD Radeon RX 570 Series
Manufacturer: Gigabyte Technology Co., Ltd.
Product Name: B450M DS3H
Comment 1 Nate Graham 2025-05-28 16:07:23 UTC
Can reproduce, but a 2x2 puzzle isn't much of a puzzle! I wonder if 3x3 should be the minimum size.
Comment 2 cwo 2025-05-28 16:15:52 UTC
(In reply to Nate Graham from comment #1)
> Can reproduce, but a 2x2 puzzle isn't much of a puzzle! I wonder if 3x3
> should be the minimum size.

2×2 is good for testing, and I guess if someone wants a truly easy win. I'd say it's fine to keep it as the minimum, users who want at least a small challenge can simply choose a higher number..
Comment 3 Bug Janitor Service 2025-05-29 09:11:43 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kdeplasma-addons/-/merge_requests/830
Comment 4 cwo 2025-05-29 19:12:01 UTC
Git commit 1ed2c7ff69154e06cc890bf94c59bbcf40b34fa6 by Christoph Wolk.
Committed on 29/05/2025 at 09:08.
Pushed by cwo into branch 'master'.

applets/fifteenpuzzle: don't shuffle into a solved puzzle

When reshuffling the board, it's possible to immediately get an already
solved puzzle. It's very unlikely for realistic board sizes, but can be
triggered somewhat if you refresh a 2×2 board often for some reason.

We might as well make sure it never happens. To do this easily, we
convert the existing solution checker into a function with return value,
rather than always immediately marking the board as solved if it is, and
use that to reshuffle if needed.

M  +9    -4    applets/fifteenPuzzle/package/contents/ui/FifteenPuzzle.qml

https://invent.kde.org/plasma/kdeplasma-addons/-/commit/1ed2c7ff69154e06cc890bf94c59bbcf40b34fa6
Comment 5 cwo 2025-05-29 19:40:45 UTC
Git commit de00ace4af9f708401069f6bd2721fdfbbf1549c by Christoph Wolk.
Committed on 29/05/2025 at 19:17.
Pushed by cwo into branch 'Plasma/6.4'.

applets/fifteenpuzzle: don't shuffle into a solved puzzle

When reshuffling the board, it's possible to immediately get an already
solved puzzle. It's very unlikely for realistic board sizes, but can be
triggered somewhat if you refresh a 2×2 board often for some reason.

We might as well make sure it never happens. To do this easily, we
convert the existing solution checker into a function with return value,
rather than always immediately marking the board as solved if it is, and
use that to reshuffle if needed.


(cherry picked from commit 1ed2c7ff69154e06cc890bf94c59bbcf40b34fa6)

Co-authored-by: Christoph Wolk <cwo.kde@posteo.net>

M  +9    -4    applets/fifteenPuzzle/package/contents/ui/FifteenPuzzle.qml

https://invent.kde.org/plasma/kdeplasma-addons/-/commit/de00ace4af9f708401069f6bd2721fdfbbf1549c