Jump to content




Self-Replicating Turtle - Revisited


90 replies to this topic

#1 Inksaver

  • Members
  • 59 posts

Posted 10 May 2014 - 09:46 AM

Hi All

My first post here, so treat me gently.

In sept 2012 this post: http://www.computerc...62-competition/ launched a competition to create a self-replicating turtle.

It appears nobody ever completed it, but it caught my interest, as I run a computer club at my son's school, and looked to be a topic worth investigating.

I started 6 months ago, having never even heard of Lua, let alone used it, but I am fairly proficient with VB6

I finally have a Lua script working. It is >11,500 lines long, uses classes, objects, functions (and recursive functions) and follows most of the rules in the original post:
Competition Rules

Youtube Videos

Brief description: the first tree is harvested, a cobble base camp is constructed with a furnace in the centre, then the trees in a 33 X 33 area are harvested, with mineshafts dug down to level 40 at the end of each run to get coal and ironore only.
When enough saplings are available (min 5) a treefarm is constructed to provide fuel or wood in the future.
When complete a single deep mineshaft goes down to level 14 and 2 corridors are dug in a cross shape centred on the original tree. (2 blocks high to allow player to explore). This is repeated on level 10 and level 7.

Each quarter of the cross shape is mined in two halves, by completely removing all blocks, and placing cobble on the ceiling to create 3 chambers 33 x 33 x 2. This method is faster than strip mining, where the constant turtle rotation to check walls takes longer than simply removing it. The final layer to bedrock is mined vertically.


For anybody who wants to get started, here is an easy method:

First VERY IMPORTANT!

Open this file in notepad:
"%appdata%\.minecraft\config\ComputerCraft.cfg"

in 'general' section find:
"# The disk space limit for computers and turtles, in bytes"
Change the following line to:
"I:computerSpaceLimit=10000000"
That is a tenfold increase in size.
find:
"# The disk space limit for floppy disks, in bytes"

Change the following line to:
"I:floppySpaceLimit=500000"
Save and re-start Minecraft

if you do not do this, the file start.lua is too big to copy to a floppy disk, and the logFiles produced by the script to debug can run to 6MB or more in the computerSpaceLimit. This will cause the script to fail.
I have tested a number of worlds to try out the script:

IMPORTANT - Choose or create a tree with a minimum of 6 logs, otherwise you are likely to run out of fuel!

Sample Worlds
download script from: http://pastebin.com/2Zf5an8H
Current Pastebin updated to Version 1.1.1
Jul 17 2014 12:18 GMT

As updates are put on Pastebin, I will post again in this thread

Edited by Inksaver, 17 July 2014 - 11:19 AM.


#2 H4X0RZ

  • Members
  • 1,298 posts
  • LocationGermany

Posted 10 May 2014 - 12:05 PM

That's AMAZING!!

#3 Cozzimoto

  • Members
  • 221 posts
  • LocationDallas, Tx

Posted 10 May 2014 - 04:51 PM

DAM, someone actually did it, dude congrats! +1

#4 viluon

  • Members
  • 183 posts
  • LocationCzech Republic

Posted 10 May 2014 - 05:14 PM

Well, this seems... AWESOME! Great job! (+1)

#5 Inksaver

  • Members
  • 59 posts

Posted 12 May 2014 - 08:52 PM

Thanks for the comments guys.

All videos uploaded from start to finish, heavily edited and annotated to keep them short.

Any improvements to the script would be appreciated. After all I am still a beginner!

Would it be presumptuous to post a tutorial for the whole script in the tutorials section?
(It looks like most of the tutorials there are by experts in LUA.)
I have learned a lot about classes, objects, functions etc. from the 8 months I have been working in this script, and would love to pass the knowledge on.

Enjoy

#6 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 01:24 AM

On every run i get this error in different moments: Start.lua: 2779: Slot number 0 out of range

it appears to be when the turtle is behind the furnace with the chest on the bottom and tries to craft something

Logs(same run):
pastebin.com/vSJcH4f8
pastebin.com/7EzfeX5p
pastebin.com/Bby0kB4y
pastebin.com/WMCwNKPN


edit: wrong ones

EDIT: seems i cannot replicate anymore...

Edited by TurtleHunter, 13 May 2014 - 03:20 AM.


#7 flaghacker

  • Members
  • 655 posts

Posted 13 May 2014 - 10:51 AM

View PostInksaver, on 12 May 2014 - 08:52 PM, said:

After all I am still a beginner!
No. You're really not.

Quote

Would it be presumptuous to post a tutorial for the whole script in the tutorials section?
(It looks like most of the tutorials there are by experts in LUA.)
I have learned a lot about classes, objects, functions etc. from the 8 months I have been working in this script, and would love to pass the knowledge on.
I would really love a tutorial!

Edited by flaghacker, 13 May 2014 - 10:51 AM.


#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,330 posts
  • LocationAustralia

Posted 13 May 2014 - 12:07 PM

Wow really nice work! I doff my cap to you sir, 'tis truly fine work you've done there...

if i were to pick on anything code wise it would be your lack of local variables/functions, they are a little more efficient and it means once the program stops running the global scope isn't littered with variables from your program, otherwise there's nothing too major I can see that I would say you could improve. you could probably shorten the script a little by removing non-essential comments (for example, commented out test code)

as to your question about tutorials, I feel like you'd be fine to write one up, you seem to have the expertise and intellect to be able to make an intelligent tutorial with good and thorough explanations. :) I think potentially doing a tutorial of the whole script could turn out a little long, I'd probably say as a rule of thumb I wouldn't go much longer than the tutorials posted by Lyqyd or myself, due to the fact of the young audience we have here on these forums the attention span isn't always there to accompany long tutorials, also keeping it basic as as dumbed down as possible could be beneficial due to the wide range of programmatic skills we have here too, even referring them to read tutorials from the Ask a Pro renewal series to lessen your work while still providing them with the information.

Edited by theoriginalbit, 13 May 2014 - 12:09 PM.


#9 Inksaver

  • Members
  • 59 posts

Posted 13 May 2014 - 02:02 PM

@TurtleHunter
post the seed of your world, along with the coordinates of the tree you are starting from, and the direction facing, and I will see if I can sort the problem

@flaghacker
Tutorial started

@theoriginalbit
Thanks very much for your constructive criticism. I have started to change the functions to local, and clear out some of the unused code.
Regards tutorials, the club I run is for 12 to 16 yrs, and I know exactly what you mean regarding attention span of that age group! I will post one soon to see how it goes down, and take it from there.

#10 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 02:32 PM

View PostInksaver, on 13 May 2014 - 02:02 PM, said:

@TurtleHunter
post the seed of your world, along with the coordinates of the tree you are starting from, and the direction facing, and I will see if I can sort the problem

@flaghacker
Tutorial started

@theoriginalbit
Thanks very much for your constructive criticism. I have started to change the functions to local, and clear out some of the unused code.
Regards tutorials, the club I run is for 12 to 16 yrs, and I know exactly what you mean regarding attention span of that age group! I will post one soon to see how it goes down, and take it from there.
I used the seed from the option 4, i think that it is because i give him saplings manually(when it haves one or more alredy)

Edited by TurtleHunter, 13 May 2014 - 02:33 PM.


#11 Inksaver

  • Members
  • 59 posts

Posted 13 May 2014 - 03:12 PM

If you change anything manually, the script will not recognise what you have put in , so best not to interfere once it is running. I will re-run option 4 later, in case I missed something, or worse, created another problem by solving something else!

#12 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 08:16 PM

View PostInksaver, on 13 May 2014 - 03:12 PM, said:

If you change anything manually, the script will not recognise what you have put in , so best not to interfere once it is running. I will re-run option 4 later, in case I missed something, or worse, created another problem by solving something else!
Also another bug: you cant put it on a dir cause it will crash when trying to copy itself to the floppy

#13 Inksaver

  • Members
  • 59 posts

Posted 13 May 2014 - 08:25 PM

View PostTurtleHunter, on 13 May 2014 - 08:16 PM, said:

Also another bug: you cant put it on a dir cause it will crash when trying to copy itself to the floppy

You DID change the config file:
"I:floppySpaceLimit=500000"
?

otherwise it will crash

#14 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 08:30 PM

View PostInksaver, on 13 May 2014 - 08:25 PM, said:

View PostTurtleHunter, on 13 May 2014 - 08:16 PM, said:

Also another bug: you cant put it on a dir cause it will crash when trying to copy itself to the floppy

You DID change the config file:
"I:floppySpaceLimit=500000"
?

otherwise it will crash
I did, the thing is that you suppose that the file is named start.lua and that its not on a dir like in line 3275. You should use shell.getRunningProgram and shell.resolveProgram to get the absolut path to the file

and just in case i have a chickenchunks chuck loader 3 blocks up of the starter tree with a radius of 3 chunks

Edited by TurtleHunter, 13 May 2014 - 08:37 PM.


#15 Inksaver

  • Members
  • 59 posts

Posted 13 May 2014 - 09:24 PM

The creation of a copy of start.lua to a floppy disk, then from there to new turtles has not caused any errors with the worlds I have used it on so far.
Now you have highlighted a problem, I will need to investigate it.
The line you are referring to is:
startFile.writeLine('fs.copy("/disk/start.lua", "start.lua")')
Could you use windows explorer to see what you have in there is similar to this:
0 is the original turtle Miner1
1 is Miner2
2 is Miner3
disk

disk contains:
0
which has:
minerList.txt
start.lua
startup

Bear in mind the line quoted above is not a line of code run by start.lua. It is a line of text written to a file called startup
So it is only when startup is run by either Miner2 or Miner3 when they are activated.

Attached Thumbnails

  • Attached Image: disk.jpg

Edited by Inksaver, 13 May 2014 - 09:30 PM.


#16 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 09:52 PM

View PostInksaver, on 13 May 2014 - 09:24 PM, said:

The creation of a copy of start.lua to a floppy disk, then from there to new turtles has not caused any errors with the worlds I have used it on so far.
Now you have highlighted a problem, I will need to investigate it.
The line you are referring to is:
startFile.writeLine('fs.copy("/disk/start.lua", "start.lua")')
Could you use windows explorer to see what you have in there is similar to this:
0 is the original turtle Miner1
1 is Miner2
2 is Miner3
disk

disk contains:
0
which has:
minerList.txt
start.lua
startup

Bear in mind the line quoted above is not a line of code run by start.lua. It is a line of text written to a file called startup
So it is only when startup is run by either Miner2 or Miner3 when they are activated.
You dindt undesrtand me :P, I downloaded your file as start/start.lua and it crashed because it didnt find start.lua in / cause it was on /start, you should detect the path of your file to copy it to the disk, its a pretty simple fix

#17 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 13 May 2014 - 10:20 PM

Dude... How did you do this...
This is freaking awesome

Edited by cptdeath58, 13 May 2014 - 10:20 PM.


#18 TurtleHunter

  • Members
  • 112 posts

Posted 13 May 2014 - 10:59 PM

Crash: Turtle has full inventory and is trying to craft something. The error was Slot 0 out of range

logs: pastebin.com/wyY8Lkmy
pastebin.com/gPrWfTfg
pastebin.com/BU9vJEQ1
pastebin.com/FH2UEffg

Screenshots: http://imgur.com/a/5FEH0

Im the bug hunter :P

Edited by TurtleHunter, 13 May 2014 - 11:08 PM.


#19 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 14 May 2014 - 12:02 AM

Really nice, I like!

Not to be a dick or anything but Lua is not an acronym it actually means "moon" in Portuguese so you don't have to write it in caps :)

#20 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,330 posts
  • LocationAustralia

Posted 14 May 2014 - 12:21 AM

View PostInksaver, on 13 May 2014 - 02:02 PM, said:

@theoriginalbit
Regards tutorials, the club I run is for 12 to 16 yrs, and I know exactly what you mean regarding attention span of that age group! I will post one soon to see how it goes down, and take it from there.
we've had people as young as 6 (iirc) on these forums before. and obviously making it even more difficult when they're ESL ;)

I do agree with TurtleHunter, I'd probably use a dynamic method, although you don't really need to use shell.resolve, just shell.getRunningProgram
if you wanted to get really tricky you'd also use fs.getName so that when you continue to create the new programs they're still named the same as what the original user specified.

Example
if disk.isPresent("bottom") then
  local filepath = shell.getRunningProgram()
  local filename = fs.getName(filepath)
  fs.copy(filepath, "/disk/"..filename)

  -- snip --

  startFile.writeLine('fs.copy("/disk/'..filename..'", "'..filename..'")')

  -- snip --
end

if you wanted to be even more clever about it you could also use disk drive detection and getting its mount path as a just in case, but you shouldn't really need it in this instance.

Edited by theoriginalbit, 14 May 2014 - 12:45 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users