Minesweeper with ECS

After some time in chats of game development communities like Love2D, raylib and itch.io I had heard tons of how great an ECS(Entity Component System architecture) is, how better than the usual OOP ones. After reading that multiple time I decided to give it a try and check if the advantages were real or if it was only preaching about their preferences.

Since minesweeper was a simple game I decided to remake my love2D minesweeper clone with an ECS architecture by using the tutorial Love2D | Entity Component System as starting point.

What is an ECS?

Entity Component System architecture is a pattern mostly used for games. It follows the composition over inheritance principle by defining each object in the game as an entity(player, ground, bullets, etc). This pattern has three main parts:

ECS in minesweeper

After following the tutorial and having the base structure and logic for the entity, component and system of the ECS, the next step was starting to implement my game with it.

The initial point was identifying what data I used to make the initial minesweeper implementation and creating the main components from that, so I created the components:

For each grid of the map an entity with each of the components was created. So we only have one entity with all the components (ehh not much composition in this case).

After starting trying to implement the systems, some way to communicate between them was missing, so I created an event module where the systems can register to listen for specific events and any system can fire an event. The received event has a table to pass any data. With all this ready I implemented the game logic with the following systems:

A bit of the initialization logic of the entities stayed in main.lua but could also be factored into a specific system if needed.

Result

This was a funny experiment, initially the ECS architecture was a bit different. But after testing it I found some advantages:

The same UI and logic was obtained with this implementation as we can see in the next image.

ECS Minesweeper

Repository

If you want to checkout the code of the project check the repository.