Esempio n. 1
0
void puzzle_i()
{
    Blocks bs;
    Board board(5, 6);

    bs.push_back(&(*(new Block()))("***"));
    bs.push_back(&(*(new Block()))("***| *| *"));
    bs.push_back(&(*(new Block()))("**|**"));
    bs.push_back(&(*(new Block()))("*|**"));
    bs.push_back(&(*(new Block()))(" **| *|**"));
    bs.push_back(&(*(new Block()))("*|*"));
    bs.push_back(&(*(new Block()))("***|  *"));
    bs.push_back(&(*(new Block()))("*|**| *"));

    cout << "---------- Puzzle I ----------" << endl;

    if (!board.Unblock(bs))
    {
        cout << "No solution!" << endl;
    }

    for (auto i = bs.cbegin(); i != bs.cend(); i++)
    {
        delete (*i);
    }
}
Esempio n. 2
0
// Start solving the problem.
bool Board::Unblock(Blocks bs)
{
    count_setblock = 0;
    count_checkblock = 0;
    count_setcell = 0;
    count_checkcell = 0;

    // Sort Blocks by block weight
    sort(bs.begin(), bs.end(), [](Block *a, Block *b)
    {
        return (a->weight > b->weight);
    });

    for (auto i = bs.cbegin(); i != bs.cend(); i++)
    {
        (*i)->Print("Block " + to_string(i - bs.cbegin()));
    }

    // Find solution
    bool result = RecursiveSetBlock(bs, 0);

    cout << "count_setblock   = " << count_setblock << endl
         << "count_checkblock = " << count_checkblock << endl
         << "count_setcell    = " << count_setcell << endl
         << "count_checkcell  = " << count_checkcell << endl;

    return result;
}