summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: 8ccbf73203cae80fec520d4a25d883be8dc1275b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Kamil Kaminski
 * NetID: kkamin8
 *
 * CS340
 * Project 3, Sliding Block Puzzles
 *
 *
 */

#include "main.h"

int main(int argc, char *argv[])
{
    /* seed rand() */
    srand((unsigned int ) time(NULL));

    if (argc != 2)
    {
        cout << "usage: " << argv[0] << " <file>" << endl;
        return -1;
    }

    cout << "\tSliding Block Puzzles" << endl << endl;

    Grid grid = loadGrid(argv);
    printGrid(grid);
    queue<Grid> toCheck;
    queue<Grid> checked;

    /* kickstart the queue */
    possibleMoves(grid, toCheck);

    /* main algorithm */
    while (!toCheck.empty())
    {
        Grid popped = toCheck.front();
        toCheck.pop();

        if (checkSoln(popped))
        {
            cout << "Solution: " << endl;
            printGrid(popped);

            cout << "Steps: " << endl;
            popped.printMoves();
            break;
        }
        else
            possibleMoves(popped, toCheck);
    }

    cout << "\n\tBye!" << endl;
    return 0;
}