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

EnderMine v0.2 - Branch mining with enderchests

Started by The Lone Wolfling, 17 January 2013 - 03:46 PM
The Lone Wolfling #1
Posted 17 January 2013 - 04:46 PM
I've been writing a program off and on for the past few days, based on the idea of having fully autonomous chunkloading mining turtles. (Note that this means good luck getting back any mining turtles you run with this program…)

As such, the goal of this program is to mine the most ores per unit of time per turtle. It currently doesn't check the sides of the (1x1) tunnel it digs except when it finds ores ahead/above/below - this is intentional, as fuel is cheap, and if it turns to check a side it takes longer per block exposed. If you want it to be thorough, change line 200 to digRecursively(true).

Code is on PasteBin; instructions are included at the top of the file. Just put dirt in slot 13, smoothstone in slot 14, an ender chest for blocks mined in slot 15, and an ender chest for fuel in slot 16.

If anyone has any questions / comments / suggestions, please tell me.

It currently has a limitation of only being able to dig 100 blocks per ore-mining mode, as it is recursive and there is a stack limit of ~240 calls (256 minus os use, I'm guessing…). I've been thinking about how to switch it over to a mapping of what blocks are mined / exposed, and if/when I do that I will call that v1. The biggest problem with a mapping is that I don't know how to optimize checking blocks, and have a sinking feeling that there is no "good" solution at all.
Ulthean #2
Posted 17 January 2013 - 08:54 PM
I don' have the time to look at the code now, but since you mentioned the recursion limit: I tackled this problem by replacing the recursion with a regular, non-recursive function. It's hard to explain (and I need to go now, so can't really take the time to think of a good explanation) but take a look at the excavate function in: http://pastebin.com/fRh3UXa6

Basically every time you would normally call the recursive function instead it adds an entry to an array, it then searches the new location for ores, if it finds any it will add another entry to the array, if it doesn't it goes back one step, and continues (the values in the array are used so he can continue at the correct location)

EDIT: in my code lookForOres returns the direction of an ore, when it returns 7 it means no ores were found in any of the adjacent squares.
The Lone Wolfling #3
Posted 18 January 2013 - 12:57 AM
Oh ok. I find it intriguing how different our routines for mining an ore vein are, even though they do the same thing. What's the size limit of arrays anyway?

Also, love the APIs, especially api_turtleExt.turnTo and api_turtleExt.turnFrom.
Ulthean #4
Posted 18 January 2013 - 01:23 AM
I'm not entirely sure, but I have had the excavate function dig out a 50x50 area without problems, so around 2500 at least :)/>

Edit: I found the api_turtleExt very useful, for operations such as api_turtleExt.compare(left) and especially the digAndMove