diff --git a/Board.cpp b/Board.cpp index 7c89ecd..72fb1ea 100755 --- a/Board.cpp +++ b/Board.cpp @@ -28,7 +28,8 @@ Board::Board(const Board& b) { vector xp = b.getXPieces(); vector op = b.getOPieces(); Piece* temp; - bool valid = false; + //bool valid = false; + //char tempturn = b.getTurn(); for (int i = 0; i < xp.size(); ++i) { temp = new Piece(xp[i]->getX(), xp[i]->getY(), 'X'); diff --git a/Engine.cpp b/Engine.cpp index 96f0867..d2d9d02 100755 --- a/Engine.cpp +++ b/Engine.cpp @@ -69,7 +69,7 @@ void Engine::easyAI() srand(time(NULL)); int randomChoice = rand() % (listOfMoves.size()-1) - 0; - int temp = randomChoice; + //int temp = randomChoice; cout << "easy AI move: " << listOfMoves[randomChoice].row << listOfMoves[randomChoice].column << listOfMoves[randomChoice].moveType << "\n"; b->move(listOfMoves[randomChoice]); b->changeTurns(); @@ -78,7 +78,7 @@ void Engine::easyAI() void Engine::AI(){ cout << "----------------------BEGIN AI FUNCTION----------------------\n"; vector listOfMoves = b->viewPossibleMoves(); - //Board* b = new Board(*b); + Board* temp = new Board(*b); //probably not needed, check later /* @@ -92,7 +92,7 @@ void Engine::AI(){ minMax(b, listOfMoves[i]); }*/ - b->move(minMax(listOfMoves[0], 0)); + b->move(minMax(temp, listOfMoves[0], 0)); b->changeTurns(); //verification of correct turn @@ -105,37 +105,41 @@ void Engine::AI(){ cout << "----------------------END AI FUNCTION----------------------\n"; } -moves Engine::minMax(moves m, int c){ +moves Engine::minMax(Board* temp, moves m, int c){ //testing purposes only, c = finite depth - /* + + cout << "c: " << c << "\n\n"; + cout << "current turn: " << temp->getTurn() << "\n"; + vector listOfMoves = temp->viewPossibleMoves(); if (c > 5){ return m; } - if (b->isGameOver() == true){ + if (temp->isGameOver() == true){ cout << "END OF PATH REACHED\n"; return m; } else { - if(b->isThisMovePossible(8 - m.row, b->charToIntColumn(m.column), m.moveType)){ + if(temp->isThisMovePossible(m.row, m.column, m.moveType) && temp->getPiece(m.row, m.column)->getType() == temp->getTurn()){ cout << "piece has been moved in minMax\n"; - b->move(m); - b->changeTurns(); + temp->move(m); + temp->changeTurns(); + temp->displayBoard(); + } + else { + m = minMax(temp, listOfMoves[c+1], c+1); } - cout << "c: " << c << "\n\n"; - cout << "current turn: " << b->getTurn() << "\n"; - vector listOfMoves = b->viewPossibleMoves(); for (int i = 0; i < listOfMoves.size(); ++i){ //return minMax(b, listOfMoves[i]); } - b->displayBoard(); + temp->displayBoard(); //limited recursion - return minMax(b, listOfMoves[0], ++c); + minMax(temp, listOfMoves[c], ++c); //testing return m; - }*/ + } } \ No newline at end of file diff --git a/Engine.h b/Engine.h index d1b3809..97efbf8 100755 --- a/Engine.h +++ b/Engine.h @@ -12,5 +12,5 @@ public: void startGame(); void easyAI(); void AI(); - moves minMax(moves m, int c); + moves minMax(Board* temp, moves m, int c); }; \ No newline at end of file