I'm still supposed to be studying, but it was bugging me to have a piece of code out when it still had OBVIOUS bugs in it. The fix was pretty quick, and I'm including the corrected patch below. APPLY THIS TO THE ORIGINAL FILES, not to the files as patched. diff -rc2 mines/README mines2/README *** mines/README Tue Oct 3 21:31:37 1989 --- mines2/README Sun Oct 6 00:22:04 1991 *************** *** 7,10 **** --- 7,12 ---- * - July 1988 * + * Patched with unofficial patch "kak 0.2" + * Here are the sources for the mines game. I hacked this up from the chess tool - you might recognize the lineage. I've been too lazy to write a diff -rc2 mines/board.c mines2/board.c *** mines/board.c Tue Oct 3 21:31:40 1989 --- mines2/board.c Sun Oct 6 00:38:15 1991 *************** *** 23,26 **** --- 23,30 ---- BOOL BlewUpSelf; + #define DEFAULT_HUNT TRUE + BOOL AutoHunt = DEFAULT_HUNT; + void FindSafe(sx,sy); + /* * set up the playing surface at the beginning of the game *************** *** 418,423 **** --- 422,432 ---- { PlayerLocation = * dest; + if (AutoHunt) { + sqp->traversed = FALSE; /* kludge for FindSafe */ + FindSafe(dest->x,dest->y); + } sqp->traversed = sqp->occupied = TRUE; DrawSquare(dest); + Message(MineWarningMessage()); } *************** *** 456,471 **** { static char warning[128]; ! register int x, y; ! int minesFound; ! ! minesFound = 0; ! for (x = PlayerLocation.x - 1 ; x <= PlayerLocation.x + 1 ; x++) { ! for (y = PlayerLocation.y - 1 ; y <= PlayerLocation.y + 1 ; y++) { ! if (x >= 0 && x < XSIDE_SIZE && y >= 0 && y < YSIDE_SIZE && MainBoard[x][y].mined) ! if( ! MainBoard[x][y].blown ) ! minesFound++; ! } ! } ! sprintf(warning, "%d mine(s) nearby", minesFound); return(warning); } --- 465,470 ---- { static char warning[128]; ! sprintf(warning, "%d mine(s) nearby", ! MineCount(PlayerLocation.x,PlayerLocation.y)); return(warning); } *************** *** 490,491 **** --- 489,551 ---- } + /* + * count how many bombs next to this square. + */ + /* Square MainBoard[XSIDE_SIZE][YSIDE_SIZE]; */ + int + MineCount(sx,sy) + int sx, sy; + { + register int x, y; + int minesFound = 0; + + if (sx < 0 || sx >= XSIDE_SIZE || sy < 0 || sy >= YSIDE_SIZE ) + return -1; + for (x = sx - 1; x <= sx + 1 ; x++) { + for (y = sy - 1; y <= sy + 1 ; y++) { + if (x >= 0 && x < XSIDE_SIZE && y >= 0 && y < YSIDE_SIZE + && MainBoard[x][y].mined) + if( ! MainBoard[x][y].blown ) + minesFound++; + } + } + return minesFound; + } + /* + * Locate "most" contiguous square with no bombs in them. + * (this algorithm may miss an orignally dangerous but now safe square -- + * so what? It's just for convience anyway.) + */ + /* Square MainBoard[XSIDE_SIZE][YSIDE_SIZE]; */ + void + FindSafe(sx,sy) + int sx, sy; + { + register int x, y; + Coordinate dest; + register Square * sqp; + + if (sx < 0 || sx >= XSIDE_SIZE || sy < 0 || sy >= YSIDE_SIZE) + return; + + sqp = &MainBoard[sx][sy]; + + if (sqp->traversed == TRUE ) + return; + if (MineCount(sx,sy) != 0 ) { + sqp->safe = TRUE; + sqp->unsafe = FALSE; + } + else { + + sqp->traversed = TRUE; + + for (x = sx - 1; x <= sx + 1 ; x++) + for (y = sy - 1; y <= sy + 1 ; y++) + FindSafe(x,y); + } + dest.x = sx; + dest.y = sy; + DrawSquare(&dest); + return; + } diff -rc2 mines/version.h mines2/version.h *** mines/version.h Sun Oct 6 00:20:35 1991 --- mines2/version.h Sun Oct 6 00:23:08 1991 *************** *** 0 **** --- 1,2 ---- + static char *VERSION = "unixpc mines: unofficial patch kak 0.2"; + static char *VERDATE = "Sun Oct 6 00:14:45 EDT 1991";