Hi there! So I have created a rotating puzzle, but I need a way to figure out if it has been solved. So far I have been experimenting with scripts from this thread:
I am using their method in detecting this puzzle, with some edits. Basically, how this system works is by taking the absolute values of the “Outlets” at the end of each frame
This is my maze. At the end of every “Entrance” or “Opening”, there is an invisible outlet.
Basically, I need a reliable algorithm that can detect when all the outlets are lined up. However, as you can see from the picture above, it isn’t exactly lined up like one would hope. The reason it isn’t is because I manually had lay each frame out, because UIGridlayouts don’t support rotation.
So basically, I created a modified version of the script:
local function CheckFinished()
local CheckComplete = {}
for i, v in pairs(partsOutlet) do
if table.find(CheckComplete, v) == nil then
local AbsP1 = v.AbsolutePosition
for n, k in pairs(partsOutlet) do
if v ~= k then
local AbsP2 = k.AbsolutePosition
local XValue1 = AbsP1.X
local YValue1 = AbsP1.Y
local XValue2 = AbsP2.X
local YValue2 = AbsP2.Y
local check1 = false
local check2 = false
if XValue1 and YValue1 and XValue2 and YValue2 then
if XValue1 > XValue2 then
if XValue1 - XValue2 <= 5 then
print(XValue1 - XValue2)
check1 = true
end
elseif XValue1 < XValue2 then
if XValue2 - XValue1 <= 5 then
print(XValue2 - XValue1)
check1 = true
end
else
check1 = true
end
if YValue1 > YValue2 then
if YValue1 - YValue2 <= 5 then
print(YValue1 - YValue2)
check2 = true
end
elseif YValue1 < YValue2 then
if YValue2 - YValue1 <= 5 then
print(YValue2 - YValue1)
check2 = true
end
else
check2 = true
end
end
if check1 == true and check2 == true then
table.insert(CheckComplete, v)
table.insert(CheckComplete, k)
end
end
end
end
end
if #CheckComplete == (#partsOutlet) then
return true
else
return false, #CheckComplete, #partsOutlet
end
end
partsOutlet is a table that I have already inserted all the outlets.
I know it’s kinda inefficient, basically what I am doing is breaking down each absolute position then seeing if their absolute positions are within 5 pixels of each other. if it is, then that means those two outlets are solved, and it puts that into a “solved” table
But for some reason, it’s acting weird. I have a print function that displays how many are completed compared to how many there are. But I get inconsistent and varied results:
This solved puzzle prints 46 / 48
This unsolved puzzle however, prints 48/48
Also note that I added two outlets at the start and the end (the purple things at the start and end) and also 2 squares do not have any outlets due to them being blank.
So I’m just confused at how to approach this right now. If anyone has a better method to check if it is done, or a suitable solution to this problem, that would be great.
Thanks!