Exemple #1
0
void ZoneOpenRandomTiles(Puzzle & pzl, u8 & opens, const u8* it1, const u8* it2)
{
    std::vector<u8> values;
    values.reserve(25);
    const u8* it = NULL;

    while(opens)
    {
	values.clear();
	it = it1;
	while(it && it2 && it <= it2){ if(! pzl.test(*it)) values.push_back(*it); ++it; }
	if(values.empty()) break;
	pzl.set(*Rand::Get(values));
	--opens;
    }
}
void PartialSolver::solve()
{
    while(!puzzles.empty())
    {
        Puzzle& front = puzzles.front();
        ///Clear points to find points for next puzzle
        points.clear();
        findPoints(front.puzzle);
        list< pair<int,int> >::iterator it = points.begin();
        for(;it!=points.end(); it++)
        {
            int row = (*it).first;
            int col = (*it).second;
            Puzzle back = Puzzle(front);
            try
            {
                back.set(row, col, variable);
                back.solve();
                if(back.complete())
                {
                    if(back.correct())
                    {
                            solved.push_back(back);
                    }
                    else
                    {
                            incorrect.push_back(back);
                    }
                }
                else
                {
                    ///If the puzzle is still partially correct continue search
                    if(partiallyCorrect(back))
                        puzzles.push_back(back);
                }
            } catch (bool& value) {
                //incorrect.push_back(back);
            }
        }
        puzzles.pop_front();
    }
}