{"id":15547656,"url":"https://github.com/lucaangioloni/gameoflife","last_synced_at":"2025-04-23T18:24:23.208Z","repository":{"id":62625812,"uuid":"111835350","full_name":"LucaAngioloni/GameOfLife","owner":"LucaAngioloni","description":"Game Of Life implementation using Numpy and PyQt for GUI","archived":false,"fork":false,"pushed_at":"2019-01-22T05:06:57.000Z","size":1966,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T02:22:16.063Z","etag":null,"topics":["board","conway","game","gameoflife","gui","pyqt","python","qt","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","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/LucaAngioloni.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}},"created_at":"2017-11-23T17:25:28.000Z","updated_at":"2025-01-21T10:40:21.000Z","dependencies_parsed_at":"2022-11-04T04:47:31.684Z","dependency_job_id":null,"html_url":"https://github.com/LucaAngioloni/GameOfLife","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaAngioloni%2FGameOfLife","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaAngioloni%2FGameOfLife/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaAngioloni%2FGameOfLife/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaAngioloni%2FGameOfLife/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucaAngioloni","download_url":"https://codeload.github.com/LucaAngioloni/GameOfLife/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250488532,"owners_count":21438802,"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":["board","conway","game","gameoflife","gui","pyqt","python","qt","simulation"],"created_at":"2024-10-02T13:09:56.803Z","updated_at":"2025-04-23T18:24:23.187Z","avatar_url":"https://github.com/LucaAngioloni.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GameOfLife\n## Overview\nThe **Game of Life** was invented in 1970 by the British mathematician John Horton Conway. Conway developed an interest in a problem which was made evident in the 1940’s by mathematician John von Neumann, who aimed to find a hypothetical machine that had the ability to create copies of itself and was successful when he discovered a mathematical model for such a machine with very complicated rules on a rectangular grid. Thus, the Game of Life was Conway’s way of simplifying von Neumann’s ideas. It is the best-known example of a cellular automaton which is any system in which rules are applied to cells and their neighbors in a regular grid. Martin Gardner popularized the Game of Life by writing two articles for his column “Mathematical Games” in the journal Scientific American in 1970 and 1971.\n\n## Rules of the Game\nThe game is played on a two-dimensional grid (or board). Each grid location is either empty or populated by a single cell. A location’s **neighbors** are any cells in the surrounding **eight adjacent locations**. The simulation of starts from an initial state of populated locations and then **progresses through time**. The evolution of the board state is governed by a few simple rules:\n1. Each populated location with one or zero neighbors dies (from loneliness).\n2. Each populated location with four or more neighbors dies (from overpopulation).\n3. Each populated location with two or three neighbors survives.\n4. Each unpopulated location that becomes populated if it has exactly **three** populated neighbors. \n5. All updates are performed simultaneously **in parallel**.\n\nThis figure illustrates the rules for cell death, survival, and birth:\n![Go_LRules.png](./images/Go_LRules.png)\n\n## Implementation\nThe game was implemnted using Python:\n  - Numpy for the state of the game (model, updates, evolution...) (a couple of lines use Scipy)\n  - PyQt5 for the GUI\n \n### The Model\nThe model has been implemented in the `GameOfLife` Class.\n\nThis class contains the game state and the rules of the game.\n\nIt provides methods to get, set, modify and evolve the state following the rules.\nIt also provides methods to load and save the state from and to file.\n\nAttributes:\n- mat = current state of the game\n- heatmap = weighted average of past states (history of past states)\n- do_heatmap = boolean value defining what to return in get_state (the state or the heatmap)\n- x, y = current board dimensions\n- initial_state = backed up initial state that becomes the state when/if reset\n\n### The game loop\nThe game loop has been implemented subclassing the `QTimer` class from the Qt Framework to create a custom timer that times out accordingly to a specific speed (duration) set live at runtime.\n\nThis is the `GolLoop` class:\n\nAttributes:\n- going = bool value representing the state of the game\n- currentTimer = value of time between GoL steps in ms\n\nIt fires a timeout signal every currentTimer ms.\n\nAll the update methods of the GUI elements and of the Model are connected to the time out signal emitted from this class.\n\n### The GUI\nThe GUI is composed of a main window (`MainWindow` class) containing some stock widgets and some custom widget developed for this game.\n\n#### GolViewer\nThis is the custom widget designed to show and edit (with mouse events) the state of the Game of Life.\n\nIt can receive as input 1 channel images (the state of the game or the current heat map) or color (color+alpha) images (maybe for a different representation of the state of the game).\n\nAttributes:\n- gol = reference to an object of class GameOfLife (the model)\n- drawing = bool value to keep track of mouse button long press and movement\n- V_margin = dimension of right and left margin in window (widget) coordinates for the image\n- H_margin = dimension of top and bottom margin in window (widget) coordinates for the image\n- h = board (gol state) height\n- w = board (gol state) width\n- lastUpdate = time of the last view update\n- pixmap = image representing the state of the game (QPixmap object) (self.pixmap())\n\n## Functionalities\nThe game can be launched from the `main.py` script:\n```\n$ python3 main.py\n```\n### Main window\nThe Main window presents itself like this:\n![Gui.png](./images/Gui.png)\n\n### Play/Pause\nThe user can play/pause or reset the board using the push buttons at the bottom.\nMoreover the speed (framerate) of the simulation can be changed using the dedicated slider even during the simulation.\n\n### Draw and delete\nThe user can draw new cells on the board using the **Left Click** of the mouse, and delete cells using **Right Click** (In both cases dragging the mouse while clicking is allowed and behaves like expected).\n\nThis can be done also while the simulation is running.\n\n### Load known patterns\nFrom the drop down menu at the top, the user can choose between some well known patterns to load and play.\n\n### Heatmap\nThis implementation of Game of Life presents also a Heatmap (History) of the past game states. To visualize it just check the check button at the top right. (example in the picture below)\n![Heatmap.png](./images/Heatmap.png)\n\n### Save and Load\nFinally the user can save his own creations and load them using the Load and Save buttons at the bottom right.\nA modal window will pop up so that the user can choose where to save or what to load.\n\nThe game states are saved in PNG format (1 channel images \\[0 dead cells, 255 living cells\\])\n\n### Game demonstration\n\n\u003cimg src=\"https://github.com/LucaAngioloni/GameOfLife/raw/master/images/Video.gif\" alt=\"Demonstration Gif\" data-load=\"full\"\u003e\n\n## Requirements\n| Software       | Version        | Required |\n| -------------- |:--------------:| --------:|\n| **Python**     |     \u003e= 3.5     |    Yes   |\n| **PyQt5**      |     \u003e= 5.1     |    Yes   |\n| **Numpy**      |Tested on v1.13 |    Yes   |\n| **Scipy**      |Tested on v1.0.0|    Yes   |\n| **Pillow**     |Tested on v4.3.0|    Yes   |\n| QDarkStylesheet|    \u003e= 2.3.1    | Optional |\n\nQDarkStylesheet was used for a better looking GUI (highly recommended) and can be found in [this GitHub Repo](https://github.com/ColinDuquesnoy/QDarkStyleSheet)\n\n## Future developements\nMaybe implement **Pan and Zoom** functionalities with fixed board size (big) not depending on the pattern loaded.\n\n## License\nLicensed under the term of [MIT License](http://en.wikipedia.org/wiki/MIT_License). See attached file LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaangioloni%2Fgameoflife","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucaangioloni%2Fgameoflife","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaangioloni%2Fgameoflife/lists"}