This smart contract implement rock paper scissors game on Near blockchain, which use a cryptographic primitive named commitment.
Supposed that alice and bob want to play a game:
- Someone create a new game, get game id(gid);
- Alice use her private factor(such as hash of signature(gid, shape)) to pass her commitment to contract, which bind her choice to this commitment without showing it.
- Bob do the same.
- Now that both alice and bob cannot change his or her choice. Alice can reveal her choice(Shape);
- Bob can also reveal his choice(He may choose not to reveal, so some punishment is needed to implemented later).
- Now that Alice and Bob both reveal their choices, someone(maybe the winner) can run the get_result method to show the winner!
cargo test -- --nocapture
- Limit total game count
- Limit the number of games a player can play at the same time
It can be implemented to bet on:
- Near, the native token of Near blockchain
- NEP-141 token(fungible token standard of Near)
- NEP-4 token(NFT standard of Near)
A time window mechanism is needed to avoid locking bet money permenantly.
Currently the contract only support two-players schema. In reality, rock paper scissors game can be played by more than two people with multiple rounds.