local robot = require('robot') local nav = require('nav') local io = require('io') local filename = ... if not filename then print('Usage: build_circle ') print('The robot starts in the center') return 1 end local file = io.open(filename, 'r') if not file then print('File not found') return 2 end local radius = tonumber(file:read("*l")) if not radius then print('Requires radius on the first line') return 3 end local rings = {} -- parse file: for line in file:lines() do local ring = {} for c in string.gmatch(line, ".") do local n = tonumber(c) if c == 'X' then ring[#ring + 1] = c elseif n then ring[#ring + 1] = n else print('Invalid sequence: ' .. c) return 4 end end rings[#rings + 1] = ring end file:close() local inverted = false robot.select(1) local inventorySize = robot.inventorySize() -- build: nav.forward(radius) robot.turnRight() for _, ring in ipairs(rings) do for _ = 1, 4 do inverted = false for i, n in ipairs(ring) do if n == 'X' then robot.turnRight() inverted = true else -- place sequence for _ = 1, n do robot.placeDown() if robot.count() == 0 then local current_slot = robot.select() if current_slot == inventorySize then print('Waiting for more materials') local _ = io.read() robot.select(1) else robot.select(current_slot + 1) -- select the next item slot if robot.count() == 0 then print('Waiting for more materials') local _ = io.read() end end end nav.forward() end if i ~= #ring then -- step level if not inverted then robot.turnRight() nav.forward() robot.turnLeft() else robot.turnLeft() nav.forward() robot.turnRight() end end end end end robot.turnLeft() nav.forward() robot.turnRight() end robot.turnRight() nav.forward(radius + #rings) robot.turnAround()