My experience developing a hidden role game in Reach

Abraham “Abe” Nalisi
Appminia
Published in
3 min readSep 6, 2022

When I first heard the words Decentralized Application, it did not occur to me how broad the use cases for such an implementation could be. Through the Decentralized Umoja bounty hack, I was introduced to Reach, a fairly easy to learn language that aids in the creation of smart contracts for use in blockchain.

Hidden role games are the kinds of games you play as a group. Everyone is given an identity and you have one or two members within the group with jeopardizing identities. It’s the task of everyone else to figure them out either before the time runs out, or before the mission at hand is completely jeopardized. With that said, there can be a plethora of games with this setup. Among Us is one such example. For our scenario, we picked a fairly simple one, Spyfall.

As a team, we dived into development right after going through the well-defined tutorials and workshops on the Reach website. The project we picked, a hidden role game, seemed challenging enough to excite us, but simple enough to tackle for a hackathon. However, the journey was not going to be as smooth as we’d imagined.

The logic for the game is fairly simple: The members of the group are assigned roles in a specific location (space station, pirate ship, etc.) but one of them is assigned the spy role and they do not know the location they’re in. The game then progresses with each player asking a different player questions that would let them either spill their spy identity or defend their knowledge of the location. All this without letting whoever the spy is know the location. There’s a timer to ensure that the game doesn’t go on forever. If the spy comes out and correctly identifies the location, the spy wins. If the other players figure out who the spy is, they win.

Enter Reach, and now you have to factor in stakes and winning remission. Crypto wallets need to be added and wagers collected at the start of the round. Whoever creates the lobby would have to determine how much for the wager and how many players are allowed to enter the lobby. Merging the Reach build with the logic was one hurdle. Getting the Reach code right, was another.

Thankfully, the community and our mentor proved to be useful resources in understanding the path we were taking. We had a problem handling multiple payouts and a couple of edge cases and worst-case scenarios. For the bounty, we decided to focus on getting the best-case scenarios to work perfect. In future iterations, we will work on getting the worst-case scenarios not to cause crashes and bugs in the game.
Reach handles smart contracts in a fluid and efficient way. It’s one of the best things I learned over the course of the hack. From the moment a wallet is connected, and the address bound to the contract, it stays open until when the contract is closed after payouts. This prevents any additional parties from joining midway through the contract execution and thereby secures the escrow wagers.

It’s been interesting building with Reach, and I’m grateful to the mentor, my teammates, and the community for the learning experience I’ve had in the bounty. It would be amazing to experience smart contracts in other sectors of the tech industry and Reach just might reach those heights we envision for blockchain.

--

--