hi all,
i write this snippet of code to randomly draw a maze. when ROW is defined less then 12, it works well. but when ROW >12, the result truns out to be weired.(the "wall" around the maze is broken :( )
eg. (PS: 'O' DENOTES SPACE)
right form:
XXXXXXX
XOXOXOX
XXOXOXX
XXXXXXX
undesired form: (when row >12)
XXXXXXXoXXXX
XXOOOOOXXO
XOOOOXXXXX
XX OXOOXX
OXXXOOXXXXX
the "wall" is broken...what happened?
it does sth. with my complier or .......plz help me
thanks in advance!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROW 10
#define COLUMN 10
int main()
{
int draw_maze();
draw_maze();
getchar();
return 0;
}
int draw_maze()
{
int maze[ROW][COLUMN]={0};
int i,j;
for(i=1; i<(COLUMN-1); i++) //clear inner space
for(j=1; j<(ROW-1); j++)
maze[i][j]=1;
srand((unsigned)time(NULL));
for(i=1; i<COLUMN-1; i++) //randomly set blocks
for(j=1; j<ROW-1; j++)
maze[i][j] = rand()/(RAND_MAX/2); // maze[i][j] = 0 or 1
for(i=0; i<COLUMN; i++)
{
for(j=0; j<ROW; j++)
if(maze[i][j]==0)
printf("x");
else
printf(" ");
printf("\n");
}
}