Building rings

master
D4VID 9 months ago
parent de0b3a8915
commit 64d9792aed

@ -121,3 +121,5 @@ if mode == 'center' then
else
move_back_to_top_corner(grid)
end
file:close()

@ -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 <filename>')
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()

@ -0,0 +1,6 @@
25
82222111X1122227
82222111X11122227
822221111X11122227
83322211X1222337
83322211X11222337
Loading…
Cancel
Save