#include #include #include #include #include "Engine.h" Engine::Engine(){ Board* brd = new Board(); b = brd; } void Engine::startGame(){ cout<<"WELCOME\n"; cout<<"1. Play against AI?\n"; cout<<"2. Play against a human?\n"; cout<<"Enter choice: \n"; int choice = -1; cin >> choice; cout << "OK" << endl; string move; bool gameOver = false; vector record; b->snapshot(record, *b); while (gameOver != true){ gameOver = b->isGameOver(); while(b->getTurn() == 'O' && !b->isValid()){ b->displayBoard(); cout<<"\nEnter command: "; cin>>move; cout << "\n"; b->interpret(move, *b); if(b->isValid()){ b->changeTurns(); b->setValidFalse(); } } while(b->getTurn() == 'X' ){ easyAI(); //AI(3); } gameOver = b->isGameOver(); b->setValidFalse(); b->snapshot(record, *b); } } void Engine::easyAI(){ vector listOfMoves = b->viewPossibleMoves(); srand(time(NULL)); int randomChoice = rand() % (listOfMoves.size()-1) - 0; b->move(listOfMoves[randomChoice]); b->changeTurns(); } void Engine::AI(int depth){ Board* temp = new Board(*b); moves empty; MNode* root = new MNode(*temp, empty, 0); //only doing 1 branch right now because testing /*for (int i = 0; i < listOfMoves.size(); ++i){ minMax(b, listOfMoves[i]); }*/ //remove this soon //b->move(minMax(temp, listOfMoves[0], 0, 0)); b->changeTurns(); b->displayBoard(); } moves Engine::minMax(MNode* node, int depth){ Board current = node->getState(); vector listOfMoves = current.viewPossibleMoves(); /* if (current.isGameOver() == true){ cout << "END OF PATH REACHED\n\n"; return m; } else { if(current.getPiece(8 - m.row, m.column)->getType() == current.getTurn() && current.isThisMovePossible(8 - m.row, m.column, m.moveType)){ temp->move(m); temp->evaluate('X', 'O'); temp->changeTurns(); } else { m = minMax(temp, listOfMoves[++r], c, r); } vector listOfMoves = temp->viewPossibleMoves(); minMax(temp, listOfMoves[0], 0, 0); return m; } */ }