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

Getting a turtle to use a sensor, locate a nearby player, and chase them through a maze

Started by PSanf420, 17 November 2012 - 12:02 AM
PSanf420 #1
Posted 17 November 2012 - 01:02 AM
OK, I'm working on an adventure map in Tekkit 3.1.3, which uses ComputerCraft 1.4.1. I'm creating a giant maze, and would like to use some melee turtles to liven things up. I'd like the turtles to detect when a player is nearby in the maze, and then go attack them. Is it possible to get turtles to work with sensors? I've been researching and am not sure if that's going to be included in a future version of ComputerCraft, or if I can just put a sensor control block in a turtle and have it work. Also, does anyone have a script or API that would allow the turtle to learn it's environment and improve it's pathfinding to a specific location? The maze I've built is huge, and it's very possible for a user to trap the turtles by running around a corner. I'd like them to have some obstical avoidence that would allow them to navigate around the walls in search of the player. Finally, the maze featres a lot of leaf blocks in it's construction, and I don't want the turtles to grief the walls when bumping into things. Does anyone know a good way to descriminate targets?
Orwell #2
Posted 17 November 2012 - 03:00 AM
Read the last two pages of this thread:
http://www.computercraft.info/forums2/index.php?/topic/126-mc-125-cc-133-ccsensors-smpssp/page__st__400
and read this thread:
http://www.computercraft.info/forums2/index.php?/topic/5996-144-cc-147-openccsensors/

CCSensors is no longer being maintained, but OpenCCSensors it now a work-in-progress project implementing the same. It only has an inventory reading sensor module for now, but it is being expanded. OpenCCSensors does support sensors as turtle upgrades. It's not for CC 1.4.1 though.
kazagistar #3
Posted 17 November 2012 - 05:01 AM
For pathfinding, I don't exactly know what kind of intelligence you want to give your turtles. Where and why are they pathing to when they are not killing the player? Why not a random walk? If they ARE killing the player, why would they path around the player?

If you want to "learn" the maze, you need to keep track of your location and just make a 3 dimentional table. Then, you can use pathing algorithms as if the table was a graph to find your way around. Look these up on wikipedia if you don't know them.
PSanf420 #4
Posted 18 November 2012 - 03:24 AM
Read the last two pages of this thread:
http://www.computerc...p/page__st__400
and read this thread:
http://www.computerc...-openccsensors/

CCSensors is no longer being maintained, but OpenCCSensors it now a work-in-progress project implementing the same. It only has an inventory reading sensor module for now, but it is being expanded. OpenCCSensors does support sensors as turtle upgrades. It's not for CC 1.4.1 though.

Thankyou for the clarification. Is OpenCCSensors going to be backwards compatable with CCSensors? If so, then I can probably use CCSensors, which is included with Tekkit, and simply update the blocks if Tekkit ever includes OpenCCSensors. This information also let's me know what development options are available to me when working with turtles.
PSanf420 #5
Posted 18 November 2012 - 03:43 AM
For pathfinding, I don't exactly know what kind of intelligence you want to give your turtles. Where and why are they pathing to when they are not killing the player? Why not a random walk? If they ARE killing the player, why would they path around the player?

If you want to "learn" the maze, you need to keep track of your location and just make a 3 dimentional table. Then, you can use pathing algorithms as if the table was a graph to find your way around. Look these up on wikipedia if you don't know them.

When not trying to hunt down and kill the player the turtles would be doing a random walk to learn the maze. When the player gets within a certain distance they should try to follow the shortest path to the player (periodically checking the player's location and updating the optimal path), and attack the player.

I'm just not sure how to go about implementing all of this functionality. Getting the player location to the turtle will need to be accomplished with a centralized computer using a sensor to provide the information. GPS information will be provided to the turtles with the included API in the standard fashion. I can envision learning the maze with a random walk. That would simply entail getting the current GPS coordinates, choosing a direction at random and moving a block, checking the GPS coordinates again to see if the turtle was able to move in that direction, and mapping the results into an array. The data in the array can be mapped to GPS coordinates easily by using a set point on the graph to equate with a coordinate, and then adding or subtracting from that value. The pathfinding is where I get lost, but the article you linked seems to be rather clear. Going about implimenting all of this is another point of confusion. What should the turtle do when it detects the player, but doesn't have all of the information required to get to them because portions of the maze are unexplored? The turtle will need to realize that it's chosen shortest path won't work (because it's gone beyond it's previously explored area), then switch between random walking explorization to increase it's knowlege of it's surroundings and attempting to goto the player to attack them.
Cloudy #6
Posted 18 November 2012 - 04:23 AM
Thankyou for the clarification. Is OpenCCSensors going to be backwards compatable with CCSensors?

Nope - but it will be a lot simpler to use.
PSanf420 #7
Posted 18 November 2012 - 10:52 AM
Thankyou for the clarification. Is OpenCCSensors going to be backwards compatable with CCSensors?

Nope - but it will be a lot simpler to use.

Any idea if/when OpenCCSensors will be replacing CCSensors in Tekkit?
overfritz #8
Posted 18 November 2012 - 12:52 PM
Thankyou for the clarification. Is OpenCCSensors going to be backwards compatable with CCSensors?

Nope - but it will be a lot simpler to use.

Any idea if/when OpenCCSensors will be replacing CCSensors in Tekkit?

Considering that Tekkit relies on ForgeBukkit to operate…I would say as soon as that gets updated for 1.4.x. But that would mean a large loss of mods…so odds are, not for a looong time.