lint/style changes
This commit is contained in:
parent
4404eb21e9
commit
8736aee27c
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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_
|
||||
|
@ -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));
|
||||
|
106
src/Player.cc
106
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user