diff --git a/.gitignore b/.gitignore index fbdafd5..83ce8ae 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ build/ # personnal documentation doc/*.txt -doc/*.violet.html +doc/diagrams/*.violet.html doc/mockups/* # data files diff --git a/README.md b/README.md index 8a697f8..e014240 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Modern stacker game with every polyominoes from size 1 to 15, made in C++ with [ // TODO when the game is finished // -This game has been tested on and built on Windows 11 and WSL2 Ubuntu only. +This game has been tested on and built for Windows 11 and WSL2 Ubuntu. If your OS isn't compactible with either of theses two, you can try [manually building the project](#manual-build). ## How to play @@ -19,7 +19,6 @@ Each gamemode has its own objective, but you can play as you wish. You can see and change in-game keybinds in the **SETTINGS** section of the main menu! All of in-menu navigation is done with the **arrow keys**, the **Enter key** and the **Escape key**. Theses are unchangeable keybinds. You will find more infos about the Rotation System, the scoring system, or the different pieces type in the **INFO** section of the main menu. -If you want to know more details about the generation of polyominoes, [check the documentation](/doc/)! ## Features @@ -51,6 +50,9 @@ Pieces select screen AutoRS demonstration ![](./doc/readme/rotations.gif) +0° spins demonstration +![](./doc/readme/rotation_0.gif) + ## Manual build This project uses xmake for compiling, xmake is cross-platform and works in most OS, xmake also automatically install supported librairies. @@ -76,6 +78,7 @@ To switch between debug and release mode: ``xmake f -m release`` If for some reasons you wanna run the command line version (not updated): +``xmake build text`` ``xmake run text`` ### Package the project @@ -102,8 +105,14 @@ If for some reasons you wanna run the command line version (not updated): | 12 | 126759 | 2s 709.277ms | 1s 530.34ms | 0s 155ms | 1647867 bytes | | 13 | 476270 | 10s 668.308ms | 7s 395.512ms | 0s 765.601ms | 6667780 bytes | | 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 normalizing 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`` ## Credits diff --git a/doc/class_diagramm_core.png b/doc/diagrams/class_diagramm_core.png similarity index 100% rename from doc/class_diagramm_core.png rename to doc/diagrams/class_diagramm_core.png diff --git a/doc/class_diagramm_pieces.png b/doc/diagrams/class_diagramm_pieces.png similarity index 100% rename from doc/class_diagramm_pieces.png rename to doc/diagrams/class_diagramm_pieces.png diff --git a/doc/readme/rotation_0.gif b/doc/readme/rotation_0.gif new file mode 100644 index 0000000..63182f7 Binary files /dev/null and b/doc/readme/rotation_0.gif differ diff --git a/src/TextUI/main.cpp b/src/TextUI/main.cpp index cf97bee..5663a3f 100644 --- a/src/TextUI/main.cpp +++ b/src/TextUI/main.cpp @@ -6,46 +6,57 @@ #include #include +static const int MAXIMUM_PIECES_SIZE = 10; +static const int BENCHMARK_PIECES_SIZE = 15; -void testGeneratorForAllSizes(int amount); + +void testGeneratorForAllSizes(int max_size); void testGeneratorForOneSize(int size); -void testGeneratorByprintingAllNminos(int n); -void testStoringAndRetrievingPieces(int size); -void generateFilesForAllSizes(int amount); -void generateFilesForOneSize(int size); -void loadFromFilesForOneSize(int size); -void readStatsFromFilesForAllSizes(int amount); +void printPiecesByTypesForOneSize(int size); +void readStatsFromFilesForAllSizes(int max_size); -void benchmarking(int max_size); +void benchmarking(int min_size, int max_size); int main(int argc, char** argv) { std::srand(std::time(NULL)); - // dev: generate files if it hasn't been done before, UI will NOT generate the files - //generateFilesForAllSizes(10); + #ifdef BENCHMARK + benchmarking(1, BENCHMARK_PIECES_SIZE); + #else + // dev: generate files if it hasn't been done before, UI will NOT generate the files + //generateFilesForAllSizes(10); - TextApp UI; - UI.run(); + PiecesFiles pf; + for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { + if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) { + std::cout << "INFO: Pieces files for size " << i << " not found, generating..." << std::endl; + pf.savePieces(i); + } + } + + TextApp UI; + UI.run(); + #endif return 0; } -void testGeneratorForAllSizes(int amount) { +void testGeneratorForAllSizes(int max_size) { using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::duration; using std::chrono::milliseconds; Generator generator; - for (int i = 1; i <= amount; i++) { + for (int i = 1; i <= max_size; i++) { auto t1 = high_resolution_clock::now(); std::vector n_minos = generator.generatePolyominoes(i); auto t2 = high_resolution_clock::now(); duration ms_double = t2 - t1; - std::cout << "generated " << n_minos.size() << " polyominoes of size " << i << " in " << ms_double.count() << "ms" << std::endl; + std::cout << "Generated " << n_minos.size() << " polyominoes of size " << i << " in " << ms_double.count() << "ms" << std::endl; } } @@ -67,24 +78,8 @@ void testGeneratorForOneSize(int size) { } } -void testGeneratorByprintingAllNminos(int n) { - Generator generator; - std::vector n_minos = generator.generatePolyominoes(n); - - for (Polyomino& n_mino : n_minos) { - n_mino.goToSpawnPosition(); - } - std::sort(n_minos.begin(), n_minos.end()); - - for (Polyomino& n_mino : n_minos) { - - std::cout << n_mino << std::endl; - } -} - -void testStoringAndRetrievingPieces(int size) { +void printPiecesByTypesForOneSize(int size) { PiecesFiles piecesFiles; - piecesFiles.savePieces(size); std::vector pieces; std::vector convexPieces; @@ -108,79 +103,9 @@ void testStoringAndRetrievingPieces(int size) { } } -void generateFilesForAllSizes(int amount) { - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; +void readStatsFromFilesForAllSizes(int max_size) { PiecesFiles piecesFiles; - - for (int i = 1; i <= amount; i++) { - auto t1 = high_resolution_clock::now(); - piecesFiles.savePieces(i); - auto t2 = high_resolution_clock::now(); - - duration ms_double = t2 - t1; - std::cout << "Generated pieces files for size " << i << " in " << ms_double.count() << "ms" << std::endl; - } - - std::vector pieces; - std::vector convexPieces; - std::vector holelessPieces; - std::vector otherPieces; - for (int i = 1; i <= amount; i++) { - auto t1 = high_resolution_clock::now(); - piecesFiles.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces); - auto t2 = high_resolution_clock::now(); - - duration ms_double = t2 - t1; - std::cout << "Read pieces from files for size " << i << " in " << ms_double.count() << "ms" << std::endl; - } -} - -void generateFilesForOneSize(int size) { - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - PiecesFiles piecesFiles; - - std::cout << "Generating " << size << "-minos files" << std::endl; - for (int i = 0; i < 10; i++) { - auto t1 = high_resolution_clock::now(); - piecesFiles.savePieces(size); - auto t2 = high_resolution_clock::now(); - - duration ms_double = t2 - t1; - std::cout << ms_double.count() << "ms" << std::endl; - } -} - -void loadFromFilesForOneSize(int size) { - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - PiecesFiles piecesFiles; - - std::vector pieces; - std::vector convexPieces; - std::vector holelessPieces; - std::vector otherPieces; - std::cout << "Loading " << size << "-minos from files" << std::endl; - for (int i = 0; i < 10; i++) { - auto t1 = high_resolution_clock::now(); - piecesFiles.loadPieces(size, pieces, convexPieces, holelessPieces, otherPieces); - auto t2 = high_resolution_clock::now(); - - duration ms_double = t2 - t1; - std::cout << ms_double.count() << "ms" << std::endl; - } -} - -void readStatsFromFilesForAllSizes(int amount) { - PiecesFiles piecesFiles; - for (int i = 1; i <= amount; i++) { + for (int i = 1; i <= max_size; i++) { std::vector pieces; std::vector convexPieces; std::vector holelessPieces; @@ -194,7 +119,7 @@ void readStatsFromFilesForAllSizes(int amount) { } } -void benchmarking(int max_size) { +void benchmarking(int min_size, int max_size) { using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::duration; @@ -206,7 +131,7 @@ void benchmarking(int max_size) { Generator gen; PiecesFiles pf; - for (int i = max_size; i <= max_size; i++) { + for (int i = min_size; i <= max_size; i++) { std::cout << "| " << i; auto t1 = high_resolution_clock::now(); diff --git a/xmake.lua b/xmake.lua index d534d59..493efd2 100644 --- a/xmake.lua +++ b/xmake.lua @@ -11,18 +11,27 @@ target("core") add_files("src/Pieces/*.cpp") add_files("src/Core/*.cpp") -target("text") - set_kind("binary") - set_default(false) - add_files("./src/TextUI/*.cpp") - add_deps("core") - target("graph") + set_default(true) set_kind("binary") add_files("./src/GraphicalUI/**.cpp") add_deps("core") add_packages("sfml") +target("text") + set_default(false) + set_kind("binary") + add_files("./src/TextUI/*.cpp") + add_deps("core") + +target("benchmark") + set_default(false) + set_kind("binary") + add_files("./src/TextUI/*.cpp") + add_deps("core") + add_defines("BENCHMARK") + + -- -- If you want to known more usage about xmake, please see https://xmake.io --