int main(void) {

	readAndVerify();
	//addTextToLocation();
	return EXIT_SUCCESS;
}
示例#2
0
int main()
{
    std::list<Puzzle> solutions;
    
    static std::stack<Puzzle> alternatives;
    
    char inputString[81];
    
    std::string inputPuzzle = readAndVerify(inputString);
    
    Puzzle puzzle(inputPuzzle);
    
    puzzle.generatePossibleValues();
    
    alternatives.push(puzzle);
    
    while (!alternatives.empty())
    {
        puzzle = alternatives.top();
        alternatives.pop();
        
        //decide all immediately decideable cells
        puzzle.decideCells();
        
        //try simplification strats
        bool simplificationFound = true;
        while (!puzzle.solved() && simplificationFound)
        {
            simplificationFound = false;
            do
            {
                simplificationFound = hiddenSingles(puzzle);
            }
            while (simplificationFound == true);
            
            //fall back to guessing
            if (!simplificationFound)
            {
                Puzzle alternative;
                alternative = *clone(puzzle);
                if ((simplificationFound = guess(puzzle, alternative)))
                {
                    //record alternative if guess is wrong
                    alternatives.push(alternative);
                }
            }
            
            //decide all immediately decidable cells before looking for further simplifications
            if (simplificationFound)
            {
                puzzle.decideCells();
            }
        }
        
        
        //if solution is found or contradiction is found(no simplifications)
        if (puzzle.solved())
        {
            solutions.push_back(puzzle);
        }
    }
    
    if (solutions.empty())
    {
        std::cout << "No solutions.\n";
    }
    
    if (!solutions. empty())
    {
        while (!solutions.empty())
        {
            solutions.front().printPuzzle();
            solutions.pop_front();
        }
    }
    
    std::exit(0);
    
}//end main