diff --git a/build.lua b/build.lua index b55c670..f352f64 100644 --- a/build.lua +++ b/build.lua @@ -121,3 +121,5 @@ if mode == 'center' then else move_back_to_top_corner(grid) end + +file:close() diff --git a/build_circle.lua b/build_circle.lua new file mode 100644 index 0000000..bfceba1 --- /dev/null +++ b/build_circle.lua @@ -0,0 +1,95 @@ +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) + +-- 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 + robot.select(robot.select() + 1) -- select the next item slot + 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() diff --git a/rings b/rings new file mode 100644 index 0000000..4637312 --- /dev/null +++ b/rings @@ -0,0 +1,6 @@ +25 +82222111X1122227 +82222111X11122227 +822221111X11122227 +83322211X1222337 +83322211X11222337