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.

You might also like...
Building a Mario-like, classic platformer game in Python using the PyGame Library

Building a Mario-like, classic platformer game in Python using the PyGame Library

Guess The Random Number - A sample Random Number Guessing Game Python Program
Guess The Random Number - A sample Random Number Guessing Game Python Program

Guess_The_Random_Number This repo contains a simple "Random Number Guessing Game

Client-Server design (guess the closest number to the average score game)

Multiplayer game (enter the number closest to the average) Design Client-Server design The client's side is responsible for sending numbers from the g

A classic alien shooting game.

Space-Invaders A classic alien shooting game. Description An open source game created by me and friends. How to play Install the latest python version

Wordle is a web-based word game. Players have six attempts to guess a five-letter word;

Wordle is a web-based word game. Players have six attempts to guess a five-letter word; feedback is given for each guess, in the form of colored tiles, indicating when letters match or occupy the correct position. This program helps solving wordle problems.

Blender Game Engine Game Type Templates Logic Bricks (and Python script) based Game Templates for Blender

Blender-Game-Engine-Templates Blender Game Engine Game Type Templates Logic Bric

A playable version of Chess – classic two-player, various AI levels, and the crazyhouse variant! Written in Python 3

A playable version of Chess – classic two-player, various AI levels, and the crazyhouse variant! Written in Python 3. Requires the installation of PIL/Pillow and Requests

A 16x16 clone of Minecraft Classic, written in Python with the Ursina Engine

VoxelCraft A 16x16 clone of Minecraft Classic, written in Python with the Ursina Engine Features:Trees, Water(But there's no gravity, so if you break

Practice the use of the random library to get the user guess the result.
Practice the use of the random library to get the user guess the result.

Guessing Game Practice the use of the random library to get the user guess the result. Additional description about the project and its features. Buil

Comments
  • ERROR: Could not find a version that satisfies the requirement pywin32

    ERROR: Could not find a version that satisfies the requirement pywin32

    pip install -r requirements.txt

    ERROR: Could not find a version that satisfies the requirement pywin32==302 (from -r requirements.txt (line 43)) (from versions: none) ERROR: No matching distribution found for pywin32==302 (from -r requirements.txt (line 43))

    Linux version 5.11.0-37-generic (buildd@lcy01-amd64-021) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 (Ubuntu 5.11.0-37.41~20.04.2-generic 5.11.22)

    processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz stepping : 3 microcode : 0x28 cpu MHz : 2252.362 cache size : 3072 KB

    opened by geraldneale 1
Owner
Kronus91
Kronus91
Guess number game with PyQt5

Guess-Number-Project Guess number game with PyQt5 you can choose a number in your mind and then computer will guess a nummber and you guide the comput

MohammadAli.HBA 1 Nov 11, 2021
Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
Software Design | Spring 2020 | Classic Arcade Game

Breakout Software Design Final Project, Spring 2020 Team members: Izumi, Lilo For our Interactive Visualization, we implemented the classic arcade gam

Lilo Heinrich 1 Jul 26, 2022
The Classic Fruit Collecting game made in python with pygame

FruitCollect A classic fruit Collecting game made with pygame Install pygame before running: "pip install pygame" Rules: Random fruits will drop from

Pranav Bobby 1 Dec 1, 2021
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

null 0 Jun 24, 2022
We tried to recreate this classic game using python physics libraries.

We tried to recreate this classic game using python physics libraries. The result is certainly hilarious but enjoyable. One of my very first physics application.

Delwys Glokpor 2 Dec 12, 2021
Lucky Balls is gambling game where user try to guess 6 numbers from 1 to 48 that computer has picked.

LUCKY BALLS Lucky Balls is gambling game where user try to guess 6 numbers from 1 to 48 that computer has picked. INSTRUCTIONS User input his bet, tha

rile037 2 Dec 28, 2021
Inflitator is a classic doom and wolfenstein3D like game made in Python, using the famous PYGAME module.

INFLITATOR Raycaster INFLITATOR is a raycaster made in Python3 with Pygame. It is a game built on top of a simple engine of the same name. An example

Zanvok Corporation 1 Jan 7, 2022
Python codes for the classic Hang Man game

Python codes for the classic Hang Man game. The user will be assigned a random word to guess, one character at a time. If the user gets everything right, the program says Well Done!, but if the user can't get the word right in 6 tries, the program says Game Over!

p.katekomol 1 Jan 25, 2022
A "guess the number" game on a GUI interface using Tkinter library🙂

A "guess the number" game on a GUI interface using Tkinter library??

Arsalan 2 Feb 1, 2022