diff --git a/Board.cpp b/Board.cpp index 8051c3c..a64bc7a 100755 --- a/Board.cpp +++ b/Board.cpp @@ -5,21 +5,42 @@ using namespace std; Board::Board() { + Piece* temp; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { - xpieces.push_back(new Piece(i, j, 'X')); - pieces.push_back(new Piece(i, j, 'X')); + temp = new Piece(i, j, 'X'); + xpieces.push_back(temp); + pieces.push_back(temp); } } for (int i = 6; i < 8; ++i) { for (int j = 0; j < 8; ++j) { - opieces.push_back(new Piece(i, j, 'O')); - pieces.push_back(new Piece(i, j, 'O')); + temp = new Piece(i, j, 'O'); + opieces.push_back(temp); + pieces.push_back(temp); } } } +Board::Board(const Board& b) { + vector xp = b.getXPieces(); + vector op = b.getOPieces(); + Piece* temp; + + for (int i = 0; i < xp.size(); ++i) { + temp = new Piece(xp[i]->getX(), xp[i]->getY(), 'X'); + xpieces.push_back(temp); + pieces.push_back(temp); + } + + for (int i = 0; i < op.size(); ++i) { + temp = new Piece(op[i]->getX(), op[i]->getY(), 'O'); + opieces.push_back(temp); + pieces.push_back(temp); + } +} + //make this efficient! bool Board::isPiece(int r, int c){ for (int i = 0; i < pieces.size(); ++i){ @@ -92,7 +113,7 @@ void Board::changeTurns(){ if (turn == 'O') turn = 'X'; else turn = 'O'; } - + void Board::displayBoard(){ cout << "; A B C D E F G H"<> boardArray; vector xpieces; vector opieces; vector pieces; - //char boardArray [8][8]; char turn = 'O'; public: Board(); + Board(const Board& b); bool isPiece(int r, int c); Piece* getPiece(int r, int c); + vector getXPieces() const { return xpieces; } + vector getOPieces() const { return opieces; } moves parse(string input); char getTurn() { return turn; } bool isGameOver(); diff --git a/Engine.cpp b/Engine.cpp index 4a83431..23a3161 100755 --- a/Engine.cpp +++ b/Engine.cpp @@ -43,7 +43,7 @@ void Engine::startGame(){ while(b->getTurn() == 'X' ) { - easyAI(); + AI(); } gameOver = b->isGameOver(); @@ -67,12 +67,12 @@ void Engine::easyAI() void Engine::AI(){ cout << "----------------------BEGIN AI FUNCTION----------------------\n"; vector listOfMoves = b->viewPossibleMoves(); - Board temp = *b; + Board* temp = new Board(*b); //probably not needed, check later - if (temp.getTurn() != 'X'){ + if (temp->getTurn() != 'X'){ cout << "a changing of turns is needed. \n"; - temp.changeTurns(); + temp->changeTurns(); } //only doing 1 branch right now because testing @@ -80,7 +80,8 @@ void Engine::AI(){ minMax(temp, listOfMoves[i]); }*/ - //b->moveWOPrint(minMax(temp, listOfMoves[0], 0)); + b->move(minMax(temp, listOfMoves[0], 0)); + b->changeTurns(); //verification of correct turn if (b->getTurn() != 'O'){ @@ -91,30 +92,32 @@ void Engine::AI(){ cout << "----------------------END AI FUNCTION----------------------\n"; } -moves Engine::minMax(Board temp, moves m, int c){ +moves Engine::minMax(Board* temp, moves m, int c){ //testing purposes only - if (c > 5){ + if (c > 5){ return m; } - if (temp.isGameOver() == true){ + if (temp->isGameOver() == true){ cout << "END OF PATH REACHED\n"; return m; } else { - if(temp.isThisMovePossible(8 - m.row, temp.charToIntColumn(m.column), m.moveType)){ + if(temp->isThisMovePossible(8 - m.row, temp->charToIntColumn(m.column), m.moveType)){ cout << "piece has been moved in minMax\n"; - //temp.moveWOPrint(m); + temp->move(m); + temp->changeTurns(); } cout << "c: " << c << "\n\n"; - cout << "current turn: " << temp.getTurn() << "\n"; - vector listOfMoves = temp.viewPossibleMoves(); + cout << "current turn: " << temp->getTurn() << "\n"; + vector listOfMoves = temp->viewPossibleMoves(); for (int i = 0; i < listOfMoves.size(); ++i){ //return minMax(temp, listOfMoves[i]); } + temp->displayBoard(); //limited recursion return minMax(temp, listOfMoves[0], ++c); diff --git a/Engine.h b/Engine.h index 463d05c..97efbf8 100755 --- a/Engine.h +++ b/Engine.h @@ -12,5 +12,5 @@ public: void startGame(); void easyAI(); void AI(); - moves minMax(Board temp, moves m, int c); + moves minMax(Board* temp, moves m, int c); }; \ No newline at end of file diff --git a/a.out b/a.out new file mode 100755 index 0000000..7410dc4 Binary files /dev/null and b/a.out differ diff --git a/test.cpp b/test.cpp index 2851e14..993ed73 100755 --- a/test.cpp +++ b/test.cpp @@ -6,8 +6,7 @@ using namespace std; int main() { //board testing - Board b; - cout << b.boardToString(); + //Board b; //engine testing Engine e;