Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local comp = require("component")
- local robot = require("robot")
- local tun = comp.tunnel
- local explored = {}
- local dirX = {0,1,0,-1}
- local dirY = {-1,0,1,0}
- local function getOff(dir, addDir)
- local resDir = (dir + addDir) % 4
- return dirX[resDir + 1], dirY[resDir+1]
- end
- local function isExplored(x, y)
- if explored[x] == nil then
- return false
- end
- return explored[x][y] == true
- end
- local function setExplored(x, y)
- if explored[x] == nil then
- explored[x] = {}
- end
- explored[x][y] = true
- end
- local function sendCmd(cmd, x, y)
- tun.send(cmd, x, y)
- end
- local function explore(x, y, dir)
- setExplored(x,y)
- sendCmd("in", x, y)
- for cd = 0, 3 do
- local xo, yo = getOff(dir, cd)
- if robot.detect() then
- sendCmd("block", x + xo, y + yo)
- else
- if not isExplored(x + xo, y + yo) then
- robot.forward()
- explore(x + xo, y + yo, (dir + cd)%4)
- end
- end
- robot.turnRight()
- end
- sendCmd("out", x , y)
- robot.back()
- end
- explore(0,0,0)
- sendCmd("end", 0, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement