This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mendax's profile picture

Turtleai

Started by Mendax, 25 February 2012 - 09:21 PM
Mendax #1
Posted 25 February 2012 - 10:21 PM
TurtleAI
By Shadow

Wanderer AI
Essentially this is and I quote 'a blind & drunk' turtle AI. It is my first AI so, it is very simple. It just picks a random direction and goes in it.
[media]http://www.youtube.com/watch?v=UGj5on0EduQ[/media]
Download: http://www.4shared.c.../Wander_AI.html

Pathfinder AI
This a somewhat a more advanced AI than the Wanderer. When it detects a wall, it either turns left or right. The constant 1 direction bug in the video is fixed.
[media]http://www.youtube.com/watch?v=8tQyEhSzrGQ[/media]
Pathfinder goin through a maze:
[media]http://www.youtube.com/watch?v=TS2hu9TSO1M&feature=youtu.be[/media]
Download: http://www.4shared.c...hfinder_AI.html

Pathfinder II
I made a much better version of the pathfinder, coded from scratch, it requires Techzune's TurtleAPI found here: http://www.computerc...zunes-programs/
When it gets to a wall, it checks left and right and then goes either left if right has a block, right if left has a block, and if both sides have a block, it turns around. Also, this is my first proper AI.
[media]http://www.youtube.com/watch?v=MxuWaVW1Zq8&feature=youtu.be[/media]
Download: http://www.4shared.com/file/LVMKg9ma/AI__4_.html
Mendax #2
Posted 26 February 2012 - 12:25 AM
Added a video with a Pathfinder going through a maze.
bonnis #3
Posted 26 February 2012 - 02:46 AM
good program(very nice!)
you should add the code to the topic :)/>/>
Xtansia #4
Posted 26 February 2012 - 04:43 AM
This isn't AI,
Artificial Intelligence means that it makes decisions based on its surroundings(Similar to how a human or animal does) which this does not this just chooses a random direction when it hits a wall.
ficolas #5
Posted 26 February 2012 - 11:30 AM
Yes isnt an AI, but is a start, I will use this for a program called turtlet (turtle pet) but changing some thins
Wojowu #6
Posted 26 February 2012 - 12:59 PM
You can make turtle stop when finding exit. Just add
while turtle.detectDown()==true then <your program> end
If you destroy block on floor on exit program will stop, and after that something can be printed.
Mendax #7
Posted 26 February 2012 - 08:55 PM
This isn't AI,
Artificial Intelligence means that it makes decisions based on its surroundings(Similar to how a human or animal does) which this does not this just chooses a random direction when it hits a wall.
This is in very early development, don't expect an update for a few days though, I have school :/
Mendax #8
Posted 27 February 2012 - 05:40 AM
UPDATE on new AI: It will require Techzune's TurtleAPI
Found here: http://www.computerc...zunes-programs/
It is not here yet though.
Mendax #9
Posted 27 February 2012 - 09:00 PM
Pathfinder II Added, video coming after school. Don't forget to get Techzune's TurtleAPI: http://www.computercraft.info/forums2/index.php?/topic/183-techzunes-programs/
Chub1337 #10
Posted 28 February 2012 - 03:24 PM
How about:

Spoiler

while true do
turtle.turnRight()
if turtle.detect() == true then
  turtle.turnLeft()
  if turtle.detect() == false then
    turtle.forward()
  else
    turtle.turnLeft()
    if turtle.detect() == false then
	  turtle.forward()
    end
  end
else
  turtle.forward()
end
if turtle.detectDown() == false then  --If it hasn't got a block under it anymore, it has reached the exit and stops.
  break
end
sleep(0.1)
end

That uses the 'keep your right hand always on the right wall'-technique. So if it can go right, it will, if it can't, it'll check for going forward and if that is not possible it'll try going left.

This way the bot always comes to the exit, no matter how complicated the maze. (Note, the paths must be 1 wide and the exit must be marked with the absence of a block under the bot.)

This is still a 'dumb'-ai. The real challenge would be mapping the entire maze by walking trough it and then determining the best path. I believe Cruor is trying to achieve that.

-Chub1337
Mendax #11
Posted 28 February 2012 - 08:54 PM
How about:

Spoiler

while true do
turtle.turnRight()
if turtle.detect() == true then
  turtle.turnLeft()
  if turtle.detect() == false then
	turtle.forward()
  else
	turtle.turnLeft()
	if turtle.detect() == false then
	  turtle.forward()
	end
  end
else
  turtle.forward()
end
if turtle.detectDown() == false then  --If it hasn't got a block under it anymore, it has reached the exit and stops.
  break
end
sleep(0.1)
end

That uses the 'keep your right hand always on the right wall'-technique. So if it can go right, it will, if it can't, it'll check for going forward and if that is not possible it'll try going left.

This way the bot always comes to the exit, no matter how complicated the maze. (Note, the paths must be 1 wide and the exit must be marked with the absence of a block under the bot.)

This is still a 'dumb'-ai. The real challenge would be mapping the entire maze by walking trough it and then determining the best path. I believe Cruor is trying to achieve that.

-Chub1337
Yes, but the idea is not to remove a block. So… yeah…
Chub1337 #12
Posted 28 February 2012 - 09:13 PM
Yes, but the idea is not to remove a block. So… yeah…

What do you mean? This doesn't remove blocks?

-Chub1337
Mendax #13
Posted 29 February 2012 - 05:01 AM
Yes, but the idea is not to remove a block. So… yeah…

What do you mean? This doesn't remove blocks?

-Chub1337
No, It's not supposed to. Also, I fixed the always go left in my AI, These AIs were not made for the one purpose of going through mazes Dx
Chub1337 #14
Posted 29 February 2012 - 09:29 AM
Yes, but the idea is not to remove a block. So… yeah…

What do you mean? This doesn't remove blocks?

-Chub1337
No, It's not supposed to. Also, I fixed the always go left in my AI, These AIs were not made for the one purpose of going through mazes Dx

I still don't get it, where in this code does it remove a block?

Code:

while true do
turtle.turnRight()
if turtle.detect() == true then
  turtle.turnLeft()
  if turtle.detect() == false then
		turtle.forward()
  else
		turtle.turnLeft()
		if turtle.detect() == false then
		  turtle.forward()
		end
  end
else
  turtle.forward()
end
if turtle.detectDown() == false then  --If it hasn't got a block under it anymore, it has reached the exit and stops.
  break
end
sleep(0.1)
end

it only detects blocks, and if there is none, it'll move forward (since there is no block, thus a path).
Also , the part where it detects down, this is to check if it's at the finish, it doesn't break the block underneath it, it breaks the loop.

break
is for breaking a loop, like here it breaks the

while true do
end
loop, otherwise it would continue forever.


turtle.dig()
is for breaking blocks :o/>/>

-Chub1337
Mendax #15
Posted 01 March 2012 - 08:40 AM
Yes, but the idea is not to remove a block. So… yeah…

What do you mean? This doesn't remove blocks?

-Chub1337
No, It's not supposed to. Also, I fixed the always go left in my AI, These AIs were not made for the one purpose of going through mazes Dx

I still don't get it, where in this code does it remove a block?

Code:

while true do
turtle.turnRight()
if turtle.detect() == true then
  turtle.turnLeft()
  if turtle.detect() == false then
		turtle.forward()
  else
		turtle.turnLeft()
		if turtle.detect() == false then
		  turtle.forward()
		end
  end
else
  turtle.forward()
end
if turtle.detectDown() == false then  --If it hasn't got a block under it anymore, it has reached the exit and stops.
  break
end
sleep(0.1)
end

it only detects blocks, and if there is none, it'll move forward (since there is no block, thus a path).
Also , the part where it detects down, this is to check if it's at the finish, it doesn't break the block underneath it, it breaks the loop.

break
is for breaking a loop, like here it breaks the

while true do
end
loop, otherwise it would continue forever.


turtle.dig()
is for breaking blocks :unsure:/>/>

-Chub1337
I said it before, this is not for just going through mazes, I like doing other stuff with it.