Advertisement
Doob

labyrinthian

Dec 15th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. --[[
  2. 01 02 03 04
  3. 05 06 07 08  1
  4. 09 10 11 12  уровень
  5. 13 14 15 16
  6.  
  7. 17 18 19 20
  8. 21 22 23 24  2
  9. 25 26 27 28  уровень
  10. 29 30 31 32
  11.  
  12. 33 34 35 36
  13. 37 38 39 40  3
  14. 41 42 43 44  уровень
  15. 45 46 47 48
  16.  
  17. 49 50 51 52
  18. 53 54 55 56  4
  19. 57 58 59 60  уровень
  20. 61 62 63 64
  21. ]]
  22.  
  23. local tLink = {} -- таблица связей
  24.  
  25. for g = 1, 64, 4 do
  26.   table.insert(tLink, {g, g+1, g+2, g+3})
  27. end
  28.  
  29. local tIndex = {} -- таблица индесов комнат
  30.  
  31. for f = 1, 64 do
  32.   table.insert(tIndex, f)
  33. end
  34.  
  35. function shuffle(tbl)
  36.   trs = math.random(1, 13)
  37.   for i = 0, trs do
  38.   i = 64
  39.     while i > 1 do
  40.       i = i - 1
  41.       j = math.random(1, i)
  42.       tbl[j], tbl[i] = tbl[i], tbl[j]
  43.     end
  44.   end
  45.   return tbl
  46. end
  47.  
  48. shuffle(tLink)
  49.  
  50. local function perm()
  51.   tIndex[4], tIndex[8], tIndex[12], tIndex[16], tIndex[32], tIndex[48], tIndex[64], tIndex[60], tIndex[56], tIndex[52], tIndex[36], tIndex[20] =
  52.   tIndex[16], tIndex[32], tIndex[48], tIndex[64], tIndex[60], tIndex[56], tIndex[52], tIndex[36], tIndex[20], tIndex[4], tIndex[8], tIndex[12]
  53.  
  54.   tIndex[24], tIndex[28], tIndex[40], tIndex[44] = tIndex[40], tIndex[24], tIndex[44], tIndex[28]
  55.  
  56.   for sh = 0, 3 do
  57.     tIndex[1+sh], tIndex[2+sh], tIndex[3+sh], tIndex[4+sh],
  58.     tIndex[5+sh], tIndex[6+sh], tIndex[7+sh], tIndex[8+sh],
  59.     tIndex[9+sh], tIndex[10+sh], tIndex[11+sh], tIndex[12+sh],
  60.     tIndex[13+sh], tIndex[14+sh], tIndex[15+sh], tIndex[16+sh] =
  61.     tIndex[5+sh], tIndex[6+sh], tIndex[7+sh], tIndex[8+sh],
  62.     tIndex[9+sh], tIndex[10+sh], tIndex[11+sh], tIndex[12+sh],
  63.     tIndex[13+sh], tIndex[14+sh], tIndex[15+sh], tIndex[16+sh],
  64.     tIndex[1+sh], tIndex[2+sh], tIndex[3+sh], tIndex[4+sh]
  65.   end
  66.  
  67.   tIndex[1], tIndex[2], tIndex[3], tIndex[4], tIndex[20], tIndex[36], tIndex[52], tIndex[51], tIndex[50], tIndex[49], tIndex[33], tIndex[17] =
  68.   tIndex[4], tIndex[20], tIndex[36], tIndex[52], tIndex[51], tIndex[50], tIndex[49], tIndex[33], tIndex[17], tIndex[1], tIndex[2], tIndex[3]
  69.  
  70.   tIndex[18], tIndex[19], tIndex[35], tIndex[34] = tIndex[19], tIndex[35], tIndex[34], tIndex[18]
  71. end
  72.  
  73. local component = require('component')
  74. local data = component.data
  75.  
  76. local hsh = data.md5(table.concat(tIndex, ' '))
  77. local tr = 1
  78. perm()
  79. while hsh ~= data.md5(table.concat(tIndex, ' ')) do
  80.   perm()
  81.   tr = tr + 1
  82. end
  83. print(tr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement