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

Mining turtle alignment (like a chess knight)

Started by Mirodin, 25 July 2014 - 09:18 PM
Mirodin #1
Posted 25 July 2014 - 11:18 PM
Hey guys,

I got a lot of questions these days, sorry for that ;)/>

I am currently writing a new mining script, which is said to replace my old quarry program which is in terms of fuel quite inefficient to the new design.
The big problem is the correct alignment of my mining turtle. In the picture attached you see black and white fields which represent the surface seen from above.

The turtle will start in the bottom left corner and dig straight down to bedrock, checking for ores etc. on its way down. Then it will go up a few blocks (to avoid bedrock collisions), two forward and one to the right (like a knight in chess), go to bottom again and dig its way up while checking for ores. This way I get 100% coverage by great block/move ratio (5 blocks/move).

But I do not have the slightest idea how to do the math for correct allignment :(/>

Does anybody got an idea how to solve this?

Thanks for helping
Cheers Mirodin
flaghacker #2
Posted 26 July 2014 - 07:56 AM
What do you mean by "the math for the alignment"? The loop structure?
Mirodin #3
Posted 26 July 2014 - 11:43 AM
No, I mean how to say the turtle "make your move underground", which works just fine and then "align overground within same chunk".

If I just do "go down" - "two forward, one to the right" - "go up" - "two forward, one to the right" which is really simple, I end up by a long line of shafts and a lot of chunks I have to chunkload. So I want the turtle to stay within a let's say 16x16 area and mine all required shafts to get 100% coverage (see picture above)

Sorry for my poor explanations, I am not a native speaker.

Cheers
Mirodin
Edited on 26 July 2014 - 09:46 AM
KingofGamesYami #4
Posted 27 July 2014 - 03:38 AM
Well, I think that's easier to do without any complicated math. Here's my solution, which needs some more coding before it will work, but you can get the general idea.

--#first, let's define the 4 different rows you can find.
local s1,s2,s3,s4 = "1000010000100001", "0010000100001000", "0000100001000010", "0100001000010000",
--#next, we'll define a 16x16 chunk
local map = { s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4 }
--#now we need some variables to mess with
local pos = { x = 16, y = 16 }
local xInc = 1 --#this is important later
local yInc = 1
--#and now our loop
while true do
 if map[ pos.x ]:sub( pos.y, pos.y ) == "1" then --#we are above a section that we should mine
  --#mine
 end
 pos.x = pos.x - xInc --#lets change our variable by whatever we want to change it by ( 1 or -1 )
  if pos.x > 16 then --#we've gone off the map
    turtle.turnLeft() --#lets move over a row
    turtle.forward()
    turtle.turnLeft()
    pos.x = 16 --#reset position to 16
    xInc = 0 - xInc --#reverse whatever we are doing, since subtracting a negative number is the same as adding a positive
    pos.y = pos.y - yInc
  elseif pos.x < 1 then --#we've gone off the map
    turtle.turnRight()
    turtle.forward()
    turtle.turnRight()
    pos.x = 1 --#reset position to 1
    pos.y = pos.y - yInc
    xInc = 0 - xInc
  end
  if pos.y > 16 then --#we are also off the map
    --#bla bla bla stuff I don't wanna write
  elseif pos.y < 1 then --#off map
    --#more stuff I dont want to write
  end
  turtle.forward()
end
--#course, I haven't put in a check to see if we don't have any space left to mine, and thus we need to start a new chunk.
flaghacker #5
Posted 27 July 2014 - 06:52 AM
That's a neat approach, maybe make the map in a loop so you can go to the next chunk? The next chunk would have a different pattern. Maybe that's not needed for the OP though.
Mirodin #6
Posted 27 July 2014 - 11:23 AM
Well, I think that's easier to do without any complicated math. Here's my solution, which needs some more coding before it will work, but you can get the general idea.
Wow, that is awesome, thank you a lot. I never would have come this idea. :blink:/>
Since everything else works, this will complete my program :D/>

That's a neat approach, maybe make the map in a loop so you can go to the next chunk? The next chunk would have a different pattern. Maybe that's not needed for the OP though.
So do I get you right that you think, I should make patterns for multiple chunks within the map like this (I did not check, if that is correct)

local map = { [1] = { s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4 }, [2] = { s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1} }
hilburn #7
Posted 27 July 2014 - 02:26 PM
I realise this is a bit late but if you just want the x,z coordinates you could do something like:


local xmax = 15
local zmax = 15
local digsite={}
for z=0,zmax do
    digsite[z]={}
    local offset = (-2*z)%5
    for row=0,math.ceil(xmax/5)+1 do
        x=offset+5*row
        if x<=xmax then digsite[z][#digsite[z]+1]=x end
    end
end

This should handle generating the coordinates for a mine of any dimension and you can then use a simple goto (x, z) function to move between them

Edit: missed a +1
Edited on 27 July 2014 - 02:19 PM
Mirodin #8
Posted 27 July 2014 - 03:30 PM
I realise this is a bit late but if you just want the x,zip coordinates you could do something like
No, it is not too late, I appreciate every help I can get, thanks a lot.
Did you study math? :blink:/>
hilburn #9
Posted 27 July 2014 - 04:09 PM
Lol no, I studied engineering a while ago but that didn't really come into it, I was just pattern making with that code. Loops and modulos are your friends for something like this.

If you wanted to make it more efficient you could just calculate the first 5 rows and then your coordinates for the row is going to be (digsite[z%5], z) as is repeats
flaghacker #10
Posted 27 July 2014 - 05:25 PM
Well, I think that's easier to do without any complicated math. Here's my solution, which needs some more coding before it will work, but you can get the general idea.
Wow, that is awesome, thank you a lot. I never would have come this idea. :blink:/>/>
Since everything else works, this will complete my program :D/>/>

That's a neat approach, maybe make the map in a loop so you can go to the next chunk? The next chunk would have a different pattern. Maybe that's not needed for the OP though.
So do I get you right that you think, I should make patterns for multiple chunks within the map like this (I did not check, if that is correct)

local map = { [1] = { s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4 }, [2] = { s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1, s2, s3, s4, s1} }

Yes, but it would be a good idea to create that table automatically.