1

Ok, many of you may not know what Pawn is. I'm converting the source from here http://en.wikipedia.org/wiki/User:Dllu/Maze to work in my SA:MP server. Pawn is a very easy code to understand so don't run because you don't know the language.

For some reason, only the outside padding and first cell (which they should be) are set to be in the maze. So, all the walls are there, and that's good. The problem is that only one cell is in the maze, and that is the starting point.

Please help!


I pasted it on Pastebin because pastebin actually has a pawn syntax. http://pastebin.com/wN6KFyFz


Also, it is supposed to support both backtrack and prim. Both have the same outcome. From what I tested I know that it never reaches the debug prints that look like this ("%i, %i | %x, %x, %x"). Well, it does reach the one in the while(!successful) loop, 1 time or 2-3 every once in a while.

Corey Iles
  • 155
  • 1
  • 17
  • Now the thing loops though every single cell until every cell is 'in' the maze. A log has been posted here http://pastebin.com/X7GSRDnd from the generation reported from this code: http://pastebin.com/MGQ3YKua – Corey Iles Jan 16 '15 at 06:57

1 Answers1

1

It's not working because you have changed some of the do...while loops in the C++ code to while loops in Pawn, which is not logically equivalent. do...while loops always execute at least once, whereas while loops execute zero or more times.

For example this code assumes that it will be run at least once:

do{
    //randomly find a cell that's in the maze
    xcur=rand()%(xsize-2)+1;
    ycur=rand()%(ysize-2)+1;
}while(!MAZE[xcur][ycur].in ||
    MAZE[xcur][ycur-1].in&&MAZE[xcur][ycur+1].in&&
    MAZE[xcur-1][ycur].in&&MAZE[xcur+1][ycur].in);

If you change that to a while loop then the loop condition will test false (because you start on a cell that's in the maze and isn't surrounded by cells that are) and so the loop will not be entered, xcur and ycur will never change and you will be stuck at the starting location forever!

If whatever version of Pawn you are using doesn't support do...while loops then you can fake them like this:

new bool:doOnce;
doOnce=true;
while(doOnce||(condition))
{
    doOnce=false;
    // do stuff...
}

is the same as

do
{
    // do stuff...
} while(condition)

assuming that evaluating the condition does not have any side effects, like incrementing or assigning variables, or Pawn is able to short-circuit the evaluation when doOnce is true.

Or else you can do it like this:

while(true)
{
    // do stuff....

    if(!condition)
        break;
}
samgak
  • 23,944
  • 4
  • 60
  • 82
  • Ok, this seemed to fix it with some more modifications. But now the thing loops though every single cell until every cell is 'in' the maze. A log has been posted here http://pastebin.com/X7GSRDnd from the generation reported from this code: http://pastebin.com/MGQ3YKua – Corey Iles Jan 16 '15 at 06:33
  • Isn't that what it's supposed to do? The maze is defined by the up/down/left/right walls of each cell, not which cells are in/not in the maze. – samgak Jan 16 '15 at 07:35
  • Oh lol, I think your right. That makes more sense. How do I create the path correctly then? – Corey Iles Jan 16 '15 at 12:36
  • Look at CellDataEnum. For each cell, if *up* is true then output a wall on the "north" side of the cell. If *left* is true then output a wall on the "west" side of the cell. I don't know the details of exporting stuff into SA:MP so you'll have to figure that bit out yourself, but that's how the maze is being stored in your script. – samgak Jan 16 '15 at 12:55
  • Now that I understand it I think I'm going to start over completely. I can't get it to work but it's probably because I didn't know what I was doing at all. I thought that 'in' was whether or not that cell would be white space or filled in. I thought left and up we're mainly for finding the next block and backtracking. Thanks for your help, I'll be back if I fail again :P. – Corey Iles Jan 16 '15 at 21:53