ai structure done

This commit is contained in:
Rebecca Schofield 2015-11-02 17:27:45 -06:00
parent 0b5b8be258
commit e2be536254
2 changed files with 18 additions and 10 deletions

View file

@ -23,19 +23,23 @@ void Engine::startGame(){
int choice = -1;
cin >> choice;
cout<<"Enter AI difficulty: \n";
int difficulty;
cin >> difficulty;
cout << "OK" << endl;
if (choice == 1)
userGame();
userGame(difficulty);
else if (choice == 2)
AIGame();
AIGame(difficulty);
else {
cout << "Please enter a valid choice.\n";
startGame();
}
}
void Engine::userGame(){
void Engine::userGame(int difficulty){
string move;
bool gameOver = false;
@ -60,39 +64,43 @@ void Engine::userGame(){
}
while(b->getTurn() == 'X' ){
//easyAI();
AI(3);
AI(difficulty);
}
gameOver = b->isGameOver();
b->setValidFalse();
b->snapshot(record, *b);
}
b->displayBoard();
string s = "";
s += b->getTurn();
cout << "Game over. " + s + " wins!\n\n";
}
void Engine::AIGame(){
void Engine::AIGame(int difficulty){
bool gameOver = false;
while (gameOver != true){
gameOver = b->isGameOver();
while(b->getTurn() == 'O'){
AI(3);
AI(difficulty);
}
b->displayBoard();
sleep(1);
while(b->getTurn() == 'X' ){
AI(3);
AI(difficulty);
}
gameOver = b->isGameOver();
}
string s = "";
s += b->getTurn();
cout << "Game over. " + s + " wins!\n\n";
}
void Engine::AI(int depth){

View file

@ -13,8 +13,8 @@ public:
Engine();
Board* getBoard() { return b; }
void startGame();
void userGame();
void AIGame();
void userGame(int difficulty);
void AIGame(int difficulty);
void AI(int depth);
void createMMTree(MNode* node, int depth, int alt);
moves evaluateMMTree(MNode* node);