feat: Enhance exploration logic to prioritize unvisited directions and improve movement efficiency

This commit is contained in:
MayaTheShy
2026-02-19 22:36:15 -05:00
parent aa0884f1d8
commit 23259a5410

View File

@@ -673,23 +673,18 @@ local function exploreStep()
-- 75% of the time: horizontal exploration (forward movement + turns) -- 75% of the time: horizontal exploration (forward movement + turns)
if r < 75 then if r < 75 then
-- Try to move forward -- Try to move forward if unvisited
if not hasBlockForward or not forwardVisited then if not forwardVisited then
if hasBlockForward then if hasBlockForward then
smartDig("forward") smartDig("forward")
end end
if smartForward() then if smartForward() then
-- Successfully moved forward
return return
end end
end end
-- If forward is blocked or visited, try turning to find unvisited direction -- If forward is visited, try to find an unvisited direction
if forwardVisited or hasBlockForward then local foundUnvisited = false
local turnAttempts = 0
local bestDirection = nil
-- Check all 4 directions to find best unvisited one
for i = 1, 4 do for i = 1, 4 do
if state.position then if state.position then
local testPos = {x = state.position.x, y = state.position.y, z = state.position.z} local testPos = {x = state.position.x, y = state.position.y, z = state.position.z}
@@ -701,20 +696,32 @@ local function exploreStep()
if not hasVisited(testPos) then if not hasVisited(testPos) then
-- Found unvisited direction! -- Found unvisited direction!
if not turtle.inspect() then local hasBlock = turtle.inspect()
smartForward() if hasBlock then
smartDig("forward")
end
if smartForward() then
foundUnvisited = true
return return
end end
end end
end end
-- Turn and check next direction -- Only turn if we haven't found a direction yet
if i < 4 then
smartTurnRight() smartTurnRight()
end end
end
-- All directions visited, just pick one and go -- If all directions visited, just move forward anyway (dig if needed)
if not foundUnvisited then
if hasBlockForward then
smartDig("forward") smartDig("forward")
smartForward() end
if not smartForward() then
-- Can't move forward at all, turn once and try again next step
smartTurnRight()
end
end end
-- 15% down (only if safe and not too deep) -- 15% down (only if safe and not too deep)