#include #include #include "Board.h" using namespace std; Board::Board() { for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { xpieces.push_back(new Piece(i, j, 'X')); } } for (int i = 6; i < 8; ++i) { for (int j = 0; j < 8; ++j) { opieces.push_back(new Piece(i, j, 'O')); } } } bool Board::elemInXs(int r, int c){ for (int i = 0; i < xpieces.size(); ++i){ if (xpieces[i]->getX() == r && xpieces[i]->getY() == c){ return true; } } return false; } bool Board::elemInOs(int r, int c){ for (int i = 0; i < opieces.size(); ++i){ if (opieces[i]->getX() == r && opieces[i]->getY() == c){ return true; } } return false; } moves Board::parse(string input) { input = myToUpper(input); int temp1; char temp2; string temp3; temp2 = input[0]; temp1 = input[1] - '0'; if (input[3] == 'L') { temp3 = "LEFT"; } else if (input[3] == 'R') { temp3 = "RIGHT"; } else { temp3 = "FWD"; } moves output(temp1, temp2, temp3); return output; } bool Board::isGameOver() { for (int i = 0; i < xpieces.size(); ++i){ if (xpieces[i]->getX() == 0){ cout<<"\n\n\nPlayer X wins!\n\n\n"<getX() == 7){ cout<<"\n\n\nPlayer O wins!\n\n\n"< 8 || row < 0 || column > 8 || column < 0) { cout<<"ERROR: index out of bound."<getType(); cout << "temp: " << temp << "\n"; if (temp != turn || temp == '_') { cout<<"ERROR: attempting to move an invalid piece."<moveFwd(); } else if (jugada.moveType == "LEFT") { if (column == 0) cout<<"Destination Spot out of range!"<getType() == temp) cout<<"you hate your own team or something? you can't do that!"<moveLeft(); } else if (jugada.moveType == "RIGHT") { if (column == 7) cout<<"Destination Spot out of range!"<getType() == temp) cout<<"you hate your own team or something? you can't do that!"<moveRight(); } } } */ //FIX THIS //take out the prints and turn changes from move void Board::moveWOPrint(moves jugada) { // } /* bool Board::isThisMovePossible(int r, int c, string moveType) { char pieceToMove = boardArray[r][c]->getType(); if (pieceToMove != turn) //trying to move invalid piece { cout << "Error in Board::isThisMovePossible: trying to move a piece outside your turn.\n"; return false; } int reflector = 1; if (pieceToMove == 'O') { reflector *= -1; } else { if (moveType == "FWD") { if (boardArray[r+reflector][c]->getType() == '_') return true; else return false; } else if (moveType == "RIGHT") { if (boardArray[r+reflector][c+1]->getType() != pieceToMove && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 <= 7) ) return true; else return false; } else if (moveType == "LEFT") { if (boardArray[r+reflector][c-1]->getType() != pieceToMove && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 >= 0) ) return true; else return false; } else return false; } } vector Board::viewPossibleMoves() { vector output; for (int r = 0; r < 8; ++r) { for (int c = 0; c < 8; ++c) { if (boardArray[r][c]->getType() == turn) { if (isThisMovePossible(r,c,"FWD")) { moves temp(8-r,intToCharColumn(c+1),"FWD"); output.push_back(temp); } if (isThisMovePossible(r,c,"LEFT")) { moves temp(8-r,intToCharColumn(c+1),"LEFT"); output.push_back(temp); } if (isThisMovePossible(r,c,"RIGHT")) { moves temp(8-r,intToCharColumn(c+1),"RIGHT"); output.push_back(temp); } } } } return output; } */ string Board::myToUpper(string input) { string output; for (int i = 0 ; i < input.size(); ++i) { int numeric; if ((input[i] - 0 >= 97) && (input[i] - 0 <= 122)) { numeric = input[i] - 32; output.push_back((char)numeric);// = 'Q';//(char) numeric; } else output.push_back(input[i]); } return output; } void Board::undo(Board& tablero) { vector record; if (record.size() < 2) { cout<<"nothing to undo"< record; input = myToUpper(input); if (input == "UNDO") { undo(tablero); } else if (input == "DISPLAYRECORD") //for debugging purposes { cout<<"record: "<& inputVec, Board inputBoard) { if (inputVec.size() == 10) { inputVec.erase(inputVec.begin()); } else if (inputVec.size() > 10) { cout<<"QUEUE OVERFLOW!"<