From c26ab898f0693bf73b61526c02adbdc9a28e72f7 Mon Sep 17 00:00:00 2001 From: Justus Wolff Date: Sun, 15 Feb 2026 19:43:14 +0100 Subject: [PATCH] keep direction for an more optimised moving scheme --- src/main.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.lua b/src/main.lua index d7224eb..ec2364b 100644 --- a/src/main.lua +++ b/src/main.lua @@ -292,45 +292,43 @@ local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling) end return selected end -local function moveto(x,y,cx,cz) - local direction = 0 - local function center(wanted) +local function center(direction, wanted) if direction == 1 and wanted ~= 1 then move("left") end if direction == -1 and wanted ~= -1 then move("right") end - end +end +local function moveto(x,y,cx,cz,direction) while x ~= cx or y ~= cz do if x > cx then -- x - center() + center(direction) cx = cx + 1 move("forward") end if x < cx then - center() + center(direction) cx = cx - 1 move("back") end if y > cz then -- z - center(1) + center(direction, 1) cz = cz + 1 move("right") move("forward") direction = 1 end if y < cz then - center(-1) + center(direction, -1) cz = cz - 1 move("left") move("forward") direction = -1 end end - center() - return cx,cz + return cx,cz,direction end local function printdes(buf, dimensions) move("up") @@ -338,13 +336,14 @@ local function printdes(buf, dimensions) local cx = 1 local cz = 1 + local direction = 0 for cy=1,dimensions["y"],1 do for _=1,3,1 do -- build walls local pbuf = {} while true do local target = getnearestunplaced(buf, pbuf, cx,cy,cz,nil, dimensions["x"],dimensions["z"], false) if not target then break end - cx,cz = moveto(target[1],target[2],cx,cz) + cx,cz = moveto(target[1],target[2],cx,cz,direction) place("down") pbuf[posasstring(cx,cy,cz)] = true end @@ -376,16 +375,17 @@ local function printdes(buf, dimensions) -- build ceiling/floor for _cz=1,dimensions["z"],1 do for _cx=1,dimensions["x"],1 do - moveto(_cx,_cz,cx,cz) + moveto(_cx,_cz,cx,cz,direction) if buf[posasstring(_cx,cy,_cz)] ~= 2 then place("down") end end end -- return to standard pos but +1 to y - moveto(1,1,cx,cz) + moveto(1,1,cx,cz,direction) move("up") end + center(direction) end while true do