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

Better excavation (WIP)

Started by slay_mithos, 21 October 2012 - 07:12 PM
slay_mithos #1
Posted 21 October 2012 - 09:12 PM
Hello,

I discovered this mod some days ago, and started to play with the default functions yesterday.

Today, wanting to do a little more, I started to code a little program for better excavation.
Basically, it digs 3 layers at once (top, front and bottom), and keeps the first slot for fuel if provided, keeping 1 in the slot.

It is limited to dig even number quarries, adding 1 if the number provided is odd, because it was easier to code that way..

So far, it seems to be able to find home correctly, but as it has only be tested by myself so far, I can't say it is flawless.


It also has two differences with the normal excavate for the "home":

1. home is 1 block behind the place where it started, so you should not place a chest directly near the turtle, but let 1 empty block.
2. It is designed to try to pull fuel from a chest above the "home" if this chest exists, so that you can put a bunch of coal or charcoal in the chest to let it run better.

I made it for my personnal usage, but it seemed to work quite well, so I thought I might as well post it here.
Have fun with it, and post your problems (if any), I will try to check the thread once in a while.


Pastebin: http://pastebin.com/MUhzN4df
Edit; new version: http://pastebin.com/VUsXMYnW
Better move algorythm and better explanations on how to use.

EDIT: I seem to have uploaded the unfinished version in place of the right one, I apology about it, here is the finished one: http://pastebin.com/Acewyb2T
ChunLing #2
Posted 22 October 2012 - 12:33 AM
Hmmm…some oddities jump out. For example, in your dig() (which is a short and somewhat generic name for a global function, by the way), you've repeated exactly the code:
		    while turtle.detect() do
				    turtle.dig()
				    i=i+1
				    if(i == 20) then
						    stop = true
						    break
				    end
		    end
		    i=0
The second loop appears unnecessary except to allow 40 iterations rather than 20, which you could change by replacing 20 with 40 in your iteration check.

Also, all your functions are global, and many of them quite short, which clutters the global space. This is not an enormous concern, since this program doesn't call other programs, but you might want to be able to call it from another program, and then it would pose problems.

But I'd say overall it's a promising start.
slay_mithos #3
Posted 22 October 2012 - 01:32 AM
Well, maybe I forgot to say it was my first time with lua, so I might not be familiar with the specifics, like how to set a function to private and such. I even put a lot of ; as end of line, and tried to make the if with the { and }…

But one thing seems strange to me in what you wrote.
It is about the 40.
Is it a number that actually signifies something?

I took 20 randomly for the gravel, and so far, it seems to be just fine, but if you think 40 is better, then let's go for 40.

As I said before, this was coded without actual knowledge of lua (I am a programer in Java and C#), and I only wanted to try out to dig 3 at a time, and I made quite a few mistakes during the actual programing, so there are potentially many duplicates and/or useless lines.

I don't have the time right now, but I will look into what you wrote as soon as possible.

Thanks for the time and the advices.
ChunLing #4
Posted 22 October 2012 - 02:41 AM
You set the scope of functions the same way you do variables, with the local tag.

In your code, you have a while loop that runs for up to 20 iterations before calling a break. Then you have an exactly identical loop right after it. Normally I imagine it doesn't get called at all, 20 digs should be enough to remove most gravel/sand falls. But the loop isn't necessary. I imagine it happened during some cutting and pasting.
slay_mithos #5
Posted 22 October 2012 - 03:15 AM
Well, it was indeed a copy/paste, as I finally had the three most important parts ready (move, return home and come back to work).

I definitely need to put all this into local functions and to do a lot of cleaning and factorisation.

Well, at least my turtles will be working for me while I work on their code^^
slay_mithos #6
Posted 22 October 2012 - 05:58 AM
Ok, got just a bit of time, so I decided to restart fresh with something way easier, and I made a farming turtle.

I already had 2 fields for wheat, so I setup a little program to harvest and replant all of this.

So far, no timer, no rednet, just a basic thing, that can be fairly easily adapted and made more universal when I get the time.

The only problem I can see (just noticed right now) is that it can get stuck on entities, and even if it won't completely wreak it, it won't be able to complete the task as expected.

http://pastebin.com/TRXTJyKk

Feel free to tell me what is wrong with the code (and I might get some comments there later if needed)
ChunLing #7
Posted 22 October 2012 - 08:29 AM
For entities, you can use an while not turtle.forward() do if turtle.detect() then turtle.dig() else turtle.attack() end end loop. Or you can just loop without the attack, if you don't want to kill something that is in your wheat field innocently (though I personally do not consider those who trample my crops to be innocent). You can have the function return false if it detects but can't break or if it runs through too many iterations without success. And if the move succeeds on the first try then you don't even process the other functions, the loop is skipped. Put a return true after the loop and you always know whether or not to update your position values/file.
slay_mithos #8
Posted 22 October 2012 - 02:44 PM
Oh, so detect returns false with entities, even though there is something?
I will take this into consideration then, thanks
ChunLing #9
Posted 22 October 2012 - 08:40 PM
Yep. Right now I only ever use it to tell me if a block is unbreakable, but once you have turtles that are comparing to see if they should dig something it can be useful to detect to see if there is anything there to dig (like say you've got a diamond pickaxe with fortune, so you want turtles to only excavate stone, gravel, dirt, and iron ore so you can max out on the ores that drop items rather than blocks).
slay_mithos #10
Posted 25 October 2012 - 08:41 PM
Hello again,

I revised the program quite a bit, and made tests to ensure it works.

Hopefully, I tested enough, and the code is of better quality than last time, as I put more reflexion this time on how to handle various things.

Here is the new link: http://pastebin.com/VUsXMYnW

As always, I will be happy if anyone can tell me where to make changes to make it better, while keeping in mind the original goal of it being a basic quarry program (no rednet or gps for example).
ChunLing #11
Posted 26 October 2012 - 02:29 AM
You should add some command line parameters to restart it at a different origin position (or to read the position out of the position log). That way, you won't have to break your turtle and lose all it's fuel after every chunk un/load.
slay_mithos #12
Posted 26 October 2012 - 11:11 AM
Turtles won't loose fuel when broken if they are labelled

but as for the restart, I don't want it for now, as it means either always writing a position into a file (heavy) or to really mess with the position system, that has nothing to do with the "real" coordinates.

That said, I will keep that in mind if I feel like I could do it.
ChunLing #13
Posted 26 October 2012 - 01:04 PM
But you're writing a position log anyway, right? Well, I use GPS for everything, so it's not like I'm one to talk about inertial guidance with saving every move and all.
slay_mithos #14
Posted 26 October 2012 - 08:10 PM
no, it's more of a debug log, to check if it turns at the right coordinates and if there are problems with going home and back.

With GPS, it would be much easier, just saving the x, y, z and rotation of the home tile, but I want the program to be usable right when you discover your first 3 diamonds and redstone.

I mainly use the turtles to clear out multiple chunks at a time (16 to 0) in search of diamonds, iron and gold, mainly, so they do offline mining on a server.
ChunLing #15
Posted 26 October 2012 - 08:13 PM
Hmm…maybe you should have them only mine stone, dirt, gravel, and obsidian? That way you can use a fortune pickaxe on the diamonds and redstone.
slay_mithos #16
Posted 26 October 2012 - 08:34 PM
Not sure how I could prevent it from mining diamonds and other item dropping, as the turtle.compare() wouldn't work.

I guess you could put 1 sample of each block allowed to be mined, but you only have 16 slots, so it's not really to my liking.

That said, I could make a turtle that mines 3 layers, leaves 2, mine 3 etc, also leaving the item dropping, so that I could access the ores to mine them, but that is not for today, at least.
ChunLing #17
Posted 26 October 2012 - 10:44 PM
You can have a block of stone, dirt, gravel, and obsidian. Have the turtle compare to those before trying to dig anything, and if it isn't one of them then go around or something. This does mean wasting a slot on the stone, since turtles collect cobble instead. And it's only worthwhile if you do have a fortune pick-axe…so more of an advanced option, I suppose.
slay_mithos #18
Posted 27 October 2012 - 04:28 AM
Yes, it is the basic, but there is one big major faw with your plan:

You get blocks high in the air, without any way to access it beside a dirt tower, that is not really a good way, if you need to spend too much time to get to the blocks, might even not be worth the trouble.
That's why I said you should let one or two layers between the 3 tall ones, so that you can access everything, but it also means potentially more mobs, and definitely more problems with lava not turning into obsidian.

Anyway, it is a good idea at the base, but I need to really work on this before I can get a good result, too bad we can't have an enchanted turtle, or a turtle using a tool in the inventory, would be really easier.
ChunLing #19
Posted 27 October 2012 - 05:07 AM
The Aperture Science mod has silk touch turtles, but you have to cheat to get them. Eventually that will get fixed, I suppose.

If you flood the mine, you don't have to worry about mobs or getting to stuff, you just need to take ladders and place them so they create air pockets. Of course, there is still the issue of whether it is easier to just have simpler miners clear out more chunks rather than bothering to multiply the returns on diamonds/redstone, against the limit of how far away the turtles can be and actually still be in loaded chunks. I guess that as long as you're making sure not to actually lose a bunch of diamonds that's doing pretty well.
slay_mithos #20
Posted 27 October 2012 - 12:54 PM
Well, I tried 3 turtles running the program on a flat age, starting at 15, each clearing 3 chunks lon and 1 chunk wide, and it gave me 42 diamonds, and so much redstone and coal that I don't know what to do with it anymore^^

The only reason to continue the mining right now would be for iron, maybe gold, because they are the only ones that don't fill a row of a diamond chest (voiding the cobble, dirt, gravel and flint already, might even void the redstone)

If done correctly, with turtles directly dumping into the piping system, combined with the new BC thing to place on top of the machines, you can prety much automate it without worries.


I even made a sword turtle for the sole purpose of lighting the area after I remove the water, so I don't have to be blown by creepers while not seeing anything at y=1^^
ChunLing #21
Posted 27 October 2012 - 03:02 PM
You got 42 diamonds from 9 chunks? That's quite good. But yeah, I guess you need to have a pretty high enchantment on your pick-axe before it becomes worth not fully automating.
spardha #22
Posted 27 October 2012 - 11:07 PM
Doesnt work for me :D/>/>

bios:338: [string "mine"]:30: '=' expected
slay_mithos #23
Posted 28 October 2012 - 12:23 PM
Oh, damn, I uploaded the wrong version where I forgot to comment some lines, I will give the right one now…
http://pastebin.com/Acewyb2T

Really, my apologies for not noticing such an error on what script to upload.
failureone #24
Posted 19 November 2012 - 04:18 PM
am not great at programing so cant realy troubleshoot my problem but i feel that your program is the most efficiant out of all i have found and would like to use it…. however once i pastebin the program i start it and get this error;

Quarry:250: attempt to perform arithmetic _ _sub on string and number

at first i thought i did something wrong but tbh i would not have a clue if it was me or not lol

EDIT: i am also running with no fuel mode on a server if that helps

EDIT 2: nevermind i just removed all the fuel checking functions and it started working fine, must be a bug with not recognizing unlimited fuel
Edited on 19 November 2012 - 04:10 PM