Better Programming

Advice for programmers.

Follow publication

Mafia — A Serverless Multiplayer Game

Jackson Bowe
Better Programming
Published in
5 min readFeb 27, 2023

--

The village at night | by Sera Elsden

This is the first article (of hopefully many) where I will be documenting my journey in creating a serverless multiplayer game, Mafia (name not final… unless???).

I will use this first article to cover the tools I intend to use and give a general idea of what this game should look like at the end. So, here we go.

What Is This Game?

I’m basing this game heavily on the popular tabletop game by the same name. It’s a social deduction game in which a majority team, the Town, tries to root out the opposing minority team, the Mafia.

Members of the Mafia are aware of their allies and must work together to mislead the Town and avoid suspicion. Town players are unaware of anyone else’s role and must use their deductive reasoning to locate evildoers.

Mechanics

The game isn’t strictly turn-based. However, it follows a similar principle. There are four states: Morning, Day, Evening, and Night.

During the Day, all town members (including the mafia members) gather to discuss what leads they have found on the Mafia. At this time, they may also decide to remove a player suspected of being a member of the Mafia.

In the Evening, the public forum closes, and players are given time to process the day’s conversation, and if possible, with their role, they can chose a player to target that night. For example, a detective may choose to follow another player and see who they visit that night. Mafia members are able to converse amongst themselves during this time.

During the Night, the game processes all the player’s actions.

In the Morning, the events of the previous Night are revealed to the town.

The cycle repeats until there is a winner.

Games Are for Nerds. What’s the Tech Stack?

Heavy sarcasm :).

What I’m using

I want the game to be playable in the web browser at this stage, which may change in future. Also, I’m primarily using AWS for the backend.

Backend

All application logic will be written in Python.

Frontend
The frontend will be made with Quasar Framework — a Vue.js wrapper. Quasar comes bundles with a wide array of prebuilt components and very thorough documentation. Another benefit is that Quasar streamlines the process of packaging a single codebase into multiple deployment formats: web, mobile, and desktop. This sparks joy.

The Glue
As I previously stated, my goal with this project is 100% serverless. However, another requirement is just as important — 100% Infrastructure as Code. IaC is exactly as it reads. All the infrastructure covered in the backend section should be provisioned in code, with nothing needing to be created in AWS manually.

There are several benefits to this approach:

  1. Changes to infrastructure can be tracked with Git. Manual editing via the AWS console is untrackable and generates no history.
  2. The project can be deployed with a single command. If I deploy in Australia, and then have reason to deploy in North America, I must be able to do so with confidence and speed.
  3. The project can be destroyed with a single command. This is extremely important. If I determine the cost becomes unsustainable, I must be able to completely eradicate all traces of it with no remnants remaining—scorched earth.

The IaC framework I will be using for this project is Serverless Stack (SST).

SST is a cloud architecture development kit that lets you provision Infrastructure as Code by leveraging the base AWS CDK with improvements geared towards serverless applications. If you’ve used any IaC providers in the past, like Terraform, AWS CDK, Serverless, SAM, etc. — I seriously recommend checking out SST. It’s next level.

Process, MVP, and Timeline

This project is my way of diving headfirst into serverless cloud development. I’m using something I’m passionate about to motivate and upskill myself in a field I think is the future. For this reason, I will attempt to follow as many best practices as possible and share them here as I adopt them.

Below is a flow chart with my rough architecture plan. This will no doubt change as the project matures.

Mafia architecture diagram

Process

User actions are sent via REST API to an AWS API Gateway. This distributes requests to the appropriate lambda microservice, called *Controllers.* The Controllers handle all application logic between frontend and backend services such as the database.

As there is no server, I cannot maintain a continuous state. All user actions must be written to the database. During the Night sequence, all user actions will be read from the database and combined with data about the game (settings, etc.).

The combined user actions and game settings will be resolved using my custom MafiaEngine. This will return the resolved game state to be communicated back to the users.

Minimum viable product

The maximum number of players in a game is 15. A typical game will have nine Town players, three Mafia players, and three Neutrals. A fully featured game will have large role diversity between the players. However, as players can share the same role, I will be aiming for the following:

  • Town: Citizen, Doctor, Bodyguard, Detective, Escort
  • Mafia: Mafioso, Liaison (evil Escort)
  • Neutral: Serial Killer, Survivor, Jester (of course)

The game will need a fully functioning lobby system, stage transitioning (morning/night/etc.), and state resolution.

Timeline

I began routine work in early January 2023 and have maintained decent weekly progress. I hope to have a playable version of this game out within two months (the end of April). Between now and then, I will aim for regular updates and cover technical roadblocks and solutions.

Conclusion

I don’t particularly want this series to be a generic game “devlog” thing. The real motivation behind this project was to get familiar with serverless cloud development, and I think it will be a massive learning opportunity.

I’m more interested in writing about how I’ve implemented some serverless features and provided a legitimate use case that is fulfilling.

If this project sounds interesting, I’d love to hear from you, especially if you see me running headlong into a classic pitfall.

Note: I’m keeping somewhat up-to-date technical documentation for the project at https://mafia-sdg.netlify.app/.

Cheers.

--

--

Jackson Bowe
Jackson Bowe

Written by Jackson Bowe

Software Engineer deep diving into serverless cloud architecture

Responses (1)

Write a response