Low-code remote-friendly “Codenames”
Tags: svelte, serverless, programming
Published: 2020-12-28 21:32:08

Board games are a perfect activity to do among friends. And one of the games I played with friends before being forced into lockdown was [Codenames](https://en.wikipedia.org/wiki/Codenames_(board_game)). There are some online options, but I find that manual actions help keep people engaged.

Codenames is a game of guessing which words in a set are related to a hint-word given by another player (the spymaster). There are two teams, the red and the blue, one player in each group is the spymaster, and the others are field agents.

To play a remote-friendly version of the game, we need to have a map card accessible to the spymasters and a 5x5 word grid accessible to everyone. 

**How can I use online services to enable and facilitate my friends to play codenames, even in lockdown?**

For the map card I took a picture of the physical cards and at the start of each round the spymasters pick a card and decide its orientation.

![Map cards picture](https://dev-to-uploads.s3.amazonaws.com/i/tv0jss9oobwba20u64kc.jpeg)

Since everyone can see the 5x5 word grid we decided to use [Miro](https://miro.com/). When field agents try to guess a word we use the shape background color to represent an innocent bystander (yellow), an opposing agent, or the assassin (black).

![5x5 grid with portuguese words](https://dev-to-uploads.s3.amazonaws.com/i/33v7w94z9ds6y5wyn0x1.png)

We spend 3 hours on a video call playing codenames, and with this setup, we reduced our distance and had a lot of fun.

---

# Enhancements

The setup works, but we can improve the manual actions when setting up a new round:
* create a random map card
* create a 5x5 grid with random words

## Create a Map Card

The map card has seven innocent bystanders (yellow), one assassin (black), nine items for the starting team and eight for the other team. A map card is also a 5x5 grid that matches the grid of words.

To create map cards, I created a web application using:
* [svelte](https://svelte.dev/), a framework to build web apps I wanted to try for a long time;
* [tailwindcss](https://tailwindcss.com/), a utility-first CSS framework, so the outcome is pleasant to look at;
* [vercel](http://vercel.app/) to deploy and serve the static files of the web app.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/10htko2ue2yr0nvt0hyn.png)

You can see a deployed version of the application at [https://codenames.fampinheiro.vercel.app/](https://codenames.fampinheiro.vercel.app/) and check the code on [GitHub](https://github.com/fampinheiro/codenames).

## Create a 5x5 Word Grid

Miro fits the purpose of showing the 5x5 word grid. However, the manual process of creating the grid with random words is tiresome. Can we automate the creation of the grid?

Looking through Miro documentation, we can use web-plugins to "modify objects on the board". We could create a web-plugin that on-demand would create a random 5x5 word grid at the start of each round.

To create a new application on Miro you need to get [a developer team](https://miro.com/app/dashboard/?createDevTeam=1) and then on [user settings apps](https://miro.com/app/settings/user-profile/apps) agree to the terms and conditions and create a new app.

The relevant settings for our web-plugin are the web-plugin link and the OAuth scopes.

![Miro create app settings](https://dev-to-uploads.s3.amazonaws.com/i/bfzpnmt5bqxuwsca5668.png)

The OAuth scopes depend on the type of interaction you want to have with the Miro SDK, in our case we need `boards:read` and `boards:write`.

### Miro Web-plugin Page

"Web-plugins are JS scripts that run on boards in isolated iframes. The JS code of a web-plugin communicates with the Miro application via PostMessage using the Miro SDK." ([source](https://developers.miro.com/docs/sdk))

In this case, the web-plugin page imports the SDK script and extends the bottom bar with a new icon. The new icon, when clicked, fetches new words and place them on the board in a 5x5 grid.
 
You can check the source code for the web-plugin page on [GitHub](https://github.com/fampinheiro/codenames/blob/master/public/miro.html).

The only thing missing to make our web-plugin functional is to create an API that returns 25 different words every time we make a request.

### Vercel Serverless Functions

Since we are already using vercel the most straightforward way to create the api is using the [serverless functions](https://vercel.com/docs/serverless-functions/introduction) service. The API gets the first 25 words on a randomized list of words and return them.

# How to Play

1. A spymaster generate a new map card [here](https://codenames.fampinheiro.vercel.app/) (the link is shareable)
2. Use the web-plugin on Miro to generate a new 5x5 word grid
3. Play the game use the shape background when field agents try to guess words
4. Go to **1**

---

# Thoughts

Although the solution described is not complicated, it shows you don't need to jump to a complex architecture, you can leverage several services to deliver value to your users. 

Product development combines systems thinking and software development, and you can try to get feedback from your users "glueing" services and tools together reducing the unknowns and uncertainties.

You can take advantage of the no-code and low-code services and tools rising in popularity to fulfil the primary purpose of a product, solve its users' problem. Use your toolbox to deliver value to your users, iterate and improve the value your product provides.