/* * Move to a particular position and see if we hit a mine. * If not, then count the number of mines adjacent to us so it can be seen. * If we are stepping onto a location where we remembered a mine is at, * then don't do it. Moving is only allowed to old locations, or to * locations adjacent to old ones. */ static void movetopos(POS newpos) { POS fixpos; /* position to fix up */ CELL cell; /* current cell */ GR_COUNT count; /* count of cells */ GR_COUNT i; /* index for neighbors */ if ((newpos < 0) || (newpos >= (FULLSIZE * FULLSIZE)) || !playing) return; cell = board[newpos]; if (isedge(cell) || (isseen(cell)) || isold(cell)) return; count = isold(cell); for (i = 0; i < 8; i++) if (isold(board[newpos + steptable[i]])) count++; if (count <= 0) return; cell = (cell & F_FLAGS) | F_OLD; steps++; PRINTSTEPS; if (ismine(cell)) { /* we hit a mine */ legs--; board[newpos] = (F_REMEMBER | F_MINE); cell = (F_EMPTY | F_OLD); board[newpos] = cell; drawbomb(newpos, redgc, GR_TRUE); clearcell(newpos); setcursor(); for (i = 0; i < 8; i++) { fixpos = newpos + steptable[i]; if (isold(board[fixpos])) { board[fixpos]--; drawcell(fixpos); } } drawstatus(); } count = 0; for (i = 0; i < 8; i++) if (ismine(board[newpos + steptable[i]])) count++; board[newpos] = cell | (count + '0'); drawcell(newpos); if ((legs <= 0) || (newpos == boardpos(size,size))) gameover(); }
/* * Here when the game is over. * Show where the mines are, and give the results. */ static void gameover(void) { POS pos; CELL cell; playing = GR_FALSE; switch (legs) { case 0: games0[index]++; steps0[index] += steps; break; case 1: games1[index]++; steps1[index] += steps; break; case 2: games2[index]++; steps2[index] += steps; break; } for (pos = 0; pos < (FULLSIZE * FULLSIZE); pos++) { cell = board[pos]; if (isseen(cell)) cell = (cell & F_FLAGS) | F_WRONG; if (ismine(cell)) cell = (cell & F_FLAGS) | F_REMEMBER; board[pos] = cell; } drawboard(); drawstatus(); }
/* * Initialize the board for playing */ static void newgame(void) { GR_COORD row; GR_COORD col; GR_COUNT count; CELL cell; POS pos; for (row = 0; row < FULLSIZE; row++) { for (col = 0; col < FULLSIZE; col++) { cell = F_EMPTY; if (badsquare(row) || badsquare(col)) cell |= F_EDGE; board[boardpos(row, col)] = cell; } } playing = GR_TRUE; count = 0; legs = 2; steps = 0; drawstatus(); setcursor(); while (count < mines) { do { row = (rand() / 16) % (size * size + 1); } while (row == (size * size)); col = (row % size) + 1; row = (row / size) + 1; pos = boardpos(row, col); if ((pos == boardpos(1,1)) || (pos == boardpos(1,2)) || (pos == boardpos(2,1)) || (pos == boardpos(2,2)) || (pos == boardpos(size,size))) continue; if (!ismine(board[pos]) && checkpath(pos)) count++; } board[boardpos(1,1)] = (F_OLD | '0'); GrClearWindow(boardwid, GR_TRUE); }
/* * Process any unhandled replication entries in the queue. */ static int Ri_process( Ri *ri ) { Rq *rq = sglob->rq; Re *re = NULL, *new_re = NULL; int rc ; char *errmsg; (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); #ifdef SIGPIPE (void) SIGNAL( SIGPIPE, SIG_IGN ); #endif if ( ri == NULL ) { #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, ERR, "Ri_process: " "Error: ri == NULL!\n", 0, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 ); #endif return -1; } /* * Startup code. See if there's any work to do. If not, wait on the * rq->rq_more condition variable. */ rq->rq_lock( rq ); while ( !sglob->slurpd_shutdown && (( re = rq->rq_gethead( rq )) == NULL )) { /* No work */ if ( sglob->one_shot_mode ) { /* give up if in one shot mode */ rq->rq_unlock( rq ); return 0; } /* wait on condition variable */ ldap_pvt_thread_cond_wait( &rq->rq_more, &rq->rq_mutex ); } /* * When we get here, there's work in the queue, and we have the * queue locked. re should be pointing to the head of the queue. */ rq->rq_unlock( rq ); while ( !sglob->slurpd_shutdown ) { if ( re != NULL ) { if ( !ismine( ri, re )) { /* The Re doesn't list my host:port */ #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " "Replica %s:%d, skip repl record for %s (not mine)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); #else Debug( LDAP_DEBUG_TRACE, "Replica %s:%d, skip repl record for %s (not mine)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); #endif } else if ( !isnew( ri, re )) { /* This Re is older than my saved status information */ #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " "Replica %s:%d, skip repl record for %s (old)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); #else Debug( LDAP_DEBUG_TRACE, "Replica %s:%d, skip repl record for %s (old)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); #endif } else { rc = do_ldap( ri, re, &errmsg ); switch ( rc ) { case DO_LDAP_ERR_RETRYABLE: ldap_pvt_thread_sleep( RETRY_SLEEP_TIME ); #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " "Retrying operation for DN %s on replica %s:%d\n", re->re_dn, ri->ri_hostname, ri->ri_port ); #else Debug( LDAP_DEBUG_ANY, "Retrying operation for DN %s on replica %s:%d\n", re->re_dn, ri->ri_hostname, ri->ri_port ); #endif continue; break; case DO_LDAP_ERR_FATAL: { /* Non-retryable error. Write rejection log. */ int ld_errno = 0; ldap_get_option(ri->ri_ldp, LDAP_OPT_ERROR_NUMBER, &ld_errno); write_reject( ri, re, ld_errno, errmsg ); /* Update status ... */ (void) sglob->st->st_update( sglob->st, ri->ri_stel, re ); /* ... and write to disk */ (void) sglob->st->st_write( sglob->st ); } break; default: /* LDAP op completed ok - update status... */ (void) sglob->st->st_update( sglob->st, ri->ri_stel, re ); /* ... and write to disk */ (void) sglob->st->st_write( sglob->st ); break; } } } else { #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, ERR, "Ri_process: " "Error: re is null in Ri_process\n", 0, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "Error: re is null in Ri_process\n", 0, 0, 0 ); #endif } rq->rq_lock( rq ); while ( !sglob->slurpd_shutdown && ((new_re = re->re_getnext( re )) == NULL )) { if ( sglob->one_shot_mode ) { rq->rq_unlock( rq ); return 0; } /* No work - wait on condition variable */ ldap_pvt_thread_cond_wait( &rq->rq_more, &rq->rq_mutex ); } re->re_decrefcnt( re ); re = new_re; rq->rq_unlock( rq ); if ( sglob->slurpd_shutdown ) { return 0; } } return 0; }