From d2f5cd2e23000bcf4eab3ee3f9cf8dfc46ddbf8b Mon Sep 17 00:00:00 2001 From: stianse Date: Mon, 15 Oct 2007 19:57:25 +0000 Subject: [PATCH] Changed the name of some member variables to conform to the convention with postfix underscore ("varName_"). --- src/Board.cpp | 96 +++++++++++++++++++------------------------------ src/Board.h | 25 ++++++------- src/Game.h | 1 - src/Session.cpp | 2 +- src/Session.h | 2 +- 5 files changed, 49 insertions(+), 77 deletions(-) diff --git a/src/Board.cpp b/src/Board.cpp index b67be37..27511f9 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -1,5 +1,5 @@ /** - * A class for a Mancala board. The following board layout is assumed + * A class for a Mancala board_. The following board_ layout is assumed * * Holes num: * @@ -39,7 +39,7 @@ using namespace std; /** Constructor. * * @param holes is the number of holes, including both house and store, in - * the board. Must be an even number. + * the board_. Must be an even number. * @param seeds is the initial number of seeds per hole. * * @exception std::invalid_argument. @@ -56,29 +56,29 @@ Board::Board(int houses, int seeds) { ostringstream msg; msg << "'holes' = " << holes << ": " - << "The number of holes in a board must be equal"; + << "The number of holes in a board_ must be equal"; throw invalid_argument(msg.str()); } - store2 = 0; - store1 = holes / 2; + store2_ = 0; + store1_ = holes / 2; - board.reserve(holes); + board_.reserve(holes); for (int i = 0; i < holes; ++i) { - if (i == store1 || i == store2) - board.push_back(0); + if (i == store1_ || i == store2_) + board_.push_back(0); else - board.push_back(seeds); + board_.push_back(seeds); } } int & Board::operator[] (int hole) { - if (hole < 0 || hole > static_cast(board.size()-1)) + if (hole < 0 || hole > static_cast(board_.size()-1)) throw invalid_argument("argument out of range"); - return board[hole]; + return board_[hole]; } @@ -107,20 +107,20 @@ bool Board::sow(int house, Half playersHalf, int * endId, Board::HoleType * endT if (seeds == 0) return false; - board[hole] = 0; + board_[hole] = 0; int opponentStore = getStoreHole((playersHalf == SOUTH) ? NORTH : SOUTH); while (seeds) { - hole = ( hole == static_cast( board.size())-1 ) ? 0 : hole + 1; + hole = ( hole == static_cast( board_.size())-1 ) ? 0 : hole + 1; if (hole != opponentStore) { - ++board[hole]; + ++board_[hole]; --seeds; } } - *endType = (hole == store1 || hole == store2) ? STORE : HOUSE; + *endType = (hole == store1_ || hole == store2_) ? STORE : HOUSE; *endId = *endType == STORE ? hole2store(hole) : hole2house(hole); return true; @@ -131,17 +131,17 @@ bool Board::sow(int house, Half playersHalf, int * endId, Board::HoleType * endT bool Board::isHalfEmpty(Half half) const { int isEmpty = true; - int hole = half == SOUTH ? store2 + 1 : store1 + 1; - int end = half == SOUTH ? store1 : store2; + int hole = half == SOUTH ? store2_ + 1 : store1_ + 1; + int end = half == SOUTH ? store1_ : store2_; while (hole != end) { - if (board[hole] != 0) + if (board_[hole] != 0) { isEmpty = false; break; } - hole = ( hole == static_cast( board.size())-1 ) ? 0 : hole + 1; + hole = ( hole == static_cast( board_.size())-1 ) ? 0 : hole + 1; } return isEmpty; @@ -151,19 +151,19 @@ bool Board::isHalfEmpty(Half half) const int Board::getSeedsInHouse(int house) const { - return board[house2hole(house)]; + return board_[house2hole(house)]; } int Board::getSeedsInStore(int store) const { - return board[store2hole(store)]; + return board_[store2hole(store)]; } Board::Half Board::getHalf (int hole) const { - if (hole <= store1 && hole != store2) + if (hole <= store1_ && hole != store2_) return SOUTH; else return NORTH; @@ -177,11 +177,11 @@ int Board::getOppositeHole( int hole ) const checkRange (hole); if ( hole == 0 ) - opposite = board.size() / 2; - else if ( hole == static_cast(board.size()) / 2 ) + opposite = board_.size() / 2; + else if ( hole == static_cast(board_.size()) / 2 ) opposite = 0; else - opposite = board.size() - hole; + opposite = board_.size() - hole; return opposite; } @@ -190,7 +190,7 @@ int Board::getOppositeHole( int hole ) const int Board::hole2house(int hole) const { checkRange (hole); - return hole < store1 ? hole : hole - 1; + return hole < store1_ ? hole : hole - 1; } /** @@ -200,9 +200,9 @@ int Board::hole2house(int hole) const int Board::hole2store(int hole) const { checkRange (hole); - if ( hole == store1 ) + if ( hole == store1_ ) return 1; - else if ( hole == store2) + else if ( hole == store2_) return 2; else return 0; @@ -210,16 +210,16 @@ int Board::hole2store(int hole) const int Board::house2hole(int house) const { - if (house < 1 || house > static_cast(board.size()-2)) + if (house < 1 || house > static_cast(board_.size()-2)) throw invalid_argument("Invalid house number"); - return house < store1 ? house : house + 1; + return house < store1_ ? house : house + 1; } int Board::store2hole(int store) const { if (store < 1 || store > 2) throw invalid_argument("Invalid store number"); - return store == 1 ? store1 : store2; + return store == 1 ? store1_ : store2_; } @@ -230,9 +230,9 @@ int Board::getHole(int num, HoleType type) const int hole; if (type == HOUSE) { - if (num < 1 || num > board.size() - 2) + if (num < 1 || num > board_.size() - 2) throw invalid_argument("Invalid house number"); - hole = (num < store1) ? num : num + 1; + hole = (num < store1_) ? num : num + 1; } else if (type == STORE) { @@ -248,9 +248,9 @@ int Board::getStoreHole(Half half) const { int hole; if (half == SOUTH) - hole = store1; + hole = store1_; else if (half == NORTH) - hole = store2; + hole = store2_; else throw invalid_argument("Only store for half SOUTH and NORTH"); return hole; @@ -258,36 +258,14 @@ int Board::getStoreHole(Half half) const size_t Board::size () const { - return board.size(); + return board_.size(); } -void Board::print(std::ostream & out) const -{ - int i; - std::ostringstream s1, s2, s3; - - for ( i = 1; i < static_cast(board.size())/2; ++i ) - { - s1 << getSeedsInHouse( board.size()-1 - i ) << "\t"; - s2 << "\t"; - s3 << getSeedsInHouse( i ) << "\t"; - } - - out << "\t" << s1.str() << "\n"; - out << getSeedsInStore( 2 ) << s2.str() << "\t "<< getSeedsInStore( 1 ) << "\n"; - out << "\t" << s3.str() << std::endl; -} - bool Board::checkRange( int hole ) const { - if ( hole < 0 || hole > static_cast(board.size()-1) ) + if ( hole < 0 || hole > static_cast(board_.size()-1) ) throw invalid_argument("Invalid hole number"); return true; } -// Board::~Board() -// { -// delete[] board; -// } - diff --git a/src/Board.h b/src/Board.h index b521598..fa1f37d 100644 --- a/src/Board.h +++ b/src/Board.h @@ -12,37 +12,32 @@ public: Board(); Board(int houses, int seeds); -// ~Board(); int & operator[] (int hole); - -// bool sow(int house, Half playersHalf, int * endId, HoleType * endType); + + size_t size() const; + int getSeedsInHouse(int house) const; int getSeedsInStore(int store) const; - int getOppositeHole(int hole) const; - void print ( std::ostream & out) const; - bool isHalfEmpty(Half half) const; + int getStoreHole(Half Half) const; + int getOppositeHole(int hole) const; int store2hole(int store) const; int hole2store(int hole) const; int hole2house(int hole) const; - - int getStoreHole(Half Half) const; int house2hole(int house) const; + Half getHalf(int hole) const; - - size_t size() const; + bool isHalfEmpty(Half half) const; private: - int store1; - int store2; - std::vector board; + int store1_; + int store2_; + std::vector board_; bool checkRange (int hole) const; }; - - #endif diff --git a/src/Game.h b/src/Game.h index feb2465..5e21fb8 100644 --- a/src/Game.h +++ b/src/Game.h @@ -23,7 +23,6 @@ public: virtual std::string getActivePlayerName() const; virtual std::string getPlayer1Name () const; virtual std::string getPlayer2Name () const; -// Board & getBoard() const; virtual bool makeMove( int house ); virtual int getSeedsInHouse( int house ) const; diff --git a/src/Session.cpp b/src/Session.cpp index 93d460b..977fb79 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -16,7 +16,7 @@ void Session::newGame () { // todo: do this completely different // delete game_; - Game * g = new Game( factory.createKalah(), 12); + Game * g = new Game( factory_.createKalah(), 12); g->player1("P1", true); g->player2("P2", true); game_ = g; diff --git a/src/Session.h b/src/Session.h index 8d0a9a1..c505b4a 100644 --- a/src/Session.h +++ b/src/Session.h @@ -16,7 +16,7 @@ public: private: IGame * game_; GuiWrapper * gui_; - EngineFactory factory; + EngineFactory factory_; }; #endif