Some of the puzzles create by lootboxes are unsolvable -- they correspond to configurations with odd parity.
The parity check
-- Check if can be solved
local inversions = 0
for i = 1, #raw_pos do
for j = i + 1, #raw_pos do
if raw_pos[i] > raw_pos[j] then
inversions = inversions + 1
end
end
end
incorrectly includes the parity of the blank (9), which allows some configuration with odd parity to pass this test.
I'd recommend the following code change:
-- Check if can be solved
local inversions = 0
for i = 1, #raw_pos do
for j = i + 1, #raw_pos do
-- Only count inversions for tiles 1-8.
-- Skip the blank tile (9) to ensure stable parity.
if raw_pos[i] ~= 9 and raw_pos[j] ~= 9 then
if raw_pos[i] > raw_pos[j] then
inversions = inversions + 1
end
end
end
end
Some of the puzzles create by lootboxes are unsolvable -- they correspond to configurations with odd parity. The parity check
incorrectly includes the parity of the blank (9), which allows some configuration with odd parity to pass this test.
I'd recommend the following code change: