Compare commits

...

3 Commits

Author SHA1 Message Date
Dominic Zimmer
cfb3074158 Add testing script.py 2020-07-09 10:14:48 +02:00
Dominic Zimmer
e84d807957 Merge branch 'master' of leafbla.de:dominic/turtles 2020-07-09 10:14:34 +02:00
Dominic Zimmer
035ab99fcc Update client for lava/water 2020-07-09 10:14:29 +02:00
2 changed files with 46 additions and 4 deletions

View File

@ -14,8 +14,10 @@ def unpairZ(z):
lookup = [-10, 4, 1, 3, 0, 2] lookup = [-10, 4, 1, 3, 0, 2]
def isDiggingSpot(x, y): def isDiggingSpot(x, y):
val = lookup[(y % 5) + 1] x, y = int(x), int(y)
return (x % 5) == val val = lookup[(((y % 5)+5)%5) + 1]
out = ((x % 5)+ 5) % 5 == val
return out
global offset global offset
offset = 10 offset = 10
@ -30,4 +32,33 @@ def ithSpot(i):
else: else:
i = i - 1 i = i - 1
j = j + 1 j = j + 1
def adjustToQuadrant(i, x, z):
if i % 4 == 0:
return x, z
elif i % 4 == 1:
return -z-1, x
elif i % 4 == 2:
return z, -x-1
elif i % 4 == 3:
return -z-1, -x-1
def iTo2Dcoords(j):
i = j // 4
quadrantI = j % 4 # 0-3 quadrant
counter = 0 # number of digging spots found
j = 0 # enumerate 2D plane
while True:
x, z = int(unpairX(j)), int(unpairZ(j)) # coords in first quadrant
x, z = adjustToQuadrant(quadrantI, x, z) # map coords correctly into other quadrants
if isDiggingSpot(x, z):
if counter == i:
return (x,z)
break
counter += 1
j += 1
print(iTo2Dcoords(3))
# for i in range(10):
# print(iTo2Dcoords(i))

View File

@ -106,6 +106,13 @@ function moveSafe(moveAction, inspectAction, digAction)
if block["name"]:lower():find("turtle") then if block["name"]:lower():find("turtle") then
-- turtle in front of me. lets wait for it to move -- turtle in front of me. lets wait for it to move
sleep(0.6) sleep(0.6)
elseif block["name"]:lower().find("water") or block["name"]:lower().find("lava") then
if moveAction() then
break
else
digAction()
updateState({ state = "I am stuck trying to walk into a liquid." })
end
else else
digAction() digAction()
end end
@ -414,13 +421,17 @@ function drawStatus()
print() print()
print(" \""..turtlestate["name"].."\"") print(" \""..turtlestate["name"].."\"")
print() print()
print()
if turtlestate["job"] then if turtlestate["job"] then
print("Current job: "..tostring(turtlestate["job"])) print("Current job: "..tostring(turtlestate["job"]))
else else
print("Current job: ") print("Current job: ")
end end
print() print()
if turtle["startfuel"] then
print("Starting Fuel: "..tostring(turtlestate["startfuel"]))
else
print("Starting Fuel: ")
end
if turtlestate["job"] then if turtlestate["job"] then
print("Recent fuel usage: "..tostring(turtlestate["fuel"])) print("Recent fuel usage: "..tostring(turtlestate["fuel"]))
else else
@ -674,7 +685,7 @@ function turtleAI2()
local job = enqueueForJob2() local job = enqueueForJob2()
turtlestate["job"] = job turtlestate["job"] = job
doRefuel2() doRefuel2()
startfuel = turtle.getFuelLevel() turtlestate["startfuel"] = turtle.getFuelLevel()
goToJob2(job) goToJob2(job)
digShaft() digShaft()
goToUnloading() goToUnloading()