Advertisement
Blazuno

Untitled

Nov 3rd, 2021 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. function odd (number)
  2. if (number % 2) == 0 then
  3. return false
  4. else
  5. return true
  6. end
  7. end
  8.  
  9. function prime (n)
  10. for i=2, n ^ (1 / 2) do
  11. if (n % i) == 0 then
  12. return false
  13. end
  14. return true
  15. end
  16. end
  17.  
  18. function getSectors (x, y, turtleAmount)
  19. turtleAmount = tonumber (turtleAmount)
  20. turtleAmount2 = tonumber (turtleAmount)
  21. turtleAmount3 = tonumber (turtleAmount)
  22. x = tonumber (x)
  23. y = tonumber (y)
  24. print ("Arguments: " .. x .. ", " .. y .. ", " .. turtleAmount)
  25. totalArea = x * y
  26. print ("Total Sector Area: " .. totalArea)
  27. local l = true
  28. local w = true
  29. local j = 2
  30. local m = 2
  31. local g = false
  32. if prime (totalArea) == true or odd (x) == true and odd (y) == true then
  33. sectorCount = 1
  34. length = length
  35. width = width
  36. else
  37. repeat
  38. if (x % turtleAmount3) == 0 then
  39. l = false
  40. else
  41. turtleAmount3 = turtleAmount3 - 1
  42. l = true
  43. end
  44. sleep (0.5)
  45. until l == false
  46. turtlesPerX = turtleAmount3
  47. repeat
  48. if (y % turtleAmount2) == 0 then
  49. w = false
  50. else
  51. turtleAmount2 = turtleAmount2 - 1
  52. w = true
  53. end
  54. sleep (0.5)
  55. until w == false
  56. turtlesPerY = turtleAmount2
  57. print ("Debug: x = " .. turtlesPerX)
  58. print ("Debug: y = " .. turtlesPerY)
  59. length = x / turtlesPerX
  60. width = y / turtlesPerY
  61. areaPerSector = width * length
  62. sectorCount = totalArea / areaPerSector
  63. if sectorCount > turtleAmount then
  64. print ("Too many sectors, attempting to lower sector amount (will use less turtles)")
  65. repeat
  66. repeat
  67. length = length+1
  68. until x % length == 0
  69. repeat
  70. width=width+1
  71. until y % width == 0
  72. areaPerSector = width * length
  73. sectorCount = totalArea / areaPerSector
  74. print ("getSectors sectorCount Debug: " .. sectorCount)
  75. turtlesPerX = x / length
  76. print ("getSectors sectorsPerX Debug: " .. turtlesPerX)
  77. turtlesPerY = y / width
  78. print ("getSectors sectorsPerY Debug: " .. turtlesPerY)
  79. sleep (2)
  80. print ("getSectors length Debug: " .. length)
  81. print ("getSectors width Debug: " .. width)
  82. until sectorCount <= turtleAmount
  83. end
  84. end
  85. return length, width, sectorCount, turtlesPerX, turtlesPerY
  86. end
  87.  
  88.  
  89. ------Uses basic math to find the coordinates that each turtle will be deployed to
  90. function getDeploymentCoords (sectorsPerRow, sectorsPerColumn, x, y, length, width, turtleCountNeeded)
  91. local deploymentTable = {}
  92. local xCoords = {}
  93. local sectorsPerRow = tonumber (sectorsPerRow)
  94. local sectorsPerColumn = tonumber (sectorsPerColumn)
  95. local x = x
  96. local y = y
  97. local j = 1
  98. local k = 1
  99. local l = 1
  100. local yCoords = {}
  101. print ("getDeploymentCoords sectorsPerRow Debug: " .. sectorsPerRow)
  102. print ("getDeploymentCoords sectorsPerColumn Debug: " .. sectorsPerColumn)
  103. for i=1, tonumber (sectorsPerRow) do
  104. for i=1, sectorsPerColumn do
  105. print ("getDeploymentCoords x Debug: " .. length)
  106. table.insert (xCoords, length)
  107. length = length + x
  108. sleep (2)
  109. end
  110. width = width + y
  111. print ("getDeploymentCoords x Debug: " .. width)
  112. table.insert (yCoords, width)
  113. sleep (2)
  114. end
  115. for i=1, sectorsPerRow do
  116. for i=1, sectorsPerColumn do
  117. table.insert (deploymentTable, xCoords[j])
  118. sleep (0.1)
  119. table.insert (deploymentTable, yCoords[k])
  120. print ("getDeploymentCoords xCoords Debug :" .. xCoords[j])
  121. print ("getDeploymentCoords yCoords Debug: " .. yCoords[k])
  122.  
  123. j = j + 1
  124. end
  125. end
  126. k = k + 1
  127. return deploymentTable
  128. end
  129.  
  130.  
  131.  
  132. print ("Length of quarry?")
  133. x = read ()
  134. print ("Width of quarry?")
  135. y = read ()
  136. print ("Amount of turtles?")
  137. turtleCount = io.read ()
  138. print ("What is your x coordinate?")
  139. plrXPos = read ()
  140. print ("What is your y coordinate?")
  141. plrYPos = read ()
  142.  
  143. term.clear ()
  144. length, width, sectorCount, sectorPerColumn, sectorPerRow = getSectors (x, y, turtleCount)
  145. print (sectorPerColumn)
  146. print (sectorPerRow)
  147. deploymentCoords = getDeploymentCoords (sectorPerRow, sectorPerColumn, length, width, plrXPos, plrYPos, turtleCount)
  148. for i, v in pairs (deploymentCoords) do
  149. print (v)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement