From 8736aee27c06abf7f25f56ccedd5e5dca8df9682 Mon Sep 17 00:00:00 2001 From: emclrk Date: Sat, 12 Aug 2023 17:00:24 -0700 Subject: [PATCH] lint/style changes --- include/GameBoard.h | 4 +- include/Player.h | 12 +++-- include/tile_utils.h | 36 +++++++-------- src/GameBoard.cc | 8 ++-- src/Player.cc | 106 +++++++++++++++++++++---------------------- 5 files changed, 87 insertions(+), 79 deletions(-) diff --git a/include/GameBoard.h b/include/GameBoard.h index 4ed03dc..41b6114 100644 --- a/include/GameBoard.h +++ b/include/GameBoard.h @@ -22,7 +22,9 @@ public: bool takeTilesFromPool(azool::TileColor color, int& numTiles, bool& poolPenalty); void returnTilesToBag(int numTiles, azool::TileColor color); void dealTiles(); - int numFactories() { return tileFactories.size(); } + int numFactories() { + return tileFactories.size(); + } bool endOfRound() { // round ends when the pool and tile factories are empty for (int ii = 0; ii < azool::NUMCOLORS; ++ii) { diff --git a/include/Player.h b/include/Player.h index 645ef1b..78ba517 100644 --- a/include/Player.h +++ b/include/Player.h @@ -15,10 +15,16 @@ public: void placeTiles(int rowIdx, azool::TileColor color, int numTiles); void endRound(bool& fullRow); void finalizeScore(); - int getScore() const { return myScore; } + int getScore() const { + return myScore; + } std::string printMyBoard() const; - bool tookPenalty() const { return myTookPoolPenaltyThisRound; } - const std::string getPlayerName() const { return myName; } + bool tookPenalty() const { + return myTookPoolPenaltyThisRound; + } + const std::string getPlayerName() const { + return myName; + } private: Player(const Player&) = delete; diff --git a/include/tile_utils.h b/include/tile_utils.h index 75808b5..58a749d 100644 --- a/include/tile_utils.h +++ b/include/tile_utils.h @@ -1,23 +1,23 @@ #ifndef TILE_UTILS_H_ #define TILE_UTILS_H_ namespace azool { - enum TileColor { - NONE = -1, - RED = 0, - BLUE, - GREEN, - YELLOW, - BLACK, - NUMCOLORS - }; - const std::string TileColorStrings[NUMCOLORS] = { - "red", - "blue", - "green", - "yellow", - "black" - }; - - const char TileColorSyms[NUMCOLORS] = { 'r', 'b', 'g', 'y', 'k' }; +enum TileColor { + NONE = -1, + RED = 0, + BLUE, + GREEN, + YELLOW, + BLACK, + NUMCOLORS +}; +const std::string TileColorStrings[NUMCOLORS] = { + "red", + "blue", + "green", + "yellow", + "black" +}; + +const char TileColorSyms[NUMCOLORS] = { 'r', 'b', 'g', 'y', 'k' }; } #endif // TILE_UTILS_H_ diff --git a/src/GameBoard.cc b/src/GameBoard.cc index 55ebc07..ad4dab0 100644 --- a/src/GameBoard.cc +++ b/src/GameBoard.cc @@ -10,9 +10,9 @@ GameBoard::GameBoard(int numPlayers) : tileBag(), lastRound(false), rng(std::default_random_engine( - std::chrono::system_clock::now().time_since_epoch().count())) { - resetBoard(); - } // GameBoard::GameBoard + std::chrono::system_clock::now().time_since_epoch().count())) { + resetBoard(); +} // GameBoard::GameBoard std::ostream& operator<<(std::ostream& out, const GameBoard& board) { // user will input 1-indexed value, even though we 0-index internally @@ -100,7 +100,7 @@ void GameBoard::dealTiles() { } tileFactories.push_back(fact); } -} // GameBoard::dealTiles +} // GameBoard::dealTiles void GameBoard::resetBoard() { memset(pool, 0, azool::NUMCOLORS*sizeof(int)); diff --git a/src/Player.cc b/src/Player.cc index 985a084..93ee31a 100644 --- a/src/Player.cc +++ b/src/Player.cc @@ -11,13 +11,13 @@ Player::Player(GameBoard* const board, std::string name) : myScore(0), myNumPenaltiesForRound(0), myTookPoolPenaltyThisRound(false) { - int gridSize = azool::NUMCOLORS * azool::NUMCOLORS; - memset(myGrid, 0, gridSize*sizeof(bool)); - for (int ii = 0; ii < azool::NUMCOLORS; ++ii) { - myRows[ii].first = 0; - myRows[ii].second = azool::NONE; - } // initialize rows - } // Player::Player + int gridSize = azool::NUMCOLORS * azool::NUMCOLORS; + memset(myGrid, 0, gridSize*sizeof(bool)); + for (int ii = 0; ii < azool::NUMCOLORS; ++ii) { + myRows[ii].first = 0; + myRows[ii].second = azool::NONE; + } // initialize rows +} // Player::Player bool Player::checkValidMove(azool::TileColor color, int rowIdx) const { // check if valid move @@ -250,7 +250,7 @@ std::string Player::printMyBoard() const { oss << "_"; } else if (jj < myRows[ii].first) { - oss << azool::TileColorSyms[myRows[ii].second]; + oss << azool::TileColorSyms[myRows[ii].second]; } } // print grid row @@ -296,54 +296,54 @@ bool Player::discardFromPool(azool::TileColor color) { } // Player::discardFromPool namespace { - int promptForFactoryIdx(int maxNumFactories) { - static const char* promptFactoryIdxDraw = "Which factory? enter index\n"; - char factInput; // TODO can we safely say there will never be more than 9 possible? - std::cout << promptFactoryIdxDraw << std::flush; - std::cin >> factInput; - int factIdx = std::atoi(&factInput); - if (factIdx < 1 or factIdx > maxNumFactories) { - return -1; - } - return factIdx; +int promptForFactoryIdx(int maxNumFactories) { + static const char* promptFactoryIdxDraw = "Which factory? enter index\n"; + char factInput; // TODO can we safely say there will never be more than 9 possible? + std::cout << promptFactoryIdxDraw << std::flush; + std::cin >> factInput; + int factIdx = std::atoi(&factInput); + if (factIdx < 1 or factIdx > maxNumFactories) { + return -1; } - azool::TileColor promptForColor() { - static const char* promptColorDraw = "Which color? [r|b|g|y|k]\n"; - char colorInput = '\0'; - std::cout << promptColorDraw << std::flush; - std::cin >> colorInput; - switch(colorInput) { - case 'r': - return azool::RED; - break; - case 'b': - return azool::BLUE; - break; - case 'g': - return azool::GREEN; - break; - case 'y': - return azool::YELLOW; - break; - case 'k': - return azool::BLACK; - break; - default: - return azool::NONE; - } // end switch + return factIdx; +} +azool::TileColor promptForColor() { + static const char* promptColorDraw = "Which color? [r|b|g|y|k]\n"; + char colorInput = '\0'; + std::cout << promptColorDraw << std::flush; + std::cin >> colorInput; + switch(colorInput) { + case 'r': + return azool::RED; + break; + case 'b': + return azool::BLUE; + break; + case 'g': + return azool::GREEN; + break; + case 'y': + return azool::YELLOW; + break; + case 'k': + return azool::BLACK; + break; + default: return azool::NONE; + } // end switch + return azool::NONE; +} +int promptForRow() { + static const char* promptRowPlacement = "Place on which row? enter number [1-5]\n"; + char rowInput; + std::cout << promptRowPlacement << std::flush; + std::cin >> rowInput; + int rowIdx = std::atoi(&rowInput); + if (rowIdx < 1 or rowIdx > azool::NUMCOLORS) { + return -1; } - int promptForRow() { - static const char* promptRowPlacement = "Place on which row? enter number [1-5]\n"; - char rowInput; - std::cout << promptRowPlacement << std::flush; - std::cin >> rowInput; - int rowIdx = std::atoi(&rowInput); - if (rowIdx < 1 or rowIdx > azool::NUMCOLORS) { - return -1; - } - return rowIdx; - } + return rowIdx; +} } // anonymous namespace void Player::takeTurn() {