From ad421650607942207396f6a6e99a2daeadbd1a48 Mon Sep 17 00:00:00 2001 From: jason riggs Date: Wed, 20 Mar 2019 18:33:28 +0000 Subject: [PATCH] change --- AIplayer.h | 2 -- Cell.cpp | 24 ++++-------------------- Cell.h | 1 - mainOthello.cpp | 10 +--------- 4 files changed, 5 insertions(+), 32 deletions(-) diff --git a/AIplayer.h b/AIplayer.h index e499fe1..3bf94aa 100644 --- a/AIplayer.h +++ b/AIplayer.h @@ -8,8 +8,6 @@ class displayBoard; class Cell; class AIplayer { public: - AIplayer() { srand(0); } // basic constructor to seed random number generator - AIplayer(int seed) { srand(seed); } // constructor to seed random number generator with desired seed pair move1(displayBoard AImove); // easy move pair move2(displayBoard AImove); // hard move mutator private: // not used diff --git a/Cell.cpp b/Cell.cpp index 294fd90..95b934c 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -6,7 +6,6 @@ using namespace std; bool Cell::isLegalPlacementfor(int x, int y, char board[][8], char playDisc, char oppDisc) { - cout << "Looking at " << x << " " << y << " to place " << (char)playDisc << endl; vector directions; Cell current(x - 1, y - 1); @@ -17,62 +16,53 @@ bool Cell::isLegalPlacementfor(int x, int y, char board[][8], char playDisc, cha Cell north(x - 1, y - 2); if (north.isOccupied(board, oppDisc)) { directions.push_back(north.NORTH); - cout << "N " << north.x << " " << north.y << endl; } Cell northEast(x, y - 2); if (northEast.isOccupied(board, oppDisc)) { directions.push_back(northEast.NORTHEAST); - cout << "NE " << northEast.x << " " << northEast.y << endl; } Cell east(x, y - 1); if (east.isOccupied(board, oppDisc)) { directions.push_back(EAST); - cout << "E " << east.x << " " << east.y << endl; } Cell southEast(x, y); if (southEast.isOccupied(board, oppDisc)) { directions.push_back(SOUTHEAST); - cout << "SE " << southEast.x << " " << southEast.y << endl; } Cell south(x - 1, y); if (south.isOccupied(board, oppDisc)) { directions.push_back(SOUTH); - cout << "S " << south.x << " " << south.y << endl; } Cell southWest(x - 2, y); if (southWest.isOccupied(board, oppDisc)) { directions.push_back(SOUTHWEST); - cout << "SW " << southWest.x << " " << southWest.y << endl; } Cell west(x - 2, y - 1); if (west.isOccupied(board, oppDisc)) { directions.push_back(WEST); - cout << "W " << west.x << " " << west.y << endl; } Cell northWest(x - 2, y - 2); if (northWest.isOccupied(board, oppDisc)) { directions.push_back(NORTHWEST); - cout << "NW " << northWest.x << " " << northWest.y << endl; } - for (int i = 0; i < directions.size(); i++) { - cout << directions.at(i) << endl; - } + // for (int i = 0; i < directions.size(); i++) { + // cout << directions.at(i) << endl; + // } for (auto direction : directions) { try{ int value = current.sequenceLength(direction, board, oppDisc, ""); - cout << "For Direction " << direction << " there was a value of " << value << endl; if (value > 0) { return true; } } catch(runtime_error &excpt) { - cout << excpt.what() << endl; + //cout << excpt.what() << endl; } } return false; @@ -80,7 +70,6 @@ bool Cell::isLegalPlacementfor(int x, int y, char board[][8], char playDisc, cha int Cell::sequenceLength(Directions direction, char board[][8], char playDisc, string indent) { int x1, y1; - cout << indent << "Entering sequenceLength with " << x + 1 << " " << y + 1 << " Looking for " << (char)playDisc <= 8 || y1 < 0 || y1 >= 8) { - cout << "Off the Board!" << endl; throw runtime_error("Invalid Sequence"); } Cell sequence(x1, y1); if (board[x1][y1] == ' ') { - cout << indent << "Found a space. Treat as invalid" << endl; throw runtime_error("Invalid Input"); } if (board[x1][y1] != playDisc) { - cout << indent << "Found \'" << (char)board[x1][y1] << "\' Returning 0" << endl; return 0; } int result = (1 + sequence.sequenceLength(direction, board, playDisc, " " + indent)); - cout << indent << "Found \'" << (char)board[x1][y1] << "\' Returning " << result << endl; return result; } diff --git a/Cell.h b/Cell.h index efba2ae..8889e75 100644 --- a/Cell.h +++ b/Cell.h @@ -14,7 +14,6 @@ class Cell { bool isOccupied(char board[][8], char disc); int x, y; - private: }; #endif diff --git a/mainOthello.cpp b/mainOthello.cpp index 36fcec4..0a71c26 100644 --- a/mainOthello.cpp +++ b/mainOthello.cpp @@ -15,14 +15,8 @@ int main() { pair AImove; bool winner = false; - // Seeding random number genrator - cout << "Please enter a random seed: "; - cin >> seed; - srand(seed); - cout << endl; - // Creates AI - AIplayer AIturn(seed); + AIplayer AIturn; // Header cout << "Welcome to Othello!" << endl; @@ -97,7 +91,6 @@ int main() { // Player two's Move } else if (turn == 2) { AImove = AIturn.move1(board); - cout << AImove.first << " " << AImove.second << endl; aiX = AImove.first; aiY = AImove.second; //Check fo valid move @@ -165,7 +158,6 @@ int main() { // Player two's Move } else if (turn == 2) { AImove = AIturn.move2(board); - cout << AImove.first << " " << AImove.second << endl; aiX = AImove.first; aiY = AImove.second; // Check fo valid move -- GitLab