Posted 23 October 2018 - 07:49 PM
So I wanted to program a turtle to go through this labyrinth: https://drive.google.com/open?id=1Tn2FbKSmAMFO8uwVTZCG0ToA3T35ALWS but for some reason it doesn't work… I programmed the turtle to use RNG since I don't know how to program the turtle, to remember the track^^
Thanks for every help.
Code:
repeat
x = false
y = false
z = false
a1 = false
a2 = false
a3 = false
a4 = false
r = false
g = false
turtle.down()
if turtle.detect() then
x = true
else
x = false
end
if x then
print("Front=Positiv")
else
print("Front=Negativ")
end
turtle.turnLeft()
if turtle.detect() then
y = true
else
y = false
end
if y then
print("Links=Positiv")
else
print("Links=Negativ")
end
turtle.turnRight()
turtle.turnRight()
if turtle.detect() then
z = true
else
z = false
end
if z then
print("Rechts=Positiv")
else
print("Rechts=Negativ")
end
turtle.turnLeft()
repeat
repeat
local a = {1, 2, 3}
b = math.random(#a)
print(B)/>
if b == 1 and x then
g = true
end
if b == 2 and y then
turtle.turnLeft()
g = true
end
if b == 3 and z then
turtle.turnRight()
g = true
end
if x and y and z then
turtle.turnLeft()
end
until g == true
if turtle.detect() then
r = false
else
r = true
end
until r == true
turtle.forward()
if turtle.detect() then
a1 = true
end
turtle.turnLeft()
if turtle.detect() then
a2 = true
end
turtle.turnLeft()
if turtle.detect() then
a3 = true
end
turtle.turnLeft()
if turtle.detect() then
a4 = true
end
turtle.turnLeft()
until a1 and a2 and a3 and a4
print("Ziel erreicht")
Thanks for every help.
Code:
repeat
x = false
y = false
z = false
a1 = false
a2 = false
a3 = false
a4 = false
r = false
g = false
turtle.down()
if turtle.detect() then
x = true
else
x = false
end
if x then
print("Front=Positiv")
else
print("Front=Negativ")
end
turtle.turnLeft()
if turtle.detect() then
y = true
else
y = false
end
if y then
print("Links=Positiv")
else
print("Links=Negativ")
end
turtle.turnRight()
turtle.turnRight()
if turtle.detect() then
z = true
else
z = false
end
if z then
print("Rechts=Positiv")
else
print("Rechts=Negativ")
end
turtle.turnLeft()
repeat
repeat
local a = {1, 2, 3}
b = math.random(#a)
print(B)/>
if b == 1 and x then
g = true
end
if b == 2 and y then
turtle.turnLeft()
g = true
end
if b == 3 and z then
turtle.turnRight()
g = true
end
if x and y and z then
turtle.turnLeft()
end
until g == true
if turtle.detect() then
r = false
else
r = true
end
until r == true
turtle.forward()
if turtle.detect() then
a1 = true
end
turtle.turnLeft()
if turtle.detect() then
a2 = true
end
turtle.turnLeft()
if turtle.detect() then
a3 = true
end
turtle.turnLeft()
if turtle.detect() then
a4 = true
end
turtle.turnLeft()
until a1 and a2 and a3 and a4
print("Ziel erreicht")