feat: Enhance exploration logic to prioritize unvisited directions and improve movement efficiency
This commit is contained in:
67
turtle.lua
67
turtle.lua
@@ -673,48 +673,55 @@ 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
|
for i = 1, 4 do
|
||||||
local bestDirection = nil
|
if state.position then
|
||||||
|
local testPos = {x = state.position.x, y = state.position.y, z = state.position.z}
|
||||||
-- Check all 4 directions to find best unvisited one
|
if facing == 0 then testPos.z = testPos.z - 1
|
||||||
for i = 1, 4 do
|
elseif facing == 1 then testPos.x = testPos.x + 1
|
||||||
if state.position then
|
elseif facing == 2 then testPos.z = testPos.z + 1
|
||||||
local testPos = {x = state.position.x, y = state.position.y, z = state.position.z}
|
elseif facing == 3 then testPos.x = testPos.x - 1
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Turn and check next direction
|
if not hasVisited(testPos) then
|
||||||
smartTurnRight()
|
-- Found unvisited direction!
|
||||||
|
local hasBlock = turtle.inspect()
|
||||||
|
if hasBlock then
|
||||||
|
smartDig("forward")
|
||||||
|
end
|
||||||
|
if smartForward() then
|
||||||
|
foundUnvisited = true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- All directions visited, just pick one and go
|
-- Only turn if we haven't found a direction yet
|
||||||
smartDig("forward")
|
if i < 4 then
|
||||||
smartForward()
|
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
|
end
|
||||||
|
|
||||||
-- 15% down (only if safe and not too deep)
|
-- 15% down (only if safe and not too deep)
|
||||||
|
|||||||
Reference in New Issue
Block a user