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
ReplitTD - Replit Tower Defense Game

IMPORTANT: I mean no offense at all in this game, this is only based off of cycl

kokomi simp :3 3 Jun 25, 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
Magic: The Gathering Arena draft tool that utilizes 17Lands data

MTGA_Draft_17Lands Magic: The Gathering Arena draft tool that utilizes 17Lands data. Steps for Windows Step 1: Download and unzip the MTGA_Draft_17Lan

41 Dec 31, 2022
A very bad wordle solver to help me solve the daily wordle

Wordle Solver A very bad wordle solver to help me solve the daily wordle on https://www.powerlanguage.co.uk/wordle/ TODO list take into account letter

Logan Anderson 4 Feb 03, 2022
A small script to help me solve Wordle because I'm that lazy

Wordle Solver A small script to help me solve Wordle because I'm that lazy. Warning: I didn't write this to be efficient nor elegant at all, so you'll

K4YT3X 3 Feb 11, 2022
Jogo Flappy Bird com phyton e phygame

Flappy-Bird Tecnologias usadas Requisitos para inicializar o jogo: Python faça o download em: https://www.python.org/ Pygame faça o download em: https

João Guilherme 1 Dec 06, 2021
Chess Game using Python

Chess Game is a single-player game where the objective is same as the original chess game. You just need to place your chess piece in a correct position. The purpose of the system is to provide some

Yogesh Selvarajan 1 Aug 15, 2022
Follow the numbers - A simple game where the player should follow the numbers and connect the dots

follow_the_numbers This is a simple game where the player should follow the numb

Sammy Mishinev 3 Nov 22, 2022
Ladder network is a deep learning algorithm that combines supervised and unsupervised learning

This repository contains source code for the experiments in a paper titled Semi-Supervised Learning with Ladder Networks by A Rasmus, H Valpola, M Hon

Curious AI 505 Nov 15, 2022
Quantum version of the game Tic Tac Toe.

QTicTacToe Quantum version of the game Tic Tac Toe. This game was inspired by the game at this site. Installation The game requires the qiskit python

1 Jan 05, 2022
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

Pramod Kumar 3 Feb 09, 2022
Chess game for 2 players with UI

2-D Chess for 2 players Overview This is a simple 2D Chess game for 2 players using pygame library. Requirements To be able to run this game, you must

7 Apr 06, 2022
This is the card game like HearthStone and Magic

Territory War How to use it use pip3 to install django and channels: pip3 install Django pip3 install channels go to CardGame/first/consumers.py and g

Caesar 3 Oct 24, 2022
A Tetris Game for programming education

Tetris Game プログラミング学習を目的とした、ブロックを操作してスコアを競うゲームです。 FAQはこちら。 tutorialはこちら。 実行環境準備 Mac環境 Finder→Application→Utility→Terminalから、ターミナルを起動して以下コマンドを実行する。 # i

11 Dec 01, 2022
用于 blivechat 的图形界面

blivechat GUI 用于 blivechat 的图形界面。 有朋友在搞 Vtuber,像 blivechat 类似的项目能通过自定义 CSS 的方式在 OBS 上添加一个非常好看的聊天栏。但是想要在桌面端看到弹幕的话得要再开一个浏览器页面,十分不方便。就想写一个背景透明的浮窗浏览器。 挺喜欢

Silence 11 Dec 29, 2022
Visualizing and learning from games on chess.com

Better Your Chess What for? This project aims to help you learn from all the chess games you've played online, starting with a simple way to download

Luc d'Hauthuille 0 Apr 17, 2022
A rhythm-based game that automatically generates obstacles based on a song's features.

DISCLAIMER: This is my first coding project, created in December 2019. The game may not be optimized, and looking back on it, there are a lot of chang

Kenneth Huang 1 Dec 27, 2021
WordleHelper suggests words to help players better enjoy the hit game Wordle

WordleHelper Introduction WordleHelper suggests words to help players better enjoy the hit game Wordle. Both the general mode and the hard mode are su

Shao-Yu, Chu 5 Jun 02, 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
A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

Amos 3 Aug 29, 2021