From 5a6eb68feaf9c8c27b98bf10487de0eb838ca242 Mon Sep 17 00:00:00 2001 From: William Bracho Blok Date: Mon, 19 Oct 2015 16:00:19 -0500 Subject: [PATCH] Update main.cpp --- main.cpp | 913 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 782 insertions(+), 131 deletions(-) diff --git a/main.cpp b/main.cpp index 4cac03e..dc9920e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,52 +1,89 @@ #include #include #include +#include + using namespace std; -class piece +// 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; + // } +// }; + +string myToUpper(string input) { - char color; //w for white, b for white, e for empty - int xpos; - int ypos; + string output; - public: - - piece(int x, int y) + for (int i = 0 ; i < input.size(); ++i) { - xpos = x; - ypos = y; + 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]); } - void setColor(char kolor) + for (int i = 0; i < output.size(); ++i) { - color = kolor; + cout< 8 || x < 0 || y > 8 || y < 0) + input = myToUpper(input); + + cout< viewPossibleMoves() + char getTurn() { - cout<<"not yet!"< 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; } } -}; + + + bool isThisAPriorityMove(moves inputMove) //assumes given move is valid! + { + char pieceToMove = boardArray[inputMove.row][inputMove.column]; + cout<<"pieceToMove: "< 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); + } + + } + } + } + + // cout<<"\nnumber of possible choices: "< viewPrioritizedMoves() + { + 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 easyAI() + { + + //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: "< record; + +void undo(Board& tablero) +{ + if (record.size() < 2) + { + cout<<"nothing to undo"< input) +{ + cout<<"\n\nList of possible Moves:"<& inputVec, Board inputBoard) +{ + if (inputVec.size() == 10) + { + inputVec.erase(inputVec.begin()); + } + + else if (inputVec.size() > 10) + { + cout<<"QUEUE OVERFLOW!"<>choice; + + if (choice == 1) cout<<"playing with AI..."<>x; + gameOver = b.isGameOver(); - cout<<"y: "; - cin>>y; + while(b.getTurn() == 'O' ) + { + b.displayBoard(); + cout<<"\nEnter command: "; + cin>>move; + interpret(move,b); + } - cout<<"moveType: "; - cin>>move; - b.move(x,y,move); + vector possibleMoves = b.viewPossibleMoves(); + //displayPossibleMoves(possibleMoves); for debugging purposes - AI + + if (choice == 1) + { + b.easyAI(); + } + + else + { + while(b.getTurn() == 'X' ) + { + b.displayBoard(); + cout<<"\nEnter command: "; + cin>>move; + interpret(move,b); + } + } + + //b.snapshot(); + gameOver = b.isGameOver(); + + snapshot(record,b); } + //for debugging purposes + cout<<"Record:"<