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

Help with creating a database for mazesolver program.

Started by Meeshu, 08 April 2013 - 01:58 PM
Meeshu #1
Posted 08 April 2013 - 03:58 PM
I working on a program that will allow a turtle to find its way out of a 2 dimensional maze.

So far I've made a movement and coordinate API particular to how I want to have the program run.

Anyway, here's my dilemma: I want the turtle to be able to store points (x,y) in a database, and have 4 booleans correspond to those points.

For example:
Point A is at 4,5. To the left of point A there is a block. In front of point A is a block. To the right of point A there is no block, and behind point A there is also no block.

If the turtle gets to point A, it will recognize the fact and know which ways it can go.

Now lets say the turtle is moving forward and reaches a wall. How can I have it log this point in the database as Point B with its coordinates? And, after it's logged as point B, how can I add the 4 booleans to the database aswell?

Can anyone point me in the right direction here?
LuaEclipser #2
Posted 08 April 2013 - 04:01 PM
The only way for the turtle to get its cords. is using the gps API. i have no idea how to set it up. heres the wiki post
Meeshu #3
Posted 08 April 2013 - 04:11 PM
I'm not worried about getting the coords, that I can do. What I need help with is setting up a database capable of what I described above.
SadKingBilly #4
Posted 08 April 2013 - 04:39 PM
Create a directory for your database, a file for every X-coordinate, and have each line in that file go "Z-coordinate:North:East:South:West"?
LordIkol #5
Posted 08 April 2013 - 10:46 PM
If i understand it right the Points you have are like Checkpoints?

Maybe you can do like this.

Checkpoint[i] = {x = 4, y = 5, left = false, right = false, front = true, back = false}

once all the checkpoints are stored you can use unserialize / Serialize to store the whole table to a file and read it later.
everytime your turtle needs to check up you can use function like


for i=1, #Checkpoint do
if checkpoint[i].x == 4 and checkpoint[i].y == 5 then
whatever you want to do
end
end 

Edit: Maybe check out THIS post from Kingdaro where he and Remix explained this table stuff to me :D/>

hope that helps
Jian #6
Posted 09 April 2013 - 11:09 AM
My understanding is that you're not just trying to store checkpoints, you're trying to scan your surroundings from every point. My suggestion would be instead of having left, right, front, back being separate variables, have it effect the other points in the table.

you can setup the table like this



knownSpaces = {
{ true , false , true , true , false , false } , 
{ true , false , false , false , true , false } ,
{ true , false , true , true , false , false } , 
{ true , true , false , true , false , true } ,
{ true , false , false , false , true , false } ,
{ true , false , true , true , false , false } , 
}


- x +
y
+

so then you're reading/writing by using 'knownSpaces.xPos.yPos'..

ex knownSpaces.3.3 = true

then you have separate table for the current position info so like this
currentPos = { x = 3 , y = 3 }
and you are facing in the -x,+y direction
you could have something like

knownSpaces.( currentPos.x - 1 ).( currentPos.y + 1) = turtle.detect()

I don't think any of this code is actually usable I'm just trying to steer you in a different direction.
SuicidalSTDz #7
Posted 09 April 2013 - 11:36 AM
a file for every X-coordinate
No, just, no. This can be achievable with the use of tables, and tables only. Creating many files will do no one justice.