#include #include #include #include using namespace std; // class piece // { // char color; //w for white, b for white, e for empty // int xpos; // int ypos; // public: // piece(int x, int y) // { // xpos = x; // ypos = y; // } // void setColor(char kolor) // { // color = kolor; // } // char getColor() // { // return color; // } // }; struct moves { int row; char column; string moveType; moves(int linea, int columna, string m) { row = linea; column = columna; moveType = m; } }; class Board { char boardArray [8][8]; char turn = 'O'; //bool winOrLose; public: Board() { for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { boardArray[i][j] = 'X'; } } for (int i = 2; i < 6; ++i) { for (int j = 0; j < 8; ++j) { boardArray[i][j] = '_'; } } for (int i = 6; i <= 7; ++i) { for (int j = 0; j < 8; ++j) { boardArray[i][j] = 'O'; } } // winOrLose = false; } moves parse(string input) //needs to be idiot proof { 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; } char getTurn() { return turn; } bool isGameOver() { for (int i = 0; i < 8; ++i) { if (boardArray[0][i] == 'O') { cout<<"\n\n\nplayer O wins!\n\n\n"< 8 || row < 0 || kolumn > 8 || kolumn < 0) { cout<<"ERROR: index out of bound!"< 8 || row < 0 || kolumn > 8 || kolumn < 0) { cout<<"ERROR: index out of bound!"<= 0) && (r+reflector <= 7) && (c+1 <= 7) ) return true; else return false; } else if (moveType == "LEFT") { if (boardArray[r+reflector][c-1] != pieceToMove && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 >= 0) ) return true; else return false; } else return false; } } vector viewPossibleMoves() { vector output; for (int r = 0; r < 8; ++r) { for (int c = 0; c < 8; ++c) { if (boardArray[r][c] == 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; } void dumbassAI() { //1) see all possible movements vector listOfMoves = viewPossibleMoves(); //2) pick a movement srand(time(NULL)); int randomChoice = rand() % (listOfMoves.size()-1) - 0; // choose a move betwen listOfMoves[0] to last element //3) execute movement int temp = randomChoice; move(listOfMoves[randomChoice]); cout<<"\n\nMove executed by AI: "< input) { cout<<"\n\nList of possible Moves:"<>move; b.move(move); } vector possibleMoves = b.viewPossibleMoves(); //displayPossibleMoves(possibleMoves); b.dumbassAI(); gameOver = b.isGameOver(); } }