This contract implements a simple DICE game between two players with 50/50 odds of winning.
Before playing all players deposit funds into their @dice account just like the @exchange contract
- Player 1 proposes to bet 1 EOS and submits SHA256(secret1)
- Player 2 proposes to bet 1 EOS and submits SHA256(secret2)
Because Player 1 and 2 bet equal amounts their orders are matched and the game begins.
- A Player reveales their secret
- A 5 minute deadline starts whereby the first to reveal automatically wins unless the other player reveales
- The other player reveals and a winner is chosen and paid based upon the value of sha256( cat(secret1,secret2) )
- After the deadline anyone can trigger a default claim and the rewards
A variation on this game would be to add an additional information on offer creation that will get paid a commission when the player wins. With this commission in place there is financial incentive for a service provider to continue to execute the game in a timely manner as well as provide quality and entertaining interfaces on top of this game.
This same basic model can be used to build more robust games.
- Block Producers may exclude reveal transaction
- Losers may force winner to wait 5 minutes to get rewards
- Service providers may fail to auto-reveal on your behalf
- You may lose internet connectivity mid-game
- A blockhain reorganization could cause some havock if secrets are revealed too quickly
- @dice could protect users by rejecting reveals until a game creation is irreversible (about 45 seconds max)
- users could take risk themselves by deciding how many confirmations are required
- for small amounts it probably doesn't matter
- under normal operation of DPOS chains there are few if any chain reorganizations