diff --git a/src/Core/Game.cpp b/src/Core/Game.cpp index c0cabca..a2e5e2a 100644 --- a/src/Core/Game.cpp +++ b/src/Core/Game.cpp @@ -36,7 +36,6 @@ Game::Game(Gamemode gamemode, const Player& controls, int boardWidth, int boardH } void Game::start() { - // starts the game this->started = true; this->lost = this->board.spawnNextPiece(); } diff --git a/src/Core/main.cpp b/src/Core/main.cpp index 3e861d0..655b85d 100644 --- a/src/Core/main.cpp +++ b/src/Core/main.cpp @@ -20,23 +20,6 @@ void readStatsFromFilesForAllSizes(int amount); int main(int argc, char** argv) { std::srand(std::time(NULL)); - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - - PiecesFiles pf; - std::vector pieces; - std::vector convexPieces; - std::vector holelessPieces; - std::vector otherPieces; - pf.loadPieces(13, pieces, convexPieces, holelessPieces, otherPieces); - - auto t1 = high_resolution_clock::now(); - Bag bg(pieces); - auto t2 = high_resolution_clock::now(); - duration ms_double = t2 - t1; - std::cout << ms_double.count() << "ms" << std::endl; return 0; } diff --git a/src/Pieces/Cell.h b/src/Pieces/Cell.h index 3d0f3c8..5b9afb5 100644 --- a/src/Pieces/Cell.h +++ b/src/Pieces/Cell.h @@ -15,14 +15,14 @@ struct Cell { /** * Addition operator, returns the sums of the coordinates of both cells */ -Cell operator+(const Cell& left, const Cell& right) { +inline Cell operator+(const Cell& left, const Cell& right) { return Cell{left.x + right.x, left.y + right.y}; } /** * Additive assignation operator, adds the coordinates of the right cell to the left one */ -Cell& operator+=(Cell& left, const Cell& right) { +inline Cell& operator+=(Cell& left, const Cell& right) { left = left + right; return left; } @@ -30,7 +30,7 @@ Cell& operator+=(Cell& left, const Cell& right) { /** * Substraction operator, returns the difference of the coordinate between the left and right cell */ -Cell operator-(const Cell& left, const Cell& right) { +inline Cell operator-(const Cell& left, const Cell& right) { return Cell{left.x - right.x, left.y - right.y}; } @@ -38,7 +38,7 @@ Cell operator-(const Cell& left, const Cell& right) { /** * Substractive assignation operator, substract the coordinates of the right cell from the left one */ -Cell& operator-=(Cell& left, const Cell& right) { +inline Cell& operator-=(Cell& left, const Cell& right) { left = left - right; return left; } @@ -46,21 +46,21 @@ Cell& operator-=(Cell& left, const Cell& right) { /** * Strict inferiority operator, a cell is inferior to another if it is lower or at the same height and more to the left */ -bool operator<(const Cell& left, const Cell& right) { +inline bool operator<(const Cell& left, const Cell& right) { return (left.x == right.x) ? (left.y < right.y) : (left.x < right.x); } /** * Equality operator, two cells are equal if they have the same coordinates */ -bool operator==(const Cell& left, const Cell& right) { +inline bool operator==(const Cell& left, const Cell& right) { return (left.x == right.x) && (left.y == right.y); } /** * Stream output operator, adds the coordinates of the cell to the stream */ -std::ostream& operator<<(std::ostream& os, const Cell& cell) { +inline std::ostream& operator<<(std::ostream& os, const Cell& cell) { os << "x: " << cell.x << " y: " << cell.y; return os; } diff --git a/src/Pieces/Color.h b/src/Pieces/Color.h index 9c6404b..ce8a9d6 100644 --- a/src/Pieces/Color.h +++ b/src/Pieces/Color.h @@ -21,8 +21,19 @@ enum Color { }; -static const Color FIRST_PIECE_COLOR = PURPLE; // the first color a piece can be -static const Color LAST_PIECE_COLOR = GREEN; // the last color a piece can be +/** + * Returns the first color a piece can take + */ +inline Color firstPieceColor() { + return Color(PURPLE); +} + +/** + * Sets the color to the next available piece color + */ +inline void nextPieceColor(Color& color) { + color = (color == GREEN) ? PURPLE : Color(color + 1); +} static const std::string COLOR_RESET = "\033[38;2;255;255;255m"; // color code to reset the console color static const std::string COLOR_CODES[] = { // color codes to change the console color diff --git a/src/Pieces/PiecesFiles.cpp b/src/Pieces/PiecesFiles.cpp index 4ffca59..6f5e7ac 100644 --- a/src/Pieces/PiecesFiles.cpp +++ b/src/Pieces/PiecesFiles.cpp @@ -38,7 +38,8 @@ bool PiecesFiles::savePieces(int order) const { std::sort(nMinos.begin(), nMinos.end()); // write pieces - Color pieceColor = Color(FIRST_PIECE_COLOR + (order % (LAST_PIECE_COLOR - FIRST_PIECE_COLOR + 1))); + Color pieceColor = firstPieceColor(); + for (int i = 0; i < order; i++) nextPieceColor(pieceColor); for (const Polyomino& nMino : nMinos) { // write polyomino length char lengthByte = nMino.getLength(); @@ -46,7 +47,7 @@ bool PiecesFiles::savePieces(int order) const { // write the type and color of the piece char infoByte = (nMino.isConvex() << 7) + (nMino.hasHole() << 6) + pieceColor; - pieceColor = (pieceColor == LAST_PIECE_COLOR) ? FIRST_PIECE_COLOR : Color(pieceColor + 1); + nextPieceColor(pieceColor); piecesFile.write(&infoByte, 1); // write the cells of the piece diff --git a/src/Pieces/Rotation.h b/src/Pieces/Rotation.h index a638900..7bd61f5 100644 --- a/src/Pieces/Rotation.h +++ b/src/Pieces/Rotation.h @@ -15,14 +15,14 @@ enum Rotation { /** * Addition operator, returns a rotation corresponding to doing both rotations */ -Rotation operator+(const Rotation& left, const Rotation& right) { +inline Rotation operator+(const Rotation& left, const Rotation& right) { return Rotation((left + right) % 4); } /** * Additive assignation operator, rotate the left rotation by the right rotation */ -Rotation& operator+=(Rotation& left, const Rotation& right) { +inline Rotation& operator+=(Rotation& left, const Rotation& right) { left = left + right; return left; } diff --git a/xmake.lua b/xmake.lua index 659104e..d858933 100644 --- a/xmake.lua +++ b/xmake.lua @@ -5,6 +5,7 @@ target("main") set_rundir(".") add_files("./src/Pieces/*.cpp") add_files("./src/Core/*.cpp") + set_optimize("fastest") --