This repository is smart contract development of rock-scissors-paper powered by blockchain.
Players can create a game alikes room of traditional online game.
If opponent participate in the game, they start rock-scissors-paper with 3 steps - bet, commit, reveal.
GameFactory.sol contract keep tracks a number of games owned by the creator.
The number (0 to number of games) represents game number because when creating game using new
keward, it adds the number as salt.
So when one wants to find address of game played, simply use GetGameAddress function that calculate address of Game contract.
If one wants to join game, he/she manually call participate function to join.
When participation succeed, the phase shifts to Bet
phase and game clock (expiration clock) starts to tick.
In Bet
phase, both should call bet function giving ether equavalant to the bet size state variable initiallized by constructor.
In Commit
phase, both should call commit function with their commit which is keccak hashed bytes32 rock || scissors || paper and random number named salt.
In Reveal
phase, at lease one should call reveal function with their rock || scissors || paper and salt used.
In this phase, if one who does not reveal, opponent takes winner.
Winner takes all the money in the pot and if game is tied, the phase becomes Commit
and play again.
The game can not be done ideally - both of one or both may not take required actions on each step except Participate
phase.
So if opponent does not take action, the player can claim opponent has been vanished.
It will kick out the player or makes the player winner resetting the game.