home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Supreme Volume 6 #1
/
swsii.zip
/
swsii
/
215
/
DDJ9302.ZIP
/
MAZE.ASC
< prev
next >
Wrap
Text File
|
1993-01-11
|
940b
|
38 lines
_CELLULAR AUTOMATA FOR SOLVING MAZES_
by Basem A. Nayfeh
[EXAMPLE ONE]
#define FALSE 0
#define TRUE 1
#define FREE 0
#define WALL 1
do {
steadystate = TRUE;
/* scan the entire CA */
for (x=1;x<Xsize-1;x++) {
for (y=1;y<Ysize-1;y++) {
if (cell[x][y] == FREE) {
/* addition can be used here to determine if */
/* a cell is surrounded by 3 or more walls */
if ((cell[x+1][y] + cell[x-1][y]
+ cell[x][y+1] + cell[x][y-1]) >= 3) {
cell[x][y] = WALL;
steadystate = FALSE;
}
}
}
}
/* keep scanning the CA until */
/* a steady state condition is reached */
} while(!steadystate);
/* the cell array now contains the correct solution(s) */
/* denoted by the remaining free cells */
/* no solution if all cells are now wall cells */