src/fsss.cpp
//Set the initially known digits.
//The context is updated on 2 passes.

Set the initially known digits.
The context is updated on 2 passes.
Set the initially known digits . The context is updated on 2 passes .
static inline void init(game &g, const char* in)
{
	bitmap *gkd = g.groupKnownDigits;
	bitmap *cp = g.cellPossibilities;
	for(int i = 0; i < 81; i++) {
		if(in[i] == 0) continue;
		bitmap bm = Digit2Bitmap[in[i]];
		const int *ag = affectedGroups[i];
		if(bm & (gkd[ag[0]] | gkd[ag[1]] | gkd[ag[2]])) {
			g.mode |= MODE_STOP_PROCESSING;
			return;
		}
		cp[i] = 0; 
		if(g.cellDigits) {
			g.cellDigits[i] = (cellDigit)bm; 
		}
		if(0 == --g.cellsLeft) {
			solutionFound(g);
			return;
		}
		gkd[ag[0]] |= bm; gkd[ag[1]] |= bm; gkd[ag[2]] |= bm;
	}
	for(int i = 0; i < 81; i++) {
		bitmap &bm = cp[i];
		const int *ag = affectedGroups[i];
		bitmap knowns = gkd[ag[0]] | gkd[ag[1]] | gkd[ag[2]];
		if(bm & knowns) { 
			bm &= ~knowns;
			if(bm == 0) { 
				g.mode |= MODE_STOP_PROCESSING;
				return;
			}
			if(Bitmap2Digit[bm]) { 
				setDigit(g, i, bm);
				if(g.mode & MODE_STOP_PROCESSING) return;
			}
		}
	}
	g.lastGuess = 81 - g.cellsLeft; 
}
static inline void init ( game & g , const char * in ) { bitmap * gkd = g . groupKnownDigits ; bitmap * cp = g . cellPossibilities ; for ( int i = 0 ; i < 81 ; i ++ ) { if ( in [ i ] == 0 ) continue ; bitmap bm = Digit2Bitmap [ in [ i ] ] ; const int * ag = affectedGroups [ i ] ; if ( bm & ( gkd [ ag [ 0 ] ] | gkd [ ag [ 1 ] ] | gkd [ ag [ 2 ] ] ) ) { g . mode |= MODE_STOP_PROCESSING ; return ; } cp [ i ] = 0 ; if ( g . cellDigits ) { g . cellDigits [ i ] = ( cellDigit ) bm ; } if ( 0 == -- g . cellsLeft ) { solutionFound ( g ) ; return ; } gkd [ ag [ 0 ] ] |= bm ; gkd [ ag [ 1 ] ] |= bm ; gkd [ ag [ 2 ] ] |= bm ; } for ( int i = 0 ; i < 81 ; i ++ ) { bitmap & bm = cp [ i ] ; const int * ag = affectedGroups [ i ] ; bitmap knowns = gkd [ ag [ 0 ] ] | gkd [ ag [ 1 ] ] | gkd [ ag [ 2 ] ] ; if ( bm & knowns ) { bm &= ~ knowns ; if ( bm == 0 ) { g . mode |= MODE_STOP_PROCESSING ; return ; } if ( Bitmap2Digit [ bm ] ) { setDigit ( g , i , bm ) ; if ( g . mode & MODE_STOP_PROCESSING ) return ; } } } g . lastGuess = 81 - g . cellsLeft ; }
Set the initially known digits.
Set the initially known digits .
//First pass: set the digits w/o updating the affected cells.
 //...additional input checking here...
 //setDigit(g, i, Digit2Bitmap[in[i]]);
 //...check for error here if this is the goal...
 //if the digit we are setting has been previously set for one of
 //the 3 groups the cell is member of, we are in wrong way
 //clear the mask to exclude this cell from further processing
 //set the digit. Bit 8 is lost, translating 9 to 0.
 //lucky, 81 givens
 //g->mode |= MODE_STOP_GUESSING;
 //g->nSolutions = 1;
 //set the digit as solved for all 3 groups
 //Second pass: update the affected cells.
 //Overall performance improvement is about 9% compared to setDigit calls.
 //checkBoard(g, gkd, cp);
 //there are possibilities to be cleared
 //no possibilities for this cell
 //single digit?
 //randomize guessing positions
