Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function odd (number)
- if (number % 2) == 0 then
- return false
- else
- return true
- end
- end
- function prime (n)
- for i=2, n ^ (1 / 2) do
- if (n % i) == 0 then
- return false
- end
- return true
- end
- end
- function getSectors (x, y, turtleAmount)
- turtleAmount = tonumber (turtleAmount)
- turtleAmount2 = tonumber (turtleAmount)
- turtleAmount3 = tonumber (turtleAmount)
- x = tonumber (x)
- y = tonumber (y)
- print ("Arguments: " .. x .. ", " .. y .. ", " .. turtleAmount)
- totalArea = x * y
- print ("Total Sector Area: " .. totalArea)
- local l = true
- local w = true
- local j = 2
- local m = 2
- local g = false
- if prime (totalArea) == true or odd (x) == true and odd (y) == true then
- sectorCount = 1
- length = length
- width = width
- else
- repeat
- if (x % turtleAmount3) == 0 then
- l = false
- else
- turtleAmount3 = turtleAmount3 - 1
- l = true
- end
- sleep (0.5)
- until l == false
- turtlesPerX = turtleAmount3
- repeat
- if (y % turtleAmount2) == 0 then
- w = false
- else
- turtleAmount2 = turtleAmount2 - 1
- w = true
- end
- sleep (0.5)
- until w == false
- turtlesPerY = turtleAmount2
- print ("Debug: x = " .. turtlesPerX)
- print ("Debug: y = " .. turtlesPerY)
- length = x / turtlesPerX
- width = y / turtlesPerY
- areaPerSector = width * length
- sectorCount = totalArea / areaPerSector
- if sectorCount > turtleAmount then
- print ("Too many sectors, attempting to lower sector amount (will use less turtles)")
- repeat
- repeat
- length = length+1
- until x % length == 0
- repeat
- width=width+1
- until y % width == 0
- areaPerSector = width * length
- sectorCount = totalArea / areaPerSector
- print ("getSectors sectorCount Debug: " .. sectorCount)
- turtlesPerX = x / length
- print ("getSectors sectorsPerX Debug: " .. turtlesPerX)
- turtlesPerY = y / width
- print ("getSectors sectorsPerY Debug: " .. turtlesPerY)
- sleep (2)
- print ("getSectors length Debug: " .. length)
- print ("getSectors width Debug: " .. width)
- until sectorCount <= turtleAmount
- end
- end
- return length, width, sectorCount, turtlesPerX, turtlesPerY
- end
- ------Uses basic math to find the coordinates that each turtle will be deployed to
- function getDeploymentCoords (sectorsPerRow, sectorsPerColumn, x, y, length, width, turtleCountNeeded)
- local deploymentTable = {}
- local xCoords = {}
- local sectorsPerRow = tonumber (sectorsPerRow)
- local sectorsPerColumn = tonumber (sectorsPerColumn)
- local x = x
- local y = y
- local j = 1
- local k = 1
- local l = 1
- local yCoords = {}
- print ("getDeploymentCoords sectorsPerRow Debug: " .. sectorsPerRow)
- print ("getDeploymentCoords sectorsPerColumn Debug: " .. sectorsPerColumn)
- for i=1, tonumber (sectorsPerRow) do
- for i=1, sectorsPerColumn do
- print ("getDeploymentCoords x Debug: " .. length)
- table.insert (xCoords, length)
- length = length + x
- sleep (2)
- end
- width = width + y
- print ("getDeploymentCoords x Debug: " .. width)
- table.insert (yCoords, width)
- sleep (2)
- end
- for i=1, sectorsPerRow do
- for i=1, sectorsPerColumn do
- table.insert (deploymentTable, xCoords[j])
- sleep (0.1)
- table.insert (deploymentTable, yCoords[k])
- print ("getDeploymentCoords xCoords Debug :" .. xCoords[j])
- print ("getDeploymentCoords yCoords Debug: " .. yCoords[k])
- j = j + 1
- end
- end
- k = k + 1
- return deploymentTable
- end
- print ("Length of quarry?")
- x = read ()
- print ("Width of quarry?")
- y = read ()
- print ("Amount of turtles?")
- turtleCount = io.read ()
- print ("What is your x coordinate?")
- plrXPos = read ()
- print ("What is your y coordinate?")
- plrYPos = read ()
- term.clear ()
- length, width, sectorCount, sectorPerColumn, sectorPerRow = getSectors (x, y, turtleCount)
- print (sectorPerColumn)
- print (sectorPerRow)
- deploymentCoords = getDeploymentCoords (sectorPerRow, sectorPerColumn, length, width, plrXPos, plrYPos, turtleCount)
- for i, v in pairs (deploymentCoords) do
- print (v)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement