diff --git a/Board.cpp b/Board.cpp index 1b161d2..0282dc8 100755 --- a/Board.cpp +++ b/Board.cpp @@ -81,6 +81,7 @@ bool Board::isGameOver() void Board::changeTurns() { + cout << "TURN IS BEING CHANGED\n"; if (turn == 'O') turn = 'X'; else turn = 'O'; } @@ -99,7 +100,7 @@ void Board::displayBoard() cout<<"|\n"; } cout<<'\n'< 8 || row < 0 || kolumn > 8 || kolumn < 0) + { + cout<<"ERROR: index out of bound in second move()!"<& inputVec, Board inputBoard) } inputVec.push_back(inputBoard); +} + +void Board::testPrint(){ + for (int i = 7; i >= 0; --i){ + for (int j = 7; j >= 0; --j){ + cout << boardArray[i][j] << " "; + } + + cout << "\n"; + } } \ No newline at end of file diff --git a/Board.h b/Board.h index eecdeb3..19cdc62 100755 --- a/Board.h +++ b/Board.h @@ -34,10 +34,12 @@ public: char intToCharColumn(int input); void move(string inputMove); void move(moves jugada); + void moveWOPrint(moves jugada); bool isThisMovePossible(int r, int c, string moveType); vector viewPossibleMoves(); string myToUpper(string input); void undo(Board& tablero); void interpret(string input, Board& tablero); void snapshot(vector& inputVec, Board inputBoard); + void testPrint(); }; \ No newline at end of file diff --git a/Engine.cpp b/Engine.cpp index 72998de..5f4b602 100755 --- a/Engine.cpp +++ b/Engine.cpp @@ -85,41 +85,48 @@ void Engine::easyAI() void Engine::AI(){ cout << "----------------------BEGIN AI FUNCTION----------------------\n"; vector listOfMoves = b->viewPossibleMoves(); - Board* temp = b; - if (temp->getTurn() != 'X'){ - temp->changeTurns(); + Board temp = *b; + + //probably not needed, check later + if (temp.getTurn() != 'X'){ + cout << "a changing of turns is needed. \n"; + temp.changeTurns(); } - //temp->changeTurns(); - //cout << "after: " << temp->getTurn() << "\n"; //only doing 1 branch right now because testing /*for (int i = 0; i < listOfMoves.size(); ++i){ minMax(temp, listOfMoves[i]); }*/ - minMax(temp, listOfMoves[0]); - - b->move(listOfMoves[0]); + b->moveWOPrint(minMax(temp, listOfMoves[0], 0)); + b->displayBoard(); cout << "----------------------END AI FUNCTION----------------------\n"; } -void Engine::minMax(Board* temp, moves m){ - if (temp->isGameOver() == true){ +moves Engine::minMax(Board temp, moves m, int c){ + //testing purposes only + if (c > 1000){ + return m; + } + + if (temp.isGameOver() == true){ cout << "END OF PATH REACHED\n"; - return; + return m; } else { + if(temp.isThisMovePossible(8 - m.row, temp.charToIntColumn(m.column), m.moveType)){ + cout << "piece has been moved in minMax\n"; + temp.moveWOPrint(m); + } + cout << "c: " << c << "\n\n"; + cout << "current turn: " << temp.getTurn() << "\n"; + vector listOfMoves = temp.viewPossibleMoves(); + + for (int i = 0; i < listOfMoves.size(); ++i){ + cout << "listOfMoves[i]: (" << listOfMoves[i].row << ", " << listOfMoves[i].column << ")\n"; + //minMax(temp, listOfMoves[i]); + } - cout << "m.row: " << m.row << "\n"; - cout << "charToIntColumn(m.column): " << temp->charToIntColumn(m.column) << "\n"; - cout << "m.moveType: " << m.moveType << "\n"; - cout << "temp->isThisMovePossible(stuff): " << temp->isThisMovePossible(m.row, temp->charToIntColumn(m.column), m.moveType) << "\n\n\n"; - - vector listOfMoves = temp->viewPossibleMoves(); - /*for (int i = 0; i < listOfMoves.size(); ++i){ - minMax(temp, listOfMoves[i]); - }*/ - - temp->displayBoard(); + return minMax(temp, listOfMoves[0], ++c); } } \ No newline at end of file diff --git a/Engine.h b/Engine.h index 4011d23..463d05c 100755 --- a/Engine.h +++ b/Engine.h @@ -12,5 +12,5 @@ public: void startGame(); void easyAI(); void AI(); - void minMax(Board* temp, moves m); + moves minMax(Board temp, moves m, int c); }; \ No newline at end of file diff --git a/test.cpp b/test.cpp index 8b1eb77..65f07dc 100755 --- a/test.cpp +++ b/test.cpp @@ -4,6 +4,10 @@ using namespace std; int main() { + //board testing + Board b; + + //engine testing Engine e; e.startGame(); }