#pragma once #include #include #include "Cube.h" #include "Color.h" template class Board{ public: Board(); ~Board() = default; constexpr uint32_t GetXSize() const{return X_SIZE;} constexpr uint32_t GetYSize() const{return Y_SIZE;} constexpr uint32_t GetZSize() const {return Z_SIZE;} constexpr uint32_t GetNumberCubes() const{return X_SIZE * Y_SIZE * Z_SIZE;} /** * @brief Returns a string in the format: * !a,b,c,d,e,f,g,h,i; * Where each letter is the number of cubes in a given position's stack * @param stringBuffer the buffer to write the string into */ void ToStackString(String& stringBuffer) const; /** * @brief Returns a bool array representing the board */ std::array &LinearizeBoard() const; void Update(); void FillColor(const Color &color); void SetCubeColor(uint32_t x_coord, uint32_t y_cord, uint32_t z_cord, const Color &color); private: // this is a 3d array of cubes to represent the board. Good luck visualizing it /* _____________ / /| / / | / / | /____________/ | | | | | | / | | / |____________|/ */ std::array, Y_SIZE>, X_SIZE> cubes; bool boardStateHasChanged; }; template Board::Board(){ this->FillColor(Color(0,0,0)); } template void Board::ToStackString(String &stringBuffer) const{ std::array linearizedBoard = this->LinearizeBoard(); stringBuffer += "!" + String(linearizedBoard[0]); for(uint32_t i = 0; i < X_SIZE * Y_SIZE; i++){ stringBuffer += "," + String(linearizedBoard[i]); } stringBuffer += ";"; } template std::array & Board::LinearizeBoard() const{ // convert the board into one array where each entry represents the height of one stack std::array linearizedBoard; for(uint32_t x{0}; x < X_SIZE; x++){ for(uint32_t y{0}; y < Y_SIZE; y++){ for(uint32_t z{0}; z < Z_SIZE; z++){ bool isOccupied{this->cubes[x][y][z].isOccupied}; linearizedBoard[x + y*3] += static_cast(isOccupied); } } } return linearizedBoard; } template void Board::Update(){ } template void Board::FillColor(const Color &color){ for(uint32_t x{0}; x < X_SIZE; x++){ for(uint32_t y{0}; y < Y_SIZE; y++){ for(uint32_t z{0}; z < Z_SIZE; z++){ this->cubes[x][y][z].SetColor(color); } } } } template void Board::SetCubeColor(uint32_t x_coord, uint32_t y_cord, uint32_t z_cord, const Color &color){ this->cubes[x][y][z].SetColor(color); }