diff --git a/Board.cpp b/Board.cpp index 12fb950..6152654 100644 --- a/Board.cpp +++ b/Board.cpp @@ -8,7 +8,7 @@ using namespace std; Board::Board() { - Piece* temp; + Piece* temp; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { @@ -219,8 +219,8 @@ string Board::boardToString(){ Board Board::move(moves m){ int row = m.row; int column = m.column; - Piece* piece; + if (isPiece(row, column)) piece = getPiece(row, column); @@ -231,11 +231,13 @@ Board Board::move(moves m){ if (piece->getType() != turn) { cout<<"ERROR: attempting to move the wrong side's piece.\n"; + return *this; } else { if(isThisMovePossible(row, column, m.moveType)) { + record.push_back(*this); if (m.moveType == "FWD") { piece->moveFwd(); } @@ -282,6 +284,7 @@ Board Board::move(moves m){ } setValidTrue(); } + else { cout << "Invalid move.\n\n"; @@ -435,22 +438,18 @@ string Board::myToUpper(string input){ return output; } -void Board::undo(Board& tablero){ - vector record; - - if (record.size() < 2){ - cout<<"nothing to undo"<& inputVec, Board inputBoard){ diff --git a/Board.h b/Board.h index 85798ae..fe36548 100644 --- a/Board.h +++ b/Board.h @@ -28,12 +28,14 @@ class Board { vector xpieces; vector opieces; vector pieces; + vector record; bool valid, xtaken, otaken; - char turn = 'O'; + char turn = 'O'; public: Board(); Board(const Board& b); + vector getRecord() const{ return record; } void setValidFalse(){ valid = false; } void setValidTrue(){ valid = true; } bool isValid(){ return valid; } @@ -54,7 +56,7 @@ public: bool isThisMovePossible(int r, int c, string moveType); vector viewPossibleMoves(); string myToUpper(string input); - void undo(Board& tablero); + Board* undo(); void snapshot(vector& inputVec, Board inputBoard); int evaluate(char max, char min); }; diff --git a/Engine.cpp b/Engine.cpp index 3478067..70b92bf 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -13,9 +13,11 @@ Engine::Engine(){ b = brd; alpha = INT_MIN; beta = INT_MAX; + undo_cnt = 0; } void Engine::startGame(){ + undo_cnt = 0; cout<<"WELCOME\n"; cout<<"1. Play against AI?\n"; diff --git a/Engine.h b/Engine.h index 3899791..572de20 100644 --- a/Engine.h +++ b/Engine.h @@ -8,7 +8,7 @@ using namespace std; class Engine { Board* b; - int alpha, beta; + int alpha, beta, undo_cnt; public: Engine(); diff --git a/Parser.cpp b/Parser.cpp index 689a213..3db5ec7 100755 --- a/Parser.cpp +++ b/Parser.cpp @@ -29,19 +29,18 @@ string myToUpper(string input) { } void parseAndMove(vector tokens, Board& board) { - //Debugging int col; int row; if(tokens[0].size() == 2) { if(tokens[1].size() >= 3 && tokens[1].size() <= 5) { if(tokens[0][0] - 'A' < 0 || tokens[0][0] - 'A' > 7) { - //cout << "Error. Invalid move location. (1st coord.)\n\n"; + cout << "Error. Invalid move location. (1st coord.)\n\n"; cout << tokens[0][0] << " " << (tokens[0][0] - 'A') << "\n\n"; return; } else if(tokens[0][1] - '0' < 0 || tokens[0][1] - '0' > 7) { - //cout << "Error. Invalid move location. (1st coord.)\n\n"; + cout << "Error. Invalid move location. (1st coord.)\n\n"; return; } else { @@ -64,29 +63,23 @@ void parseAndMove(vector tokens, Board& board) { } } else { - //cout << "Error. Invalid move location. (size)\n\n"; + cout << "Error. Invalid move location. (size)\n\n"; return; } } void parseCmd(vector tokens, Board& board) { if(tokens[0] == "UNDO") { - //Debugging - //cout << "Testing UNDO.\n\n"; - //Change when you fix undo. - board.undo(board); + board = *(board.undo()); } else if(tokens[0] == "DISPLAYRECORD") { - //Debugging - //cout << "Testing DISPLAYRECORD.\n\n"; - /*Fix record, uncomment this. - cout << "recordsize: " << board->getRecord.size(); + cout << "record size: " << board.getRecord().size(); + vector record = board.getRecord(); for(int i = 0; i < record.size(); ++i) { record[i].displayBoard(); } - */ } else { diff --git a/a.out b/a.out new file mode 100755 index 0000000..32f4183 Binary files /dev/null and b/a.out differ