This is a classic guess coin game (Heads or Tails) implemented by the Chialisp.

Overview

Overview

This is a classic guess coin game (Heads or Tails) implemented by the Chialisp. It is an absolutely fair P2P game based on the Chia blockchain. You can play with anyone in the world without custody.

Requirements

  • You need to run the game with a synced Chia full node (Wallet)
  • Python 3.7.5+
  • Some Mojos (XCH)

Installation

git clone https://github.com/ytx1991/ChiaHeadsOrTails.git
cd ChiaHeadsOrTails
pip install -r requirements.txt

Configuration

Change the config.ini file before the play or I will get all your wins :D

[GameSetting]
;The wallet address you want receive the reward Mojos
RewardPuzzleHash=0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21
;A pair of BLS keys, it's not your wallet key. You can create a new Chia wallet and get a pair of keys. The keys must be unique.
SignPrivateKey=0x2423cdec6398dd75917827344e8f77c968521008578a9b06cddf309e119ee4d1
SignPublicKey=0xafc5afdd4f567c38138430dbd7e2c5f4a079602739e94625e94540f23bf0f91cb003388ece0044f437515dc7fae3f2d1
FreezeSeconds=302400

How to play

Overview

1 Dealer of the game starts a new game. It will create a local key file and return a game hash. Example:

F:\Projects\ChiaHeadsOrTails>python game.py new
The mojos you bet for this game (1 XCH = 1000000000000 mojo): 100
You flipped the coin and saw it is (HEAD or TAIL): HEAD
PLEASE SAFELY KEEP THE 76c4d49d76722bae088a4bc12bb341be0225e9e307f4bb7104345e8a02efe61b.key FILE and FILE NAME, OTHERWISE YOU WILL LOSE!
Now, please transfer your bet 100 mojos to the dealer coin address xch1dvakrdefuhty9yytusda8qshxa3vttz5jmke3havsn46nmz4v4wqthc9e8.
You can track the transaction at https://chia.tt/info/address/xch1dvakrdefuhty9yytusda8qshxa3vttz5jmke3havsn46nmz4v4wqthc9e8
Send the game hash to your friends to start the game:
0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21|100|0x76c4d49d76722bae088a4bc12bb341be0225e9e307f4bb7104345e8a02efe61b|100|0x6b3b61b729e5d642908be41bd382173762c5ac5496ed98dfac84eba9ec55655c
NOTE: As the dealer you need to reveal the winner in 100 seconds after the player committed the guess.

2 Dealer pays the bet to the dealer coin address. You can use the chia UI client to do this. Remember the unit is Mojo not XCH and you need to EXACT amount of Mojos. A new dealer coin will be created after the payment confirmed.

3 Dealer publishing the game hash to the world. Anyone who know the game hash can join the game.

4 Player inputs the game hash. It will return a player coin address

F:\Projects\ChiaHeadsOrTails>python game.py play
Input the game hash you want to play: 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21|100|0x76c4d49d76722bae088a4bc12bb341be0225e9e307f4bb7104345e8a02efe61b|100|0x6b3b61b729e5d642908be41bd382173762c5ac5496ed98dfac84eba9ec55655c
This is a valid game.
Now you need to pay your bet 100 mojos to address xch1d4gq0dsgp9tgxqpk04mem7w43lnfuxr6cn4jlaexqtt4qwzn8gmsksharm before the guess.
You can track the transaction at https://chia.tt/info/address/xch1d4gq0dsgp9tgxqpk04mem7w43lnfuxr6cn4jlaexqtt4qwzn8gmsksharm

5 Player pays the bet to the player coin address. You can use the chia UI client to do this. Remember the unit is Mojo not XCH and you need to EXACT amount of Mojos. A new playercoin will be created after the payment confirmed

6 Player makes a guess (HEAD or TAIL) and commit the game. No one can refund after the commit. Mojos from dealer & player coins will send to the stake coin.

F:\Projects\ChiaHeadsOrTails>python game.py commit
Input the game hash you want to commit: 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21|100|0x76c4d49d76722bae088a4bc12bb341be0225e9e307f4bb7104345e8a02efe61b|100|0x6b3b61b729e5d642908be41bd382173762c5ac5496ed98dfac84eba9ec55655c
You guess the coin is (HEAD or TAIL): HEAD
{'status': 'SUCCESS', 'success': True}
The game is set. Wait the dealer reveal the winner. If the game is timeout you can claim all Mojos by the "timeout" command.

7a Dealer needs to reveal the winner before the timeout (set by the dealer). If the player guess is wrong then the dealer will win the game. All Mojos will send to the winner wallet address.

F:\Projects\ChiaHeadsOrTails>python game.py reveal
Input the game hash you want to reveal: 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21|100|0x54910a2489aec3f015e4473129bdd47c052bced441a681ee05e4de225bd16752|302400|0xc8e4cf0346d30e1344bb05f32bc5eff28ca4ec6ad63a66aabce564b64a20f4eb
Reveal key is B2BBFFRA4S7KUC9N
Dealer coin 0010fcfe7a76e124ae3cb8b15ae005e1d8645e5e8f2d949313553a98f845b050 spent, revealing the winner ...
Player 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21 guessed the coin is TAIL
{'status': 'SUCCESS', 'success': True}
You win! 200 mojo will send to your address 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21.

7b Player can claim all Mojos if the dealer doesn't reveal the winner before the timeout. The dealer can still reveal the winner after the deadline and before the player withdraw.

F:\Projects\ChiaHeadsOrTails>python game.py timeout
Input the game hash you think it is timeout: 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21|100|0x76c4d49d76722bae088a4bc12bb341be0225e9e307f4bb7104345e8a02efe61b|100|0x6b3b61b729e5d642908be41bd382173762c5ac5496ed98dfac84eba9ec55655c
Trying to withdraw timeout game ...
Dealer coin f3dfb6b58150d3c6312f5ff969b308f73add15b49b384a083da5d2b82ddcd811 spent, revealing the winner ...
Player 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21 guessed the coin is HEAD
{'status': 'SUCCESS', 'success': True}
You win! 200 mojo will send to your address 0x59545e1cf881294a631dc96772cf64605e6f6943d4214a32e43c32aa02b7ec21.

Q & A

What is a Game Hash

Game Hash is a unique string represents a game. It has fixed format and useful information.

Game Hash format: DEALER_REWARD_ADDRESS|BET_AMOUNT_MOJO|TOSS_HASH|FREEZE_SECONDS|DEALER_COIN_PUZZLE

DEALER_REWARD_ADDRESS: The wallet address of the dealer

BET_AMOUNT_MOJO: The bet for the game in Mojo. Both dealer and player have to pay same amount of Mojo.

TOSS_HASH: A random encrypted string, indicates the coin is HEAD or TAIL. It is hash by a random key owned by the dealer.

FREEZE_SECONDS: The reaction time for the dealer to reveal the winner after the player commit the game. If the dealer cannot reveal the winner in time than the player can withdraw all the Mojo.

DEALER_COIN_PUZZLE: The puzzle hash of the dealer coin for this game.

Can I refund my bet?

Sure, but only before the game set. You can use the "refund" command to do it.

I paid wrong amount of Mojo, what should I do?

You must pay the exact amount of Mojo to continue the game. No matter you paid less or more, you should refund you bet first then pay again.

I don't have any Mojo, how to play?

You don't have to pay the bet by youself. As long as you get the coin address, you can ask you friends pay the bet for you.

Why this is a fair game?

Everything is locked by the Chialisp. No one can cheat the blockchain. You cannot refuse to acknowledge the winner or change the commit guess / fact.

Owner
Kronus91
Kronus91
Cricket game using PYQT

Cricket-game-using-PYQT This is a Fantasy cricket Desktop application build in p

Sanket Mane 1 Jan 03, 2022
HTTP API for FGO game data. Transform the raw game data into something a bit more manageable.

FGO game data API HTTP API for FGO game data. Transform the raw game data into something a bit more manageable. View the API documentation here: https

Atlas Academy 51 Dec 26, 2022
A simple game with the main idea to be: Guess The Number

GuessTheNumber GuessTheNumber is a simple game I made using Python. The main mechanic of the game is to guess the number that randomly generated from

0 Jun 24, 2022
Web frontend to play games from 2008 Miniclip - uses Ruffle for playback

cliparchive Description A set of scripts to download games from the Wayback Machine's archive of Miniclip.com, and a Web frontend to play them using r

Simon Garrelou 3 Dec 09, 2022
🪨 📄 ✂ game in python with recursion

🪨 📄 ✂ Game Rock Paper Scissor game in python with recursion ⚙️ Developer's Guide Things you need to get started with this code:- Download python3 fr

Atul Anand 3 Jul 25, 2022
HackNC 2021 Project

pyTunes HackNC 2021 Project Setting Up Once the repo is cloned, install the requirements through pip install -r ./requirements.txt Once that is done,

Demo 1 Nov 07, 2021
Ultimaze est un jeu en 2.5D, réalisé dans le cadre d'un projet de NSI.

Ultimaze Ultimaze est un jeu en 2.5D, réalisé dans le cadre d'un projet de NSI. La consigne était d'utiliser la librairie pygame pour créer un jeu en

parlabarbedeMerlin 3 Sep 17, 2022
Minecraft Script to Tellraw Datapack Generator

Minecraft Script to Tellraw Datapack Geneator (STDG) can generate a chain of tellraw command in datapack from script.

1 Jan 28, 2022
TetrisAI - Tetris AI Bot using computer vision to play game automatically

Tetris AI Tetris AI Bot using computer vision to play game automatically bot.py

11 Aug 29, 2022
Lint game data metafiles against GTA5.xsd for Rockstar's game engine (RAGE)

rage-lint Lint RAGE (only GTA5 at the moment) meta/XML files for validity based off of the GTA5.xsd generated from game code. This script accepts a se

GoatGeek 11 Sep 18, 2022
Aftermath is an anti token grabber written in Python3.

🎈 Aftermath 🎈 Aftermath is an anti token grabber written in Python3. This tool with a GUI setup is checking the Downloads folder to search for token

Billy 39 Dec 16, 2022
AI Games and its programming solution with Python.

Problem: Save the princess: Problem defination on Hackerrank: https://www.hackerrank.com/challenges/saveprincess About problem: Princess Peach is trap

Hasit Parmar 1 Feb 19, 2022
Setup minecraft server (Tuinity) to your directory

hapeshiva server-setup Setup minecraft server (Tuinity) for you. Support for optimization Create optimized yml Customazible server port and view dista

3 May 11, 2022
Repository for the DecodED2 Game Project!

DecodED2 Game Project Hello everyone! Welcome to the GitHub Repository for DecodED2, as a start you'll need to clone this repository and make sure you

6 Sep 29, 2021
This is text based adventure game

CHOOSE-YOUR-OWN-ADVENTURE This is text based adventure game CONTRIBUTORS Aditya binukumar Srishti Sharma Shiva Tripathi Tanishq Tanwar ABOUT Theme: Ho

Tanishq Tanwar 3 May 31, 2022
Create a Hangman Game using Python and all techniques of Python.

Hangman Game Created by Fernando Callasaca Game rules: Choose a word and if you guess it will appear completed. In case it is not the word then the ma

Fernando Callasaca 3 Nov 01, 2021
This is a simple game made using pygame.

Ball breaker This is a simple game made using pygame game view The game view have been updated wait for the new view to be uploaded Game_show.mp4 Lear

Rishikesh Kumar 3 Nov 05, 2021
This is a 2D Link to the Past-esque game made using Python 3.2.5 and pygame 1.9.2

Queen-s-Demise Queen's Demise This is a 2D Link to the Past-esque game made using Python 3.2.5 and pygame 1.9.2 I made this for a game development cla

Zoey 1 Dec 15, 2021
Useful guides, tutorials, and FAQs related to LEGO Universe and Darkflame Universe.

Awesome Lego Universe A curated list of awesome things related to LEGO Universe. LEGO Universe was a kid-friendly massively-multiplayer online role pl

Eric Myllyoja 33 Dec 12, 2022
This repository has the lessons of the gamming programming course

learning-python-game-programming This repository has the lessons of the gamming programming course Na faculdade, estou fazendo a disciplina de program

Mateus Faustino 1 Nov 16, 2021