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