{"id":19692988,"url":"https://github.com/magnetrwn/margolus-cpp","last_synced_at":"2025-10-07T03:05:01.329Z","repository":{"id":188874582,"uuid":"679597649","full_name":"magnetrwn/margolus-cpp","owner":"magnetrwn","description":"Reversible cellular automaton simulator for Margolus neighborhood automata: from billiard ball, to gas diffusion, tron, and critters, or any other ruleset possible.","archived":false,"fork":false,"pushed_at":"2024-09-01T21:00:45.000Z","size":1604,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T11:57:18.908Z","etag":null,"topics":["automata","automaton","cellular-automaton","command-line","configurable","library","render","reversible"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magnetrwn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-17T07:38:09.000Z","updated_at":"2024-09-01T21:00:48.000Z","dependencies_parsed_at":"2023-12-30T12:27:39.455Z","dependency_job_id":"7d8ab93a-8b67-453a-b90f-46fcd6e6bf97","html_url":"https://github.com/magnetrwn/margolus-cpp","commit_stats":null,"previous_names":["magnetrwn/margolus-cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/magnetrwn/margolus-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetrwn%2Fmargolus-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetrwn%2Fmargolus-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetrwn%2Fmargolus-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetrwn%2Fmargolus-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magnetrwn","download_url":"https://codeload.github.com/magnetrwn/margolus-cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetrwn%2Fmargolus-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278712711,"owners_count":26032742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automata","automaton","cellular-automaton","command-line","configurable","library","render","reversible"],"created_at":"2024-11-11T19:14:57.379Z","updated_at":"2025-10-07T03:05:01.287Z","avatar_url":"https://github.com/magnetrwn.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Margolus CPP: Reversible cellular automaton simulator\n\n[![CodeFactor](https://www.codefactor.io/repository/github/magnetrwn/margolus-cpp/badge)](https://www.codefactor.io/repository/github/magnetrwn/margolus-cpp)\n\nMargolus CPP (`margolus-cpp`) is a simulator for different reversible cellular automata based on the [Margolus neighborhood](https://en.wikipedia.org/wiki/Block_cellular_automaton).\n\nThe behaviour of the simulator can be controlled by setting the ruleset used to control how each 2x2 block is changed for each iteration.\n\n![Demo](margolus-demo.gif)\n\n## Build\n\nTo build Margolus CPP on Linux systems, you can run `./build.sh` from project root.\nOther platforms such as Windows might require slight modifications, such as in the use of `\u003cunistd.h\u003e` for `usleep()`, and will need you to manually run `cmake` inside the build folder.\n\n## Storage\n\nSimulations can be loaded and saved, stored in an easily readable and understandable format. They contain simulation parameters and the gamerule used, as well as the status of the grid.\n\nCheck the `build/examples` folder to look at actual saves.\n\n## Usage as CLI utility\n\nOutput of `./margolus -h`:\n\n```\nAvailable command line options:\n  -h, --help                Display help message.\n  -l, --load arg            Path to the file to load.\n  -s, --save arg            Path to the file to save, once finished.\n  -S, --save-stdout         Show output file on stdout instead of an actual file.\n  -i, --iters arg (=0)      Iterations to run, positive forwards, negative backwards.\n  -r, --render arg (=ANSI)  Engine to use to render grid, options: q, ANSI, SDL2.\n  -o, --odd-flip            Flip render colors on odd iterations.\n  -a, --animated            Run with a 75ms step animation.\n```\nRunning `./margolus` with no arguments will just display the state of the grid, with default width and height, without stepping the simulation, but additional parameters can change the behaviour of the program.\n\nFor example, when running `./margolus -i-100 -a`, a 100 step animation will run **backward** steps of the grid.\n\n## Usage as library\n\n**Note:** I haven't looked at this for a while, so this is likely *outdated*.\n\nHere is a sample program using Margolus CPP.\n\n```cpp\n#include \u003ciostream\u003e\n\n#include \"margolus.hpp\"\n#include \"marg_render.hpp\"\n\nint main() {\n    // Create a Margolus simulator with a 10x10 grid and specified block transforms\n    std::vector\u003cstd::string\u003e transforms = { \"ROTATE_90_LEFT\", \"INVERT\" };\n    Margolus marg(10, 10, transforms);\n\n    // Fill a rectangular region with random cells\n    marg.fillRect(2, 2, 7, 7, Margolus::NOISE, 0.8);\n\n    // Fill a specific point by swapping its value\n    marg.fillPoint(3, 3, 6, 6, Margolus::TOGGLE);\n\n    // You can also access the grid directly through indexes\n    marg[3][8] = true;\n\n    // Display the initial grid using the render functionality\n    std::cout \u003c\u003c \"Initial Grid:\" \u003c\u003c std::endl;\n    MargolusRender::basicANSI(marg);\n\n    // Perform 20 forward steps\n    for (size_t i = 0; i \u003c 20; i++)\n        marg.step(Margolus::FORWARD);\n\n    // Show current grid\n    std::cout \u003c\u003c \"Grid after 20 forward steps:\" \u003c\u003c std::endl;\n    MargolusRender::basicANSI(marg, marg.getOffset());\n\n    // Perform 20 backward steps\n    for (size_t i = 0; i \u003c 20; i++)\n        marg.step(Margolus::BACKWARD);\n\n    // Show current grid\n    std::cout \u003c\u003c \"Grid after 20 backward steps:\" \u003c\u003c std::endl;\n    MargolusRender::basicANSI(marg, marg.getOffset());\n\n\n    return 0;\n}\n\n```\n\n## Contributing\n\nIf you feel like contributing, feel free to send issues and PRs! If you use VS Code, the `clangd` extension can be used with the project automatically detecting location of files after running `./build.sh` at least once.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetrwn%2Fmargolus-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagnetrwn%2Fmargolus-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetrwn%2Fmargolus-cpp/lists"}