diff options
Diffstat (limited to 'sorter.lua')
-rw-r--r-- | sorter.lua | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -105,39 +105,56 @@ local function runErrands() move(state.park_pos, state.start_pos, state.safe_y, true) move(state.start_pos, state.sort_pos, state.safe_y) - local current_pos = state.sort_pos - for _, next_pos in pairs(state.coords) do - move(current_pos, next_pos, state.safe_y) - current_pos = next_pos - end + inv_utils.fillTurtle() + local oneMoreRound = inv_utils.hasItemsInTurtle() + while (oneMoreRound) do + local current_pos = state.sort_pos + for _, next_pos in pairs(state.coords) do + move(current_pos, next_pos, state.safe_y) + current_pos = next_pos + inv_utils.storeIdenticalItemsInStorage() + + if not inv_utils.hasItemsInTurtle() then + break + end + end - if inv_utils.hasItemsInTurtle() then - move(current_pos, state.leftover_pos, state.safe_y) - move(state.leftover_pos, state.start_pos, state.safe_y) - else - move(current_pos, state.start_pos, state.safe_y) + if inv_utils.hasItemsInTurtle() then + move(current_pos, state.leftover_pos, state.safe_y) + inv_utils.emptyTurtle() + move(state.leftover_pos, state.sort_pos, state.safe_y) + else + move(current_pos, state.sort_pos, state.safe_y) + end + + + inv_utils.fillTurtle() + oneMoreRound = inv_utils.hasItemsInTurtle() end + move(state.sort_pos, state.start_pos, state.safe_y) move(state.start_pos, state.park_pos, state.safe_y, true) end local function run() - local result = true --runDiagnostics() + local result = runDiagnostics() if not result then return nil end write("Start? (y/N) ") - local response = "y"--read() + local response = read() local firstChar = string.sub(response, 1, 1) if firstChar == "y" or firstChar == "Y" then print("Started sorting.") - --refuel.refuel() + refuel.refuel() runErrands() else print("Aborted.") return nil end + + os.shutdown() end return { run = run } |