These questions refer to a maze program (16x16 block)
first question:
- here is a function I am trying to replace
void lvl0_get_walls(int y, int x, int *North, int *East, int *West, int *South);
/* This function indirectly returns the walls (1 for present, 0 of absent)
in the cell y, x from the internal maze. Avaliable only at Level 0
or 1. */
I am assuming to use a 2D array so I can create my own maze, I made a few different data files with the respective x,y coordinates and 1's/0's to represent if walls are there or not. How do I include this in my driver? I got this from my text but don't really understand how it works/ what I have to change so it'll read in my data file:
Code:
int i,j;
FILE *fp;
if((fp = fopen("file","r")) == NULL)
{ fprintf(stderr,"Unable to open file\n");
exit(1);
}
for(i = 0; i < MAX_ROWS; i++)
for(j = 0; j < MAX_COLS; j++)
fscanf(fp, "%d", &a[i][j]);
fclose(fp);
Here's a sample of my data file:
/* x y n e w s */
0 0 0 0 1 1
0 1 0 0 1 0
0 2 0 0 1 0
0 3 1 0 1 0
another version I made that doesnt include the x,y:
/* south walls */
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1
...did the same for north,east and west walls as well
2nd question:
I have to count the number of unique cells visited in the maze, we already have a basic cell counter which increments on every move. How do I go about setting up a unique counter? I'm thinking something along the lines of when a new cell is visited it will set a variable to TRUE and increment the count. how would I set all cells to unvisited?
Thanks!