/////////////////////////////////////////////////////////////////////
// The Jewel Game //
// by Nick Cash //
// //
// Fall 2007 //
// 810:161 - Artificial Intelligence //
// //
// main.cpp - contains main(), the starting point for the program //
/////////////////////////////////////////////////////////////////////
// standard includes
#include <cstdlib>
#include <ctime>
#include <iostream>
// custom includes
#include "game.h"
// setup the namespace so we dont have "std::" everywhere
using namespace std;
// Search functions
std::string BreadthSearch( cGameBoard* );
std::string DepthLimitedSearch( cGameBoard* ); // recursive implementation
std::string IterativeDeepeningSearch( cGameBoard* ); // uses recursive DLS as well
// Everything starts here
int main(int argc, char *argv[])
{
cGameBoard board; // our initial instance of a game board
string solution; // holds our solution string of spells
time_t start,end; // hold some timing values
double dif; // timing value
// use input to setup our game board
if ( SetupGameBoard(board, argc, argv) == false )
{
cout << endl << "Failed to intialize game board. Make sure you input a valid argument of length 9." << endl;
return EXIT_FAILURE;
}
// print the initial board
cout << "\n\nInitial Board\n-------------\n";
board.Print();
cout << endl << endl;
// Start timer
time(&start);
// check which function to use
switch ( search_function )
{
default:
case 0:
cout << "Using Iterative Deepening Search\n";
solution = IterativeDeepeningSearch(&board);
break;
case 1:
cout << "Using Depth Limited Search.\n";
solution = DepthLimitedSearch(&board);
break;
case 2:
cout << "Using Breadth First Search.\n";
solution = BreadthSearch(&board);
break;
}
// End timer and calculate the difference in time
time(&end);
dif = difftime(end,start);
// add spaces to solution
solution = AddSpaces(solution);
// Print out our data
cout << "Spell solution -> " << solution << endl;
cout << "Search lasted -> " << dif << " seconds" << endl;
cout << "Nodes stored -> " << nodes_stored << endl;
cout << "Nodes expanded -> " << nodes_expanded << endl;
return EXIT_SUCCESS;
}