diff --git a/README.md b/README.md index 3caf7e9..0f8d7aa 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ If for some reasons you wanna run the command line version (not updated): ### One-sided n-polyominoes | n | Number | Generation | File storing | File retrieving | File size | -| - | - | - | - | - | - | +| -: | -: | :-: | :-: | :-: | -: | | 1 | 1 | 0s 0.005622ms | 0s 0.750955ms | 0s 0.014016ms | 2 bytes | | 2 | 1 | 0s 0.005758ms | 0s 0.181323ms | 0s 0.012256ms | 3 bytes | | 3 | 2 | 0s 0.017525ms | 0s 0.054497ms | 0s 0.006431ms | 8 bytes | @@ -109,12 +109,13 @@ If for some reasons you wanna run the command line version (not updated): | 14 | 1802312 | 45s 606.597ms | 32s 28.7977ms | 2s 919.653ms | 27034680 bytes | | 15 | ~6M | ~5mn | ~5mn | ~10s | ~100 MB | -_File storing includes normalizing and sorting all polyominoes before writing them to the file._ +_File storing includes type checking and sorting all polyominoes before writing them to the file._ If you want to know more details about the generation and storage of polyominoes, [check the documentation](/doc/)! Run it yourself by typing: -``xmake build benchmark`` -``xmake run benchmark`` +``xmake f -m release`` +``xmake build bmark`` +``xmake run bmark`` ## Credits diff --git a/src/GraphicalUI/main.cpp b/src/GraphicalUI/main.cpp index 1aeaba7..d2c7977 100644 --- a/src/GraphicalUI/main.cpp +++ b/src/GraphicalUI/main.cpp @@ -15,7 +15,7 @@ int main() { PiecesFiles pf; for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) { - #ifdef NDEBUG + #ifndef DEBUG std::cout << "IMPORTANT: You are currently in release mode, if you do not wish to generate big pieces (can take several minutes), type 'xmake f -m debug'." << std::endl; #endif @@ -23,7 +23,7 @@ int main() { pf.savePieces(i); } } - #ifndef NDEBUG + #ifdef DEBUG std::cout << "IMPORTANT: You are currently in debug mode, if you wish to use bigger pieces, type 'xmake f -m release'." << std::endl; bool everythingGenerated = true; diff --git a/src/Pieces/Generator.cpp b/src/Pieces/Generator.cpp index 40255a6..34d4af0 100644 --- a/src/Pieces/Generator.cpp +++ b/src/Pieces/Generator.cpp @@ -50,7 +50,7 @@ void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nex } // generate the list of candidate positions - for (Position position : this->currentTestedShape) { + for (const Position position : this->currentTestedShape) { this->tryToAddCandidatePosition(Position{position.x, position.y + 1}, nextAvaibleNumber, candidatePositions); this->tryToAddCandidatePosition(Position{position.x + 1, position.y}, nextAvaibleNumber, candidatePositions); this->tryToAddCandidatePosition(Position{position.x, position.y - 1}, nextAvaibleNumber, candidatePositions); @@ -58,7 +58,7 @@ void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nex } // try adding a square only to positions with a higher number than the last one - for (auto [key, val] : candidatePositions) { + for (const auto [key, val] : candidatePositions) { if (val > lastAddedPositionNumber) { this->currentTestedShape.insert(key); this->generate(polyominoSize, val, nextAvaibleNumber, (polyominoSize == this->currentTestedShape.size()) ? std::map() : candidatePositions); diff --git a/src/Pieces/PiecesFiles.cpp b/src/Pieces/PiecesFiles.cpp index e75b0af..7034928 100644 --- a/src/Pieces/PiecesFiles.cpp +++ b/src/Pieces/PiecesFiles.cpp @@ -48,7 +48,9 @@ bool PiecesFiles::savePieces(int polyominoSize, std::vector& polyomin for (const Polyomino& polyomino : polyominoes) { // write the characteristics of the piece - char infoByte = (polyomino.isConvex() << 7) + (polyomino.hasHole() << 6) + polyomino.getLength(); + bool isConvex = polyomino.isConvex(); + bool hasHole = (isConvex) ? false : polyomino.hasHole(); + char infoByte = (isConvex << 7) + (hasHole << 6) + polyomino.getLength(); piecesFile.write(&infoByte, 1); // write the positions of the piece diff --git a/src/Pieces/Polyomino.cpp b/src/Pieces/Polyomino.cpp index 58ed2f8..a9fe094 100644 --- a/src/Pieces/Polyomino.cpp +++ b/src/Pieces/Polyomino.cpp @@ -15,7 +15,7 @@ Polyomino::Polyomino(const std::set& positions) { int maxX = INT_MIN; int minY = INT_MAX; int maxY = INT_MIN; - for (Position position : positions) { + for (const Position position : positions) { if (position.x < minX) minX = position.x; if (position.x > maxX) maxX = position.x; if (position.y < minY) minY = position.y; @@ -40,13 +40,13 @@ Polyomino::Polyomino(const std::set& positions, int length) : void Polyomino::normalize() { int minX = INT_MAX; int minY = INT_MAX; - for (Position position : this->positions) { + for (const Position position : this->positions) { if (position.x < minX) minX = position.x; if (position.y < minY) minY = position.y; } std::set newPositions; - for (Position position : this->positions) { + for (const Position position : this->positions) { newPositions.insert(Position{position.x - minX, position.y - minY}); } this->positions = std::move(newPositions); @@ -54,7 +54,7 @@ void Polyomino::normalize() { void Polyomino::rotateCW() { std::set newPositions; - for (Position position : this->positions) { + for (const Position position : this->positions) { newPositions.insert(Position{position.y, (length - 1) - (position.x)}); } this->positions = std::move(newPositions); @@ -62,7 +62,7 @@ void Polyomino::rotateCW() { void Polyomino::rotate180() { std::set newPositions; - for (Position position : this->positions) { + for (const Position position : this->positions) { newPositions.insert(Position{(length - 1) - (position.x), (length - 1) - (position.y)}); } this->positions = std::move(newPositions); @@ -70,7 +70,7 @@ void Polyomino::rotate180() { void Polyomino::rotateCCW() { std::set newPositions; - for (Position position : this->positions) { + for (const Position position : this->positions) { newPositions.insert(Position{(length - 1) - (position.y), position.x}); } this->positions = std::move(newPositions); @@ -89,7 +89,7 @@ void Polyomino::goToSpawnPosition() { } // calculates amount of squares per rows and columns - for (Position position : this->positions) { + for (const Position position : this->positions) { linesCompleteness.at(0).at(position.y) += 1; // 0 = bottom to top = no rotation linesCompleteness.at(1).at((length - 1) - position.x) += 1; // 1 = right to left = CW linesCompleteness.at(2).at((length - 1) - position.y) += 1; // 2 = top to bottom = 180 @@ -158,14 +158,14 @@ void Polyomino::goToSpawnPosition() { int minX = INT_MAX; int minY = INT_MAX; - for (Position position : this->positions) { + for (const Position position : this->positions) { if (position.x < minX) minX = position.x; if (position.y < minY) minY = position.y; } // center the piece with an up bias std::set newPositions; - for (Position position : positions) { + for (const Position position : positions) { newPositions.insert(Position{(position.x - minX) + (verticalEmptyLines / 2), (position.y - minY) + ((horizontalEmptyLines + 1) / 2)}); } this->positions = std::move(newPositions); diff --git a/src/TextUI/main.cpp b/src/TextUI/main.cpp index 510ef6f..42df14b 100644 --- a/src/TextUI/main.cpp +++ b/src/TextUI/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) { std::srand(std::time(NULL)); #ifdef BENCHMARK - #ifndef NDEBUG + #ifdef DEBUG std::cout << "IMPORTANT: You are currently in debug mode, debug mode has lowest optimization settings and thus yields worse benchmarking results, to switch to release mode, type 'xmake f -m debug'." << std::endl; #endif @@ -127,7 +127,7 @@ void benchmarking(int min_size, int max_size) { using std::chrono::milliseconds; std::cout << "| n | Number | Generation | File storing | File retrieving | File size |" << std::endl; - std::cout << "| - | - | - | - | - | - |" << std::endl; + std::cout << "| -: | -: | :-: | :-: | :-: | -: |" << std::endl; Generator gen; PiecesFiles pf; diff --git a/xmake.lua b/xmake.lua index 8f4678d..a1e1e22 100644 --- a/xmake.lua +++ b/xmake.lua @@ -19,7 +19,7 @@ target("text") add_files("./src/TextUI/*.cpp") add_deps("core") -target("benchmark") +target("bmark") set_default(false) set_kind("binary") add_files("./src/TextUI/*.cpp") @@ -39,8 +39,8 @@ target("graph") add_deps("core") add_packages("sfml") -if is_mode("release") then - add_defines("NDEBUG") +if is_mode("debug") then + add_defines("DEBUG") end if is_plat("mingw") then