Jump to content

Maze Map with PHP / Serverside storage


Monkuar

Recommended Posts

Just curious, how would you go about rendering and storing this in a database. For example a simple small maze. 

 

4b1b079f8c72a397f2f159d1e24636ee.png

 

With each keypress, the user is moved up,down,left,right like 1 inch. (1 block). Which is easy to do with jquery, etc. But how would go about storing the data in a databse (can update the position per update or using websockets), but essentially so maphacks are impossible and everything is saved/read from the server.

 

Would the storage data be something like [0,0,0,1,0,0,1,1,1,1,0,1] I imagine or what?

Link to comment
https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/
Share on other sites

Storage space efficiency aside, my first thought would be that each cell is a number 0-15 indicating where there are not walls. A bitmask.

   WSEN
 0 0000
 1 0001
 2 0010
 3 0011
 4 0100
 5 0101
 6 0110
 7 0111
 8 1000
 9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
The cell with the ◄ would be a 12: N=0 (0), E=0 (0), S=1 (2**2=4), W=1 (2**3=8 ). Moving S brings you to a 3 cell (N+E).

 

In MySQL you can do that with a SET automatically.

When I created a maze program I used an image to define the maze. Samples attached.

 

Not very complex, I was using it to experiment with the mathematics of creating  3D maze with perspective views.

 

 

post-3105-0-15533800-1417501723.png

post-3105-0-72932900-1417501742_thumb.png

post-3105-0-09856400-1417502001_thumb.png

That's a clever idea.

 

If the maze is drawn to specific, known constraints, you can use basic image reading functions to "parse" it. If each square is a cell or wall with a fixed size then you can pull the color of a specific pixel to determine the contents. If walls are not the same size, like they're borders, then it's a little trickier but you can still do some simple math to determine which pixel to look at for what.

  On 12/2/2014 at 2:48 AM, requinix said:

Storage space efficiency aside, my first thought would be that each cell is a number 0-15 indicating where there are not walls. A bitmask.

   WSEN
 0 0000
 1 0001
 2 0010
 3 0011
 4 0100
 5 0101
 6 0110
 7 0111
 8 1000
 9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
The cell with the ◄ would be a 12: N=0 (0), E=0 (0), S=1 (2**2=4), W=1 (2**3=8 ). Moving S brings you to a 3 cell (N+E).

 

In MySQL you can do that with a SET automatically.

 

 

When you say each cell, you mean each number in the row right?

 

That makes sense, so I would just need to create a function that checks it serverside to make sure the player can only move away one block at a time? (e.g: No flying or moving from block 1 to 15).  That will be a bit tricky for me, but I understand the process now. Thank you.

 

This system would also be used as data to be sent from the client to the websocket for a serverside mmorpg I assume.  (For serverside storage of characters positions and whatnot and preventing speed hackers and teleporters). Although, this would be very CPU intensive? Doesn't quite look that bad.

  On 12/2/2014 at 9:47 AM, Monkuar said:

When you say each cell, you mean each number in the row right?

Each row itself, yes. The table has columns for the X and Y coordinates, the type of cell (potentially), and the bitmask of where the walls are.

But I'm liking Barand's idea more now.

 

  On 12/2/2014 at 9:47 AM, Monkuar said:

That makes sense, so I would just need to create a function that checks it serverside to make sure the player can only move away one block at a time? (e.g: No flying or moving from block 1 to 15).

Have the client tell you the direction they want to move. That way all you have to validate is the direction (only four possible) and whether it's allowed (based on walls).

 

  On 12/2/2014 at 9:47 AM, Monkuar said:

This system would also be used as data to be sent from the client to the websocket for a serverside mmorpg I assume.  (For serverside storage of characters positions and whatnot and preventing speed hackers and teleporters). Although, this would be very CPU intensive? Doesn't quite look that bad.

Wouldn't expect it to be CPU intensive - most of the time would be spent waiting for the client to act. But it will use a lot of connections on the server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.