Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- height,width,length = 16,15,8
- startx,starty,startz = 0,0,0
- finalx,finaly,finalz = 15,14,7
- shell.run("3opt")
- blocks = textutils.unserialize( fs.open("blocks","r").readAll() )
- data = textutils.unserialize( fs.open("data","r").readAll() )
- getBlockId = function(x,y,z)
- return blocks[y + z*width + x*length*width + 1]
- end
- getData = function(x,y,z)
- return data[y + z*width + x*length*width + 1]
- end
- --deconstruct
- instructions = textutils.unserialize( fs.open("instructions","r").readAll() )
- local function instructions2layers(instructions)
- local layers = {}
- for x = startx,finalx do
- layers[x] = {}
- for n=1,#instructions do
- if instructions[n][1] == x then
- table.insert(layers[x],{unpack(instructions[n],1,3)})
- end
- end
- end
- return layers
- end
- function printNodes(nodes)
- for i,v in pairs(nodes) do
- textutils.pagedPrint("["..i.."] = {"..v[1]..","..v[2]..","..v[3].."}")
- end
- end
- function slowNodes(nodes)
- for i,v in pairs(nodes) do
- term.setCursorPos(v[2],v[3])
- term.setBackgroundColor(2^getData(unpack(v)))
- term.write(" ")
- sleep(0)
- end
- end
- function slowSimulate(layers)
- shell.run("clr")
- for i = startx,finalx do
- slowNodes(layers[i])
- term.setBackgroundColor(colors.black)
- shell.run("clr")
- end
- end
- function simulateIns(instructions)
- local lastx = 0
- shell.run("clr")
- for n = 1,#instructions do
- if lastx~=instructions[n][1] then
- term.setBackgroundColor(colors.black)
- shell.run("clr")
- end
- term.setCursorPos(instructions[n][2]+1,instructions[n][3]+1)
- term.setBackgroundColor(2^instructions[n][5])
- term.write(" ")
- lastx = instructions[n][1]
- sleep(0)
- end
- end
- --textutils.pagedPrint(textutils.serialize(layers))
- --printNodes(layers[0])
- local function organize(layers)
- local startingPosition = {startx,starty,startz}
- for x = startx,finalx do
- table.insert(layers[x],1,startingPosition)
- layers[x] = tsp_algorithm(layers[x])
- startingPosition = layers[x][#layers[x]]
- --startingPosition[1] = startingPosition[1] + 1
- end
- return layers
- end
- local function layers2instructions(layers)
- local instructions = {}
- --organizedlayers only
- for x = startx,finalx do
- for i = 2,#layers[x] do
- table.insert(instructions,layers[x][i])
- end
- end
- return instructions
- end
- local function add_id_and_data(instructions)
- for n = 1,#instructions do
- instructions[n][4] = getBlockId(unpack(instructions[n],1,3))
- instructions[n][5] = getData(unpack(instructions[n],1,3))
- end
- return instructions
- end
- layers = instructions2layers(instructions)
- layers = organize(layers)
- new_instructions = layers2instructions(layers)
- new_instructions = add_id_and_data(new_instructions)
- --slowSimulate(layers)
- --printNodes(layers[1])
- --textutils.pagedPrint(textutils.serialize(instructions))
- --for i,v in pairs(new_instructions) do
- --textutils.pagedPrint(i..": "..v[1]..","..v[2]..","..v[3]..","..v[4]..","..v[5])
- --end
- simulateIns(new_instructions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement