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
Code for an arcade pop-a-shot style basketball game on Raspberry Pi

Basketball-Game Code for an arcade pop-a-shot style basketball game on Raspberry Pi, made over the course of winter break 2022. How To Run: Running th

Seth Reis 1 Jan 21, 2022
BitBot - A simple shooter game

BitBot BitBot - A simple shooter game This project can be discontinued anytime I want, as it is not a "MAJOR" project for me. Which Game Engine does i

whmsft 1 Jan 04, 2022
Simple python 3D vector3 math library wrapping some types from GLM library using pybind11.

vmath Simple python 3D vector3 math library wrapping some types from GLM library using pybind11. Description Both pure python version and C++ version

6 Aug 02, 2022
Inject custom C++ code into GameMaker Studio 2 YYC builds

YYC Boost Inject custom C++ code into GameMaker Studio 2 YYC builds! WARNING: This tool is currently in an early stage of development and it is not gu

Patrik Kraif 7 Dec 30, 2022
Input-based tic tac toe game made in only python.

Tic Tac Toe Tic Tac Toe is a game in which two players seek in alternate turns to complete a row, a column, or a diagonal with either three O's or thr

Ayza 5 Jun 26, 2022
PyChess - a chess client for Linux/Windows

PyChess - a free chess client for Linux/Windows The mission of PyChess is to create a free, pleasant, PyGObject based chess game for the Linux desktop

559 Dec 28, 2022
For educational purposes, a simple script that assists in solving the word game Wordle.

WordleSolver For educational purposes, a simple script that assists in solving the word game Wordle. Instructions Pick your first word from the sugges

Christian De Leon 2 Mar 25, 2022
Sukoku-solver Python About Sudoku is one of the most popular puzzle games of all time

Sukoku-solver Python About Sudoku is one of the most popular puzzle games of all time. As a logic puzzle, Sudoku is also an excellent brain game. Bein

Harshith VH 1 Nov 20, 2021
DouZero_For_HLDDZ_FullAuto: 将DouZero用于欢乐斗地主自动化

DouZero_For_HLDDZ_FullAuto: 将DouZero用于欢乐斗地主自动化 本项目基于DouZero 和 DouZero_For_Happy_DouDiZhu 环境配置请移步项目DouZero 模型默认为ADP,更换模型请修改main.py中的模型路径 运行main.py即可 在原

322 Dec 25, 2022
Tic Tac Toe Game build with Python

Tic Tac Toe Game Description two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing th

Kemal Kochekov 2 Jan 21, 2022
Frets on Fire X: a fork of Frets on Fire with many added features and capabilities

Frets on Fire X - FoFiX This is Frets on Fire X, a highly customizable rhythm game supporting many modes of guitar, bass, drum, and vocal gameplay for

FoFiX 377 Jan 02, 2023
A Python based program that displays Your Minecraft Server's Status Infos.

Minecraft-server-Status This (very) small python script allows you to view any Minecraft server's status Information Usage Download the file, install

Jonas_Jones 2 Oct 05, 2022
Dontdie-minecraft - A python program that causes your computer to bluescreen whenever you die in Minecraft

Don't Die - A Python Program A python program that causes your computer to blues

3 Apr 19, 2022
This is a simple rock paper scissor game created with python.

This is a simple rock paper scissor game created with python.

Fayas Noushad 3 Feb 04, 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
To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

Vaibhaw 7 Oct 13, 2022
Easy and fun game to play a bit. Written in python

NumGuesser Easy and fun game to play a bit. Written in python

Lodi#0001 4 May 22, 2022
Python Interactive Mini Games

Python Interactive Mini Games Mini projects from Coursera's An Introduction to I

Ashish Choudhary 1 Jan 16, 2022
Chess-commandline - Chess in the Command Line using the Chess Module Can detect Checkmates

chess-commandline Chess in the Command Line using the Chess Module Can detect Ch

Harry Hopkinson 1 Jan 10, 2022
2DMC is an abrrieviation for 2 Dimensional Minecraft.

2DMC 2DMC is an abrrieviation for 2 Dimensional Minecraft. This idea is originally created and implemented by Griffpatch on Scratch. This is a persona

DaNub 5 Nov 06, 2022