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

[Questions] 625 Turtles bugs

Started by MrZiggyStardust, 22 October 2012 - 06:06 PM
MrZiggyStardust #1
Posted 22 October 2012 - 08:06 PM
Okay let me preface this by saying I'm a computer science major and I'm intensively trying to push the limits of ComputerCraft to do O(n) maze generation. I work with odd numbered square mazes, I managed to make a 9x9 maze randomly generated that only takes 10 seconds to make, but that's childs play and only used 81 turtles. Now I'm using the same algorithm on a 25x25 maze with 625 turtles all running the same program on startup. I have a function that makes them all mine up while they detect a block above them in order to create their x&y positions. (I'm using white wool for x and black wool for y so when they mine up they store it in their inventory so when they get a function call they can check if it's for them or not with their x/y positions).

When I run the mine up function on all 625 turtles they all start mining up, then a random number of them just stop even though there is a block above them and the rest successfully finish mining.

Here is the code they all run on startup:

function set()
  x=0
  while turtle.detectUp() do
    print(tostring(x))
    turtle.digUp()
    turtle.up()
sleep(1)
x=x+1
  end
  for i=1, x do
    turtle.down()
  end
  turtle.placeUp()
end
function reset ()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.down()
  turtle.down()
  turtle.placeUp()
end
function wall(a)
  id,msg=rednet.recieve
  if tonumber(msg)==(turtle.getItemCount(3)+(turtle.getItemCount(4)*a)) then
    turtle.digUp()
    turtle.up()
    turtle.digUp()
    turtle.up()
    turtle.select(2)
    turtle.placeUp()
    turtle.down()
    turtle.placeUp()
    turtle.down()
    turtle.select(1)
    turtle.placeUp()
  end
end
function getmod ()
  id,msg=rednet.recieve()
  return tonumber(msg)
end
rednet.open("right")
mdf=0
while true do
  id,msg = rednet.receive()
  if msg == "setMaze" then
    set()
  end
  if msg == "resetMaze" then
    reset()
  end
  if msg == "wallMaze" then
    wall(mdf)
  end
  if msg == "modifyMaze" then
    mdf = getmod()
  end
end

Then I open rednet on a computer terminal and send "setMaze" and they all start mining up and about half of them stop after one block, (They're never the same turtles though)

Can rednet only go so far? The turtles closest to the terminal usually work, so does rednet have a range, or can only so many turtles run the same program at once without issues?

Any help would be appreciated, I spent ~12 hours straight yesterday doing cool shit in computercraft and I really want this to work.
cant_delete_account #2
Posted 22 October 2012 - 08:44 PM
RedNet has a range of 64 blocks by default. You can change that in the config though.
cant_delete_account #3
Posted 22 October 2012 - 08:46 PM
Oh, and you have a few errors in your code,
like rednet.recieve() should be rednet.receive() and you missed ()'s on one of the rednet.receive.
OmegaVest #4
Posted 22 October 2012 - 08:54 PM
About the range, it can be changed by putting the sender terminal higher up. Or, make a relay really high up. At Sky limit, the range is something like 384 blocks, which will, at bedrock, still reach about 80 blocks in any direction. If my math is still right. So, supposing that is the problem, just put a relay up there, and have some fun. Or, make your GPS satellite up there.


For turtle limits, I think that mostly depends on your own computer. Mine can only handle about 40 computers with while true do loops before it goes nuts and crashes them. If I have a whole bunch of idle machines that sleep and pick up again (which still uses while true do, but without any other code between it and the timer) I can get up to 60, possibly more if I was a better coder.
Cloudy #5
Posted 22 October 2012 - 08:56 PM
What version of ComputerCraft are you using?
ChunLing #6
Posted 22 October 2012 - 08:57 PM
Altitude makes a difference as well, if there isn't a thunderstorm occurring.
MrZiggyStardust #7
Posted 22 October 2012 - 09:08 PM
I set all the ranges to 9000, I moved the computer to the center of my mass of turtles and fixed all the rednet.receive() issues, and still only the left half seems to want to do anything and a few on the right half seem to want to move. My computer doesn't slow down at all when they all start moving, I should be able to handle 625 turtles just moving up, I'm running a QuadCore PhenomX4 Black and a Geforce 550Ti, not remarkable but should slaughter anything minecraft wants to do.

Any ideas of what else it could possibly be? I know they all enter the function because they all start moving, just about half of them stop after one block. Startup just starts a file I created in the turtleAPI called maze2 (above), is there a limit to how many computers can access one API file at once?

Edit: I'm running Computercraft 1.43 and no Tekkit or any other mods except Forge, Mod Loader & Mod Loader MP
Cloudy #8
Posted 22 October 2012 - 09:14 PM
What version of ComputerCraft are you using?
Lyqyd #9
Posted 22 October 2012 - 09:16 PM
Along with your version number, what did you use to place all 625 of them?
MrZiggyStardust #10
Posted 22 October 2012 - 09:20 PM
Sorry, I edited my above post when I realized I forgot my version number.

Yeah, I'm not gonna place 625 turtles and turn them all on and give them the same startup file manually. I had 25 turtles each holding 25 turtles running this code:


while turtle.detect()==false do
  turtle.place()a = peripheral.wrap("front")
  a.turnOn()
  turtle.back()
end

Because I noticed just creating a mining turtle wont make an empty folder for it, after I had 625 empty folders I wrote an autoit script that did just this:


For $i=110 To 734 Step 1
   $file = FileOpen(String($i)&"startup", 1)
   FileWriteLine($file,'shell.run("maze2")')
   FileClose($file)
Next
Cloudy #11
Posted 22 October 2012 - 10:50 PM
Perhaps the chunks are unloaded which they are in?
MrZiggyStardust #12
Posted 23 October 2012 - 12:47 AM
I don't think so because I am sure to walk around and load all the chunks until my screen stops lagging.
MrZiggyStardust #13
Posted 24 October 2012 - 02:08 AM
Sorry for the bump, I'm just wondering if anyone else has any clue what it could be doing, all the turtles appear to receive the rednet command and start executing the set() function. The only thing I can think of is a turtle limitation, what is the maximum number of turtles you have gotten to run at once?
PixelToast #14
Posted 24 October 2012 - 02:27 AM
too many turtles might overload it and cause errors :/
Shnupbups #15
Posted 24 October 2012 - 02:44 AM
Some may be running out of fuel if fuel is enabled?
MrZiggyStardust #16
Posted 24 October 2012 - 03:43 AM
Yeah, I figured something to that extent, also I have fuel disabled :

This is upsetting, I guess I'll have to find a new way to generate huge mazes quickly.
Cloudy #17
Posted 24 October 2012 - 10:08 AM
I'm not sure what's going on. Do the turtles give a response once they've received the message? The queue for events is 4096 elements long - so shouldn't be an issue.
MrZiggyStardust #18
Posted 25 October 2012 - 12:00 AM
Every turtle executes the first few lines line of the set function


function set()
  x=0
  while turtle.detectUp() do
    print(tostring(x))
    turtle.digUp()
    turtle.up()
    sleep(1)
    x=x+1
  end
  for i=1, x do
    turtle.down()
  end
  turtle.placeUp()
end


But about half of them stop instantly after turtle.up(), they don't appear to go down, they just appear to exit the function for no reason after the first call of turtle.up()
ChunLing #19
Posted 25 October 2012 - 12:53 AM
Are they underneath something when they fail their detectUp check?

Or, and this is something that Cloudy might be better able to answer, is it possible that some of them are getting back to their detectUp check before they have actually finished moving up?
MrZiggyStardust #20
Posted 25 October 2012 - 04:13 AM
They should be, and I've taken the liberty of throwing sleep statements, after they move up, even that does nothing to them. Even if they did break out of the while loop because of that, their x value would still be one and they would go into the for loop and move down one block and place up. This is the most frustrating thing in the world ^_^/>/>
ChunLing #21
Posted 25 October 2012 - 05:52 AM
Just a thought, but what are the limits for getting something like a bunch of pistons pushing blocks? I've seen some amazing things built, but…625 is a lot of tile entities being activated in the same tick (and a lot of blocks being removed). If you could get a vantage point where you could see the level of all the turtles when they are removing their first block, and get an idea of whether they are all able to dig the block on the same tick, and then whether they are synchronized on their first move.

I mean, probably you can't see them all from one place the way they're set up now. I'm afraid to try this on my system because it's not super fast and it tends to wig a bit when I use a pick-axe with a high efficiency.
MrZiggyStardust #22
Posted 26 October 2012 - 01:03 AM
Yeah I can see them all from where I am when I launch the setMaze command.

with update 1.4.2 and the newest version of forge and computercraft, half the turtles fail their rednet.open command on startup, I'm about ready to give up on this and just make something else ^_^/>/>
ChunLing #23
Posted 26 October 2012 - 01:35 AM
Try something that will make a similar number of ordinary minecraft tile entities change their visible state simultaneously. Then see what happens.