Skip to content

raouf2ouf/random-open-restricted-rps

Repository files navigation

[Random Open] Restricted RPS

TLDR; A Prouvably fair multiplayer Card Game based on Rock Paper Scissors. Players join by providing a collateral and recieve 6 random cards (a collection of Rock, Paper, Scissors cards) and 3 stars. Players play matches by chosing a card and betting a number of stars. At the end of the game, if a player has no more cards, he can redeem his stars for collateral. The fairness of the game is proven by the blockchain and any cheating is automatically detected.

Disclamer: The previous version of this game https://github.com/raouf2ouf/restricted-rps won the second best project at the Encode x Lightlink Hackathon and the new verson is submitted to the Encode x Polkadot Hackathon 24Q1. Details on the changes can be found here.

ror-rps

Links

Table Of Content

Changes for the Encode x Polkadot Hackathon

The previous version of this game submitted for the Encode x LightLink hackathon (won second best project) had various shortcommings pointed out by the judges, mainly, scaling. In the new version, we use Acurast.com and GetBlock.io to address these weaknesses. The following table explains the main changes:

Changes Previous version (github repo) Polkadot version
Technology
  • Frontend: Ionic / Wagmi
  • Backend: Nest (Nodejs)
  • Contracts: Foundry (Solidity)
  • Frontend: Next.js / Wagmi / Inkathon
  • Backend: n/a
  • Contracts: Foundry (Solidity) / Ink
Architecture Client-Server
A server is needed for automatic game creation, cards distribution, game closing, and distribution of player rewards. This Nodejs server relies on multiple Etherjs listeners.
Main issues:
  1. Reliability: The server fails regularly due to too many RPC http calls (for listeners) and too many submitted transactions at the same time.
  2. Trust: while the game is desined to eliminate the need for trusted third party, players need a minimum level of trust towards the server as its computations are not publically verifiable (initial deck generation, cards given to players) [even if any cheating done by the server will be publically detected at the end of game].
  3. Blockchain support: the server was already struggling listening to one blockchain, it needs a complete redesign for it to support multiple blockchains.
Serverless and fully decentrelized
With the help of Acurast cloud computing, a server is no longer needed, making the game 100% decentralised.
Solutions:
  • Reliability: with the use of multiple Acurast Jobs that start at different intervals, we can realiably automate the various tasks that a game needs. Furthermore, with the use of Getblock websocket RPCs we can limite the execution time of these jobs to 1-2 seconds at most.
  • Trust: with the change from hidden cards to open cards (see game design for more info), players no longer need to trust a thrid party (they will need to trust Acurast Rng numbers but that is a given).
  • Blockchain support: Now that the source of rng and automatisation is Acurast jobs, we can serve any EVM or Substrate chains. We currently have 8 jobs total: 4 jobs handle player Rng for EVM and Substrate, and 4 jobs that handle automatic game closing and reward destribution.
Scaling Games
  • Max nbr Players per Game: 6
  • Max total simultanious Players: 60
  • Nbr of Game Factories: 1
  • Max nbr Players per Game: 20 (achieved by changing deck representation)
  • Max total simultanious Players (same chain): +400 (achieved by using multiple acurast jobs)
  • Nbr of Game Factories: 5 (1 per blockchain) (achieved by using multiple Getblock rpc endpoints combined with multiple acurast jobs)
Scaling RPC calls The game requires more than 50 RPC calls per second. Furthermore, any lag on contract event listener can negatively impact the ability of players to make the right choice of cards. The handling of contracts event was not optimised along with the inability of the RPC to respond quickly. By using multiple Getblock.io websocket RPC and optimising RPC calls (40 calls per second per game) we achieve fluid gameplay.
Scaling Blockchains support In this version, only 1 blockchain (LightLink) was supported. By using Acurast as a chain-agnostic RNG provider along with Getblock RPCs we can support multiple evm and polkadot chains. Currently, we deployed the game for: Fantom Testnet, Azero Testnet, Polygon Mumbai, LightLink Testnet. Furthermore, deploying to a new blockchain is relatively straightforward as it only requires creating a Getblock RPC API keys and Acurast Jobs (along with integrating the proper wallet on the frontend).

Game Introduction and How to Play

Introduction

Rock, Paper, Scissors [RPS] is one the most iconic and played games all over the world (there is even an RPS World Championship. However, there was always a debate on wether it is a game of chance or a game of skill ?

Random Open Restricted RPS [RORRPS] is a variant that adds complexity and amplifies the role of chance and skill. It is inspired by the famous Resctricted RPS from the manga Kaiji along with the E-Card game from the same manga. By making the player cards public, chosing a card amounts to playing E-Card.

How to play

You start by joining a game and providing a collateral for which you will recieve:

  • 6 cards: a collection of Rock, Paper, Scissors cards.
  • 3 stars: used to bet when you play a card. They are redeemable for collateral at the end of the game.
  • In-game Cash: used to buy and sell cards. You can only redeem stars if you have no cards in you hand! (functionnality removed for now as the smart-contract is too big).

After which you can offer or answer a match: a match is offered by placing a hidden card and a bet (number of stars). Other players can answer your match by placing a card and bet at least equal to the minimum you indicated.

How to win [or lose]

  • You win a game when you have at least 3 stars and no cards at the end of the game. For each star above 3 you will recieve additional collateral.
  • You lose a game when you have less than 3 stars at the end of the game (you will still recieve part of your collateral for each star you have).
  • You draw a game when you have more than 3 stars and at least 1 card. You will only recieve the collateral you used.

Architecture and How it Works

The game is composed of two smart-contract:

  • RestrictedRPSFactory: handles game creation (deploys or resets an instance of the RestrictedRPSGame contract), collateral redeeming, and banning of cheaters.
  • RestrictedRPSGame: handles everything related to a game, from joining to matches along with cheat detection.

Along with these smart contract, there is a frontend to simplify contract interaction and a set of Acurast jobs that handle automation and Rng providing.

The following schemas describes how Acurast and Getblock are used to generate the Cards of a player: join-game-architecture

Known Issues

  • Acurast HttpPOST: There is currently an issue with Acurast Jobs, the HttpPost method sends a GET request rather than a POST request. this makes the job unabled to have up-to-date information on players to give the correct RNG. A workaround is currently in place only for Fantom Testnet as getting the gas fees is relatively easy for this chain.

Roadmap

This project (previous and current version) was started 4 weeks ago (mid february 2024). There is sill a lot of work to bring this game to the public, mainly:

  • 2024Q2:
    • Optimise frontend wallet connection: the blockchain change detection is currently unreliable.
    • Optimise Ink Smart Contracts: My knowledge of Ink is still limited, I believe the smart contract can be better optimized.
    • Deploy more Acurast Jobs and have a dedicated smartphone for our jobs.
    • Improve the reliability of the winning/loss aggregated data for players.
  • 2024Q3/4:
    • Public launch with Tournaments including prizes and NFTs.
    • Include Partners from Web3 and from the RPS community.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published