src/sudoku.c
static l_int32
sudokuNewGuess(L_SUDOKU  *sud)
{
l_int32   index, val, valid;
l_int32  *locs, *state;

    locs = sud->locs;
    state = sud->state;
    index = locs[sud->current];  /* 0 to 80 */
    val = state[index];
    if (val == 9) {  /* backtrack or give up */
        if (sud->current == 0) {
            sud->failure = TRUE;
            return 1;
        }
        state[index] = 0;
        sud->current--;
    }
    else {  /* increment current value and test */
        sud->nguess++;
        state[index]++;
        valid = sudokuTestState(state, index);
        if (valid) {
            if (sud->current == sud->num - 1) {  /* we're done */
                sud->finished = TRUE;
                return 0;
            }
            else  /* advance to next position */
                sud->current++;
        }
    }

    return 0;
}
/*!
 *  sudokuNewGuess()
 *
 *      Input:  l_sudoku
 *      Return: 0 if OK; 1 if no solution is possible
 *
 *  Notes:
 *      (1) This attempts to increment the number in the current
 *          location.  If it can't, it backtracks (sets the number
 *          in the current location to zero and decrements the
 *          current location).  If it can, it tests that number,
 *          and if the number is valid, moves forward to the next
 *          empty location (increments the current location).
 *      (2) If there is no solution, backtracking will eventually
 *          exhaust possibilities for the first location.
 */
sudokuNewGuess()
Input:  l_sudoku
Return: 0 if OK; 1 if no solution is possible

(1) This attempts to increment the number in the current
location.  If it can't, it backtracks (sets the number
in the current location to zero and decrements the
current location).  If it can, it tests that number,
and if the number is valid, moves forward to the next
empty location (increments the current location).
(2) If there is no solution, backtracking will eventually
exhaust possibilities for the first location.
sudokuNewGuess () Input : l_sudoku Return : 0 if OK ; 1 if no solution is possible ( 1 ) This attempts to increment the number in the current location . If it can ' t it backtracks ( sets the number in the current location to zero and decrements the current location ) . If it can it tests that number and if the number is valid moves forward to the next empty location ( increments the current location ) . ( 2 ) If there is no solution backtracking will eventually exhaust possibilities for the first location .
static l_int32
sudokuNewGuess(L_SUDOKU  *sud)
{
l_int32   index, val, valid;
l_int32  *locs, *state;
    locs = sud->locs;
    state = sud->state;
    index = locs[sud->current];  
    val = state[index];
    if (val == 9) {  
        if (sud->current == 0) {
            sud->failure = TRUE;
            return 1;
        }
        state[index] = 0;
        sud->current--;
    }
    else {  
        sud->nguess++;
        state[index]++;
        valid = sudokuTestState(state, index);
        if (valid) {
            if (sud->current == sud->num - 1) {  
                sud->finished = TRUE;
                return 0;
            }
            else  
                sud->current++;
        }
    }
    return 0;
}
static l_int32 sudokuNewGuess ( L_SUDOKU * sud ) { l_int32 index , val , valid ; l_int32 * locs , * state ; locs = sud -> locs ; state = sud -> state ; index = locs [ sud -> current ] ; val = state [ index ] ; if ( val == 9 ) { if ( sud -> current == 0 ) { sud -> failure = TRUE ; return 1 ; } state [ index ] = 0 ; sud -> current -- ; } else { sud -> nguess ++ ; state [ index ] ++ ; valid = sudokuTestState ( state , index ) ; if ( valid ) { if ( sud -> current == sud -> num - 1 ) { sud -> finished = TRUE ; return 0 ; } else sud -> current ++ ; } } return 0 ; }
sudokuNewGuess()
      Input:  l_sudoku
      Return: 0 if OK; 1 if no solution is possible
sudokuNewGuess () Input : l_sudoku Return : 0 if OK ; 1 if no solution is possible
/* 0 to 80 */ /* backtrack or give up */ /* increment current value and test */ /* we're done */ /* advance to next position */