{"id":16011029,"url":"https://github.com/ethomson/dat-life","last_synced_at":"2025-03-17T20:30:53.461Z","repository":{"id":44208862,"uuid":"275336984","full_name":"ethomson/dat-life","owner":"ethomson","description":"dat conway life","archived":false,"fork":false,"pushed_at":"2024-06-16T12:31:29.000Z","size":64,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T03:41:47.756Z","etag":null,"topics":["cellular-automata","conways-game-of-life"],"latest_commit_sha":null,"homepage":"https://npmjs.com/dat-life","language":"TypeScript","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/ethomson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2020-06-27T09:11:28.000Z","updated_at":"2023-12-18T14:26:02.000Z","dependencies_parsed_at":"2024-10-27T16:11:56.384Z","dependency_job_id":"344860ff-4c20-42e3-b9c2-7ff0c37f3455","html_url":"https://github.com/ethomson/dat-life","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":"0.19999999999999996","last_synced_commit":"2caf14dbb78520211913bbea141865ee368eda63"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethomson%2Fdat-life","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethomson%2Fdat-life/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethomson%2Fdat-life/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethomson%2Fdat-life/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethomson","download_url":"https://codeload.github.com/ethomson/dat-life/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878488,"owners_count":20362433,"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","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":["cellular-automata","conways-game-of-life"],"created_at":"2024-10-08T13:22:50.761Z","updated_at":"2025-03-17T20:30:53.127Z","avatar_url":"https://github.com/ethomson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Conway's Game of Life\n\nA TypeScript library for [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) that supports a typical implementation, multi-color versions and other variations on the standard game.\n\nThis library does not support any mechanism to output the board; users are responsible for its display, this library merely calculates the state of the game board at each generation.\n\nSee [examples/life.js](examples/life.js) for an example of a console application that will draw the board.\n\n## Usage\n\n1. Create a new instance of the `Life` object - with optional width and height of the game board:\n\n        const life = new Life(width, height);\n\n2. Set the initial conditions.  The initial board is blank, but you can either randomize the layout of the populants of the board:\n\n        life.randomize();\n\n    Or you can place the population explicitly - given the `x`/`y` coordinates of the board, you can set a cell to have a live populant:\n\n        life.set(x, y, 1);\n\n    Or to have a no populant:\n\n        life.set(x, y, 0);\n\n3. Get the board data.  You can get the value of a single cell by its `x`/`y` coordinates:\n\n        const alive = life.get(x, y);\n\n4. Move on to the next generation.\n\n        life.next();\n\n    Then you can continue displaying the board (go to step 3).\n\n## Example\n\nAdd the [`dat-life`](http://npmjs.com/dat-life) package (eg, `npm install dat-life`).  Then:\n\n```javascript\nconst { Life } = require('dat-life');\n\nconst boardWidth = 80; // width of the game board\nconst boardHeight = 24; // height of the game board\n\nconst life = new Life(boardWidth, boardHeight);\nlife.randomize(); // set up the initial board with random populantss\n\nwhile (true) {\n    for (let y = 0; y \u003c boardHeight; y++) {\n        for (let x = 0; x \u003c boardWidth; x++) {\n            if (life.get(x, y)) {\n                process.stdout.write('*');\n            }\n            else {\n                process.stdout.write(' ');\n            }\n        }\n\n        process.stdout.write('\\n');\n    }\n\n    processs.stdout.line('\\n');\n    life.next();\n}\n```\n\n## Color mode\n\nThis package supports the [standard 2- and 4-color versions of the Game of Life](https://conwaylife.com/ref/mniemiec/color.htm) (called _immigration_ and _quad-life_, respectively).\n\n```javascript\n    life.setColors(2); // immigration\n    life.setColors(4); // quad-life\n```\n\nThe default 2- and 4-color versions both handle the birth and death of cells like the default Game of Life does - meaning that cells live and die according to the default rules, but coloring is based on unrelated rules.\n\nThis package also supports a new \"decay\" mode, which changes the way way that alive cells die in color mode.\n\n```javascsript\n    life.setDecay(true); // decay mode\n```\n\nIn decay mode, cells do not simply die from overcrowding or exposure.  Instead, cells are reduced by a color value.  (So if a cell is at color `3` but has overcrowding, by default when the cell has overcrowding, it would move from color `3` to dead.  In decay mode, the color is simply reduced - so color `3` changes to color `2`.)\n\nDecay mode is especially useful for games that begin in packed or highly populated initial conditions where you don't want every cell to die immediately from overpopulation.\n\n## License\n\ndat-life is released under the MIT license.\n\nSee the [license file](LICENSE.txt) for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethomson%2Fdat-life","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethomson%2Fdat-life","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethomson%2Fdat-life/lists"}