https://github.com/ariellourenco/life
This repository contains the implementation of Conway's Game of Life using ASP.NET Core.
https://github.com/ariellourenco/life
aspnetcore dotnet-core rest-api
Last synced: 2 months ago
JSON representation
This repository contains the implementation of Conway's Game of Life using ASP.NET Core.
- Host: GitHub
- URL: https://github.com/ariellourenco/life
- Owner: ariellourenco
- License: mit
- Created: 2025-03-13T16:40:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-23T17:07:26.000Z (11 months ago)
- Last Synced: 2025-08-23T23:41:12.113Z (11 months ago)
- Topics: aspnetcore, dotnet-core, rest-api
- Language: C#
- Homepage: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Conway's Game of Life
[](https://github.com/ariellourenco/life/actions/workflows/dotnet.yml)
This repository contains the implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) using ASP.NET Core. It exposes the game logic via HTTP endpoints which allows clients to interact with the simulation programmatically, such as retrieving the current grid state or advancing to the next generation.
It showcases:
- Minimal APIs
- Using EntityFramework and SQLite for data access
- OpenAPI
- User management with ASP.NET Core Identity
- Bearer authentication
- Writing integration tests for your REST API
## Assumptions
The implementation makes a few assumptions:
1. The max board size is 100x100.
2. Every cell outside the board is dead.
## Features
- Start a new [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) with the provided board state.
- Advance the board to the next generation.
- Retrieve the state of the board after a specified number of generations.
- Retrieve the final state of the board.
## Running the Project
To run the project locally, follow these steps:
1. Clone the repository:
```bash
git clone https://github.com/ariellourenco/life.git
cd life
```
1. Install the **dotnet-ef** tool: `dotnet tool install dotnet-ef -g`
1. Navigate to the `life/src/Life.Api/` folder.
1. Run `mkdir .db` to create the local database folder.
1. Run `dotnet ef database update` to create the database.
1. Learn more about [dotnet-ef](https://learn.microsoft.com/en-us/ef/core/cli/dotnet)
## Running Tests
To run the unit tests, use the following command:
```bash
dotnet test
```
## Configuration
The application can be configured using the `appsettings.json` file. The following settings are available:
- `MaxBoardSize`: The maximum size of the board.
- `MaxNumberOfAttempts`: The maximum number of generations the game can run to reach a final stage.
## Endpoints
Down below there are a list of request samples that can be used to test the Game of Life api. Moreover, we provide an [.http](src/Life.Api/game.http) file as a convenient way to the this API.
### Upload a New Board State
**POST** `/api/game/start`
Start a new [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) with the provided board state and returns the ID of the game.
**Request Body:**
```json
[
[false, true, false],
[false, true, false],
[false, true, false]
]
```
**Response:**
```json
{
"id": "guid"
}
```
### Get Next State for Board
**GET** `/api/game/{id}/next`
Retrieves the next state for the board.
**Response:**
```json
[
[ false, true, false ],
[ false, true, false ],
[ false, true, false ]
]
```
### Get State After X Generations
**GET** `/api/game/{id}/next/{generations}`
Retrieves the state of the board after a specified number of generations.
**Response:**
```json
[
[ false, true, false ],
[ false, true, false ],
[ false, true, false ]
]
```
### Get Final State for Board
**GET** `/api/game/{id}/final`
Retrieves the final state of the board. If the board doesn't reach a conclusion after a specified number of attempts, returns [422 Unprocessable Content](https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/422) status code.
**Response:**
```json
[
[ false, true, false ],
[ false, true, false ],
[ false, true, false ]
]
```