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?

Edited by Monkuar
Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
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 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.

Edited by Monkuar
Link to comment
Share on other sites

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.

 

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).

 

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.
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.