Advertisement
Guest User

Mortal Coil Solver - FULL Source

a guest
Dec 17th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.41 KB | None | 0 0
  1.  
  2.  
  3. request = game:GetService('HttpService'):GetAsync("http://www.hacker.org/coil/index.php?name=Trubisky&password=btjdwe2eg")
  4. selx = 1
  5. sely = 1
  6. math.randomseed(tick())
  7. folder = game.Workspace.storage
  8. t = tostring
  9. n=tonumber
  10.  
  11. function mysplit(inputstr, sep)
  12.         if sep == nil then
  13.                 sep = "%s"
  14.         end
  15.         local t={} ; i=1
  16.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  17.                 t[i] = str
  18.                 i = i + 1
  19.         end
  20.         return t
  21. end
  22. function rebuild(tables,remove)
  23. local newtab = {}
  24. local found = false
  25. for i,v in pairs(tables) do
  26. if v ~= remove then
  27.     if found == false then
  28.         newtab[i] = v
  29.     else
  30.         newtab[i-1] = v
  31.     end
  32. else found = true
  33. end
  34. end
  35. return newtab
  36. end
  37.  
  38. local d = tick()
  39. tables = mysplit(request, "<")
  40. newtab = {}
  41. for i,v in pairs(tables) do
  42.     if string.find(v, "FlashVars") then
  43.             table.insert(newtab, v)
  44.            
  45.     end
  46.  
  47.    
  48. end
  49. local table3 = mysplit(newtab[1], '"')
  50. local boardcords = ""
  51. local x = ""
  52. local y = ""
  53. strings = table3[4]
  54. spleet = mysplit(strings,"board")[2]
  55. print(table3[4])
  56. for i=1, string.len(spleet), 1 do
  57.     if i~=1 then
  58.         boardcords = boardcords..spleet:sub(i,i)
  59.     end
  60. end
  61. spleet2=mysplit(strings,"&")[1]
  62. for i=1, #spleet2, 1 do
  63.     if i~= 1 and i ~= 2 then
  64.         x = x..spleet2:sub(i,i)
  65.     end
  66. end
  67. spleet2=mysplit(strings,"&")[2]
  68. for i=1, #spleet2, 1 do
  69.     if i~= 1 and i ~= 2 then
  70.         y = y..spleet2:sub(i,i)
  71.     end
  72. end
  73. print(boardcords)
  74. print(x)
  75. coordinates = {}
  76.  
  77. print(y)
  78. print(tick() - d)
  79. local r = 0
  80. for i=1, tonumber(y), 1 do
  81.     for a=1, tonumber(x), 1 do
  82.         r = r + 1
  83.         --[[local d = Instance.new('Part')
  84.         d.Parent = folder
  85.         d.Size = Vector3.new(2,1,2)
  86.         d.CFrame = CFrame.new(0,0,0) + Vector3.new(2*a,0,2*i)
  87.         d.Anchored = true
  88.         d.Name = a..i--]]
  89.         coordinates[t(a).."-"..t(i)] = {}
  90.         coordinates[t(a).."-"..t(i)].selected = false
  91.         coordinates[t(a).."-"..t(i)].filled = false
  92.         coordinates[t(a).."-"..t(i)].x = a
  93.         coordinates[t(a).."-"..t(i)].y = i
  94.         coordinates[t(a).."-"..t(i)].turnpoint = false
  95.         if string.sub(boardcords,r,r) == "X" then
  96.             --d.Color = Color3.fromRGB(255,0,0)
  97.             coordinates[t(a).."-"..t(i)].filled = true
  98.         end
  99.        
  100.     end
  101. end
  102. function updatemap(cords, mx, my)
  103. folder:ClearAllChildren()
  104.  
  105. for i=1, tonumber(my), 1 do
  106.     for a=1, tonumber(mx), 1 do
  107.         --[[local d = Instance.new('Part')
  108.         d.Parent = folder
  109.         d.Size = Vector3.new(2,1,2)
  110.         d.CFrame = CFrame.new(0,0,0) + Vector3.new(2*a,0,2*i)
  111.         d.Anchored = true--]]
  112.         if t(cords[t(a).."-"..t(i)].filled) == "true" then
  113.             --d.Color = Color3.fromRGB(0,255,0)
  114.         end
  115.         if  t(cords[t(a).."-"..t(i)].selected) == "true" then
  116.             --d.Color = Color3.fromRGB(255,0,0)
  117.         end
  118.        
  119.         end
  120.     end
  121. end
  122. logs = {}
  123. function logstate(tables, num)
  124.     local newtabz = {}
  125.     for i=1, x, 1 do
  126.         for a=1,y ,1 do
  127.             newtabz[t(i).."-"..t(a)] = tables[t(i).."-"..t(a)]
  128.             --print(t(i).."-"..t(a).." "..t(newtabz[t(i).."-"..t(a)].filled))
  129.         end
  130.     end
  131.     logs[num] = newtabz
  132. end
  133. function state(num)
  134.     return logs[num]
  135. end
  136. function options(coods, a, i)
  137. local clone = coods
  138. local directions = {-1,1,-1,1}
  139. local avaliable = {}
  140.     if clone[tostring(a + -1).."-"..tostring(i)] ~= nil and clone[tostring(a + -1).."-"..tostring(i)].filled ~= true then table.insert(avaliable, "l") end
  141.     if clone[tostring(a + 1).."-"..tostring(i)] ~= nil and clone[tostring(a + 1).."-"..tostring(i)].filled ~= true then table.insert(avaliable, "r") end
  142.     if clone[tostring(a).."-"..tostring(i + -1)] ~= nil and clone[tostring(a).."-"..tostring(i + -1)].filled ~= true then table.insert(avaliable, "u") end
  143.     if clone[tostring(a).."-"..tostring(i +1)] ~= nil and clone[tostring(a).."-"..tostring(i + 1)].filled ~= true then table.insert(avaliable, "d") end
  144. return avaliable
  145.             --you have to finish fixing the values above for x1 and y2 then do a check return
  146. end
  147. function isdone(board)
  148.     local done = true
  149.     for i,v in pairs(board) do
  150.         if t(v.filled) ~= "true" then
  151.             done = false
  152.         end
  153.     end
  154.     return done
  155. end
  156. function sortoptions()
  157.     local options = {}
  158.     for i=1, tonumber(y), 1 do
  159.         for a=1, tonumber(x), 1 do
  160.             local newtab = {}
  161.             newtab.ecks = a
  162.             newtab.why = i
  163.             table.insert(options, newtab)
  164.         end
  165.     end
  166.     return options
  167. end
  168. function moveoption(tables, option)
  169.     local newtab = {}
  170.     local solved = false
  171.     for i,v in pairs(tables) do
  172.         if solved ~= true then
  173.             newtab[i+1] = v
  174.         else
  175.             newtab[i] = v
  176.         end
  177.         if v == option then
  178.             newtab[1] = v
  179.             solved = true
  180.         end
  181.     end
  182.     return newtab
  183. end
  184.  
  185. function reshuffle(cords, opts)
  186.     local movers = {}
  187.     for i,v in pairs(opts) do
  188.         if cords[t(v.ecks).."-"..t(v.why)].filled ~= true then
  189.             table.insert(movers, v)
  190.         end
  191.     end
  192.     if #movers == 1 then
  193.         opts = moveoption(opts, movers[1])
  194.             print("SHUFFLED")
  195.     game:GetService('RunService').Stepped:Wait()
  196.     end
  197.  
  198.     return opts
  199. end
  200. function ispossible(cords, mx, my)
  201.     local result = true
  202.     t = tostring
  203.     local num = 0
  204.     for i=1, tonumber(my), 1 do
  205.     for a=1, tonumber(mx), 1 do
  206.         if cords[t(a).."-"..t(i)].filled ~= true then
  207.             local o = options(cords, a, i)
  208.             if o == {} then --this section checks if there's any isolated tiles that are completely surronded; making it impossible
  209.             result = false
  210.             elseif #o == 1  then
  211.                 num = num + 1
  212.             end
  213.             --if #o == 1 then
  214.             --  num = num + 1
  215.             --end
  216.         end
  217.     end
  218.     end
  219.  
  220.    
  221.     --if num >= 2 then
  222.     --  result = false
  223.     --end
  224.     for i=1, tonumber(mx), 1 do--establishes row scanning for fullness vertica;;y
  225.         blocked=true
  226.         for a=1, tonumber(my), 1 do
  227.         if cords[t(i).."-"..t(a)].filled ~= true then
  228.             blocked=false
  229.         end
  230.         end
  231.         if blocked==true and i ~= 1 and i ~= maxx then
  232.         hidden=false
  233.         hidden1=false
  234.             for ai=1, i-1, 1 do
  235.                 for aa=1, tonumber(my), 1 do
  236.                     --you just established if a row was blocked, this is the scanning on the left. (vertical rows)
  237.                     if cords[t(ai).."-"..t(aa)].filled ~= true then
  238.                         hidden = true
  239.                     end
  240.                 end
  241.             end
  242.             for ai=tonumber(mx), i+1, -1 do
  243.                 for aa=1, tonumber(my), 1 do
  244.                     --you just established if a row was blocked, this is the scanning on the right. (vertical rows)
  245.                     if cords[t(ai).."-"..t(aa)].filled ~= true then
  246.                         hidden1 = true
  247.                     end
  248.                 end
  249.             end
  250.             if hidden == true and hidden1 == true then
  251.                 result = false
  252.             end
  253.         end
  254.     end
  255.    
  256.     --gap - below I'm doing the same as above but doing horizontal row scanning instead of vertical
  257.    
  258.     for i=1, tonumber(my), 1 do--establishes row scanning for fullness horizontally
  259.         blocked=true
  260.         for a=1, tonumber(mx), 1 do
  261.         if cords[t(a).."-"..t(i)].filled ~= true then
  262.             blocked=false
  263.         end
  264.         end
  265.         if blocked==true and i ~= 1 and i ~= maxy then
  266.         hidden=false
  267.         hidden1=false
  268.             for ai=1, i-1, 1 do
  269.                 if i-1 == 0 then break end
  270.                 for aa=1, tonumber(mx), 1 do
  271.                     --you just established if a row was blocked, this is the scanning on the left. (horizontal rows)
  272.                     if cords[t(aa).."-"..t(ai)].filled ~= true then
  273.                         hidden = true
  274.                     end
  275.                 end
  276.             end
  277.             for ai=tonumber(my), i+1, -1 do
  278.                 for aa=1, tonumber(mx), 1 do
  279.                     --you just established if a row was blocked, this is the scanning on the right. (horizontal rows)
  280.                     if cords[t(aa).."-"..t(ai)].filled ~= true then
  281.                         hidden1 = true
  282.                     end
  283.                 end
  284.             end
  285.             if hidden == true and hidden1 == true then
  286.                 result = false
  287.             end
  288.         end
  289.     end
  290.     return result
  291. end
  292.  
  293.  
  294.  
  295. function restorestart(startx, starty)
  296. r = 0
  297. --print(startx)
  298. --print(starty)
  299. selx = startx
  300. sely = starty
  301.  
  302.  
  303. for i=1, tonumber(y), 1 do
  304.     --wait()
  305.     for a=1, tonumber(x), 1 do
  306.         r = r + 1
  307.         --[[
  308.         local d = Instance.new('Part')
  309.         d.Parent = folder
  310.         d.Size = Vector3.new(2,1,2)
  311.         d.CFrame = CFrame.new(0,0,0) + Vector3.new(2*a,0,2*i)
  312.         d.Anchored = true
  313.         d.Name = a..i
  314.         --]]
  315.         coordinates[t(a).."-"..t(i)] = {}
  316.         coordinates[t(a).."-"..t(i)].selected = false
  317.         coordinates[t(a).."-"..t(i)].filled = false
  318.         coordinates[t(a).."-"..t(i)].x = a
  319.         coordinates[t(a).."-"..t(i)].y = i
  320.         coordinates[t(a).."-"..t(i)].turnpoint = false
  321.         if string.sub(boardcords,r,r) == "X" then
  322.             --d.Color = Color3.fromRGB(255,0,0)
  323.             coordinates[t(a).."-"..t(i)].filled = true
  324.         end
  325.         if i == starty and a == startx then
  326.             --d.Color = Color3.fromRGB(255,0,0)
  327.             coordinates[t(a).."-"..t(i)].selected = true
  328.            
  329.         end
  330.        
  331.     end
  332.    
  333. end
  334.  
  335.    
  336. end
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346. function revert(board, direction, x, y, sx, sy)
  347.     --print(sx)
  348.     --print(sy)
  349.     tile = board[t(x).."-"..t(y)]
  350.     board[t(x).."-"..t(y)].turnpoint = false
  351. if direction == "d" then
  352. why=0
  353. while true do
  354. why=why+1
  355. if board[t(x).."-"..t(y + why)] ~= nil and t(board[t(x).."-"..t(y + why)].turnpoint) ~= "true" then
  356. board[t(x).."-"..t(y + (why-1))].filled = false
  357. board[t(x).."-"..t(y + (why-1))].selected = false
  358. board[t(x).."-"..t(y+ why)].filled = true
  359. board[t(x).."-"..t(y + why)].selected = true
  360. selx = x
  361. sely = y + why
  362. else
  363.  
  364. if board[t(x).."-"..t(y+ why)] ~= nil then 
  365. board[t(x).."-"..t(y + (why-1))].filled = false
  366. board[t(x).."-"..t(y + (why-1))].selected = false
  367. board[t(x).."-"..t(y+ why)].filled = true
  368. board[t(x).."-"..t(y + why)].selected = true
  369. selx = x
  370. sely = y + why
  371. else restorestart(sx, sy) end
  372.  
  373.  
  374. break
  375. end
  376. end
  377. elseif direction =="u" then
  378.    
  379. why=0
  380. while true do
  381. --print("-"...."-")
  382. why=why-1
  383. if board[t(x).."-"..t(y + why)] ~= nil and t(board[t(x).."-"..t(y + why)].turnpoint) ~= "true" then
  384. --print(board[t(x).."-"..t(y + why)].filled)
  385. board[t(x).."-"..t(y + (why+1))].filled = false
  386. board[t(x).."-"..t(y + (why+1))].selected = false
  387. board[t(x).."-"..t(y + why)].filled = true
  388. board[t(x).."-"..t(y + why)].selected = true
  389. selx = x
  390. sely = y + why
  391. else
  392. --print(board[t(x).."-"..t(y + why)].filled)
  393. if board[t(x).."-"..t(y + why)] ~= nil then
  394. board[t(x).."-"..t(y + (why+1))].filled = false
  395. board[t(x).."-"..t(y + (why+1))].selected = false
  396. board[t(x).."-"..t(y + why)].filled = true
  397. board[t(x).."-"..t(y + why)].selected = true
  398. selx = x
  399. sely = y + why
  400. else  restorestart(sx, sy)  end
  401.     --print("broke")
  402. break
  403. end
  404. end
  405.  
  406. elseif direction =="l" then
  407. why=0
  408. while true do
  409. why=why-1
  410. if board[t(x + why).."-"..t(y)] ~= nil and board[t(x + why).."-"..t(y)].turnpoint ~= true then
  411. board[t(x+ (why+1)).."-"..t(y)].filled = false
  412. board[t(x + (why+1)).."-"..t(y)].selected = false
  413. board[t(x + why).."-"..t(y)].filled = true
  414. board[t(x + why).."-"..t(y)].selected = true
  415. selx = x + why
  416. sely = y
  417. else
  418.     if board[t(x + why).."-"..t(y)] ~= nil then
  419.     --print("broke")
  420.     board[t(x+ (why+1)).."-"..t(y)].filled = false
  421. board[t(x + (why+1)).."-"..t(y)].selected = false
  422. board[t(x + why).."-"..t(y)].filled = true
  423. board[t(x + why).."-"..t(y)].selected = true
  424. selx = x + why
  425. sely = y
  426.     else restorestart(sx, sy)  end
  427. break
  428. end
  429. end
  430. elseif direction == "r" then
  431. why=0
  432. while true do
  433. why=why+1
  434. if board[t(x + why).."-"..t(y)] ~= nil and board[t(x + why).."-"..t(y)].turnpoint ~= true then
  435. board[t(x+ (why-1)).."-"..t(y)].filled = false
  436. board[t(x + (why-1)).."-"..t(y)].selected = false
  437. board[t(x + why).."-"..t(y)].filled = true
  438. board[t(x + why).."-"..t(y)].selected = true
  439. selx = x + why
  440. sely = y
  441. else
  442. if board[t(x + why).."-"..t(y)] ~= nil then
  443. board[t(x+ (why-1)).."-"..t(y)].filled = false
  444. board[t(x + (why-1)).."-"..t(y)].selected = false
  445. board[t(x + why).."-"..t(y)].filled = true
  446. board[t(x + why).."-"..t(y)].selected = true
  447. selx = x + why
  448. sely = y
  449. else restorestart(sx, sy)  end
  450. break
  451. end
  452. end
  453. end
  454. return board
  455. end
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462. function opposite(dir)
  463.     local dirs = {"u", "d", "r", "l"}
  464.     local opposites = {"d", "u", "l", "r"}
  465.     for i,v in pairs(dirs) do
  466.         if v == dir then
  467.             return opposites[i]
  468.         end
  469.     end
  470.    
  471. end
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485. function move(board, direction, x, y)
  486. tile = board[t(x).."-"..t(y)]
  487. if direction == "d" then
  488. why=0
  489. while true do
  490. why=why+1
  491. if board[t(x).."-"..t(y + why)] ~= nil and board[t(x).."-"..t(y + why)].filled ~= true then
  492. board[t(x).."-"..t(y + (why-1))].filled = true
  493. board[t(x).."-"..t(y + (why-1))].selected = false
  494. board[t(x).."-"..t(y+ why)].filled = true
  495. board[t(x).."-"..t(y + why)].selected = true
  496. selx = x
  497. sely = y + why
  498. else
  499.    
  500. break
  501. end
  502. end
  503. elseif direction =="u" then
  504.    
  505. why=0
  506. while true do
  507. --print("-"...."-")
  508. why=why-1
  509. if board[t(x).."-"..t(y + why)] ~= nil and t(board[t(x).."-"..t(y + why)].filled) == "false" then
  510. --print(board[t(x).."-"..t(y + why)].filled)
  511. board[t(x).."-"..t(y + (why+1))].filled = true
  512. board[t(x).."-"..t(y + (why+1))].selected = false
  513. board[t(x).."-"..t(y + why)].filled = true
  514. board[t(x).."-"..t(y + why)].selected = true
  515. selx = x
  516. sely = y + why
  517. else
  518.     --print("broke")
  519. break
  520. end
  521. end
  522.  
  523. elseif direction =="l" then
  524. why=0
  525. while true do
  526. why=why-1
  527. if board[t(x + why).."-"..t(y)] ~= nil and board[t(x + why).."-"..t(y)].filled ~= true then
  528. board[t(x+ (why+1)).."-"..t(y)].filled = true
  529. board[t(x + (why+1)).."-"..t(y)].selected = false
  530. board[t(x + why).."-"..t(y)].filled = true
  531. board[t(x + why).."-"..t(y)].selected = true
  532. selx = x + why
  533. sely = y
  534. else
  535.     --print("broke")
  536. break
  537. end
  538. end
  539. elseif direction == "r" then
  540. why=0
  541. while true do
  542. why=why+1
  543. if board[t(x + why).."-"..t(y)] ~= nil and board[t(x + why).."-"..t(y)].filled ~= true then
  544. board[t(x+ (why-1)).."-"..t(y)].filled = true
  545. board[t(x + (why-1)).."-"..t(y)].selected = false
  546. board[t(x + why).."-"..t(y)].filled = true
  547. board[t(x + why).."-"..t(y)].selected = true
  548. selx = x + why
  549. sely = y
  550. else
  551. break
  552. end
  553. end
  554. end
  555. return board
  556. end
  557. function solve()
  558.     choseny= 0
  559.     chosenx= 0
  560.     indonee = false
  561.     opps = sortoptions()
  562.         while #opps ~= 0 do
  563.             local tempcount = 0
  564.             local v = opps[1]
  565. --          rounds = rounds + 1
  566.             crx = v.ecks
  567.             cry = v.why
  568.                 stack = {}
  569.                 if coordinates[t(crx).."-"..t(cry)].filled ~= true then
  570.                 startopts = options(coordinates, crx, cry)
  571.                 for i,v in pairs(startopts) do
  572.                     --print("startop.."..v)
  573.                 end
  574.                 chosenx = crx
  575.                 choseny = cry
  576.                 selx = crx
  577.                 sely = cry
  578.                 stack[1] = {}
  579.                 stack[1].used = {}
  580.                 indexer = 1
  581.                 while true do
  582.                     --game:GetService('RunService').Stepped:Wait()
  583.                     --  print(selx)
  584.                     --  print(sely)
  585.                         opts = options(coordinates, selx, sely)
  586.                    
  587.                     --opts = options(coordinates, selx, sely)
  588.                     for i,v in pairs(stack[indexer].used) do
  589.                         opts = rebuild(opts, v)
  590.                         --print(v)
  591.                     end
  592.                     --left off here, you're having a problem parsing attempted options so it's skipping certain ones for some reason
  593.                     local check = t(ispossible(coordinates, x, y))
  594.                     if (#opts == 0) or check == "false"  then
  595.                         --if check=="false" then
  596.                         --  print("eliminated impossible")
  597.                         --  game:GetService('RunService').Stepped:Wait()
  598.                         --end
  599.                         if selx == crx and sely == cry then
  600.                         --  print("new tile")
  601.                             break
  602.                            
  603.                         else
  604.                         --print("reverted from last direction"..stack[indexer].last)
  605.                         --print(chosenx)
  606.                         --print(choseny)
  607.                         coordinates = revert(coordinates, opposite(stack[indexer].last), selx, sely, chosenx, choseny)
  608.                         table.insert(stack[indexer-1].used, stack[indexer].last)
  609.                         --print("DELETED "..stack[indexer].last)
  610.                         stack[indexer] = nil
  611.                         indexer = indexer - 1
  612.                         end
  613.                        
  614.                     else
  615.                         opps = reshuffle(coordinates, opps)
  616.                         chosdir = opts[math.random(#opts)]
  617.                         coordinates = move(coordinates, chosdir, selx, sely)
  618.                         coordinates[t(selx).."-"..t(sely)].turnpoint = true
  619.                         indexer = indexer + 1
  620.                         --print(chosdir)
  621.                         local templated = {}
  622.                         templated.last = chosdir
  623.                         templated.selx = selx
  624.                         templated.sely = sely
  625.                         templated.used = {}
  626.                         stack[indexer] = templated
  627.                     end
  628.                     updatemap(coordinates, x, y)
  629.                     if isdone(coordinates) == true then
  630.                        
  631.                         --print("start cords: "..chosenx.."-"..choseny)
  632.                         newtabb = {}
  633.                         for i=2, #stack, 1 do
  634.                             newtabb[i-1] = stack[i].last
  635.                             --print(stack[i].last)
  636.                         end
  637.                        
  638.                         isdonee = true
  639.                        
  640.                         break
  641.                        
  642.                     end
  643.                    
  644.                    
  645.                 end
  646.                
  647.                         --code herre
  648.                 end
  649.                 if isdonee == true then
  650.                     break
  651.                 end
  652.             opps = rebuild(opps,v)
  653.         end
  654.    
  655.    
  656.    
  657.    
  658.    
  659.    
  660.    
  661.    
  662.    
  663.    
  664.    
  665.    
  666.    
  667.    
  668.    
  669.     return chosenx, choseny, newtabb
  670.    
  671.    
  672.    
  673. end
  674. local start = tick()
  675. startx, starty, moves = solve()
  676. local finaltime = tick() - start
  677. print(startx)
  678. print(starty)
  679. local finalstring = ""
  680. for i=1, #moves, 1 do
  681.     print(moves[i])
  682.     finalstring = finalstring..(string.upper(moves[i]))
  683. end
  684. print(finalstring)
  685. d = game:GetService('HttpService'):GetAsync("http://www.hacker.org/coil/index.php?name=Trubisky&password=boesge26&path="..finalstring.."&x="..(startx-1).."&y="..(starty-1))
  686.  
  687. print(d)
  688. print("with efficiency: "..finaltime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement