From 7859237ced86c0bd0d08711879692310891dcf97 Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Mon, 19 Oct 2015 15:45:41 -0500 Subject: [PATCH] finished restructuring --- Board.cpp | 837 +++++++++++++++++++++++++++--------------------------- Board.h | 395 ++------------------------ 2 files changed, 439 insertions(+), 793 deletions(-) diff --git a/Board.cpp b/Board.cpp index 78b82b3..2ad164b 100755 --- a/Board.cpp +++ b/Board.cpp @@ -1,500 +1,499 @@ -class Board +#include "Board.h" + +Board::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'; + } + } +} + +moves Board::parse(string input) { - char boardArray [8][8]; - char turn = 'O'; - public: + input = myToUpper(input); - Board() + cout< 8 || row < 0 || kolumn > 8 || kolumn < 0) { - if (turn == 'O') turn = 'X'; - else turn = 'O'; + cout<<"ERROR: index out of bound!"< 8 || row < 0 || kolumn > 8 || kolumn < 0) + + if (temp == 'O') { - cout<<"ERROR: index out of bound!"< 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 if (moveType == "RIGHT") + { + if (boardArray[r+reflector][c+1] != pieceToMove && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 <= 7) ) return true; else return false; } - } - - - - - vector viewPossibleMoves() - { - vector output; - for (int r = 0; r < 8; ++r) + else if (moveType == "LEFT") { - 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); - } - - } - } + if (boardArray[r+reflector][c-1] != pieceToMove && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 >= 0) ) return true; + else return false; } - return output; + else return false; } +} + + + + +vector Board::viewPossibleMoves() +{ + vector output; - - void easyAI() + for (int r = 0; r < 8; ++r) { - - //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: "<= 97) && (input[i] - 0 <= 122)) + { + numeric = input[i] - 32; + output.push_back((char)numeric);// = 'Q';//(char) numeric; + } + else output.push_back(input[i]); + } + + for (int i = 0; i < output.size(); ++i) + { + cout< input) +{ + cout<<"\n\nList of possible Moves:"< 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: "< 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 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: "< viewPossibleMoves(); + string myToUpper(string input); + void displayPossibleMoves(vector input); + void easyAI(); }; \ No newline at end of file