Game

Game

Git Source

Inherits: Initializable, IGame

A single-player game contract where the player guesses card numbers. The server sets hashed numbers inside the contract, and the player can guess each card.

The contract uses a commit-reveal mechanism to hide the deck of cards initially

State Variables

MAXIMUM_GUESS_NUMBER

uint256 public constant MAXIMUM_GUESS_NUMBER = 8191;

cardsRevealed

Number of revealed cards

uint256 public cardsRevealed = 0;

cardsFreeRevealedRequests

Number of free cards reveals

uint256 public cardsFreeRevealedRequests = 0;

revealedCardNumbersCount

Number of reveals per rank

usdc

Address of the USDC token

vault

Address of the Vault token

player

Address of the player

revealer

Address of the Revealer contract

gameId

Game ID number

gameDuration

Duration of the game

gameCreatedAt

Game created timestamp

claimableAfter

Duration at which the revealer can reveal the cards

maxFreeReveals

Maximum amount of free reveals

Functions

onlyPlayer

Modifier to restrict access to player only

onlyRevealer

Modifier to restrict access to revealer only

notExpired

Modifier to restrict the player from playing after the gameDuration passes

constructor

Sets contract and player addresses

Parameters

Name
Type
Description

_usdc

IERC20

The address of the USDC token

_vault

Vault

The Vault contract address

_revealer

address

The game server that submits the random hash of cards and reveals the guessed cards

_player

address

The player that created the game using the GameFactory contract

_gameId

uint256

The ID of the game stored in the GameFactory contract

_gameDuration

uint256

The duration of the game. After that, the game is unplayable

_claimableAfter

uint256

The duration during which the user can claim their win if the revealer does not reveal

_maxFreeReveals

uint256

The maximum number of free reveals a player can request

initialize

Initializes the contract by committing the deck of cards

Emits GameInitialized event

Parameters

Name
Type
Description

_hashedDeck

bytes32[52]

The hash of a random deck of cards

guessCard

Stores the player's guess

Emits CardGuessed event

Parameters

Name
Type
Description

_index

uint256

Index of the card

_betAmount

uint256

The amount of USDC that the player bets

_guessedNumbers

uint256

Numbers that the player guessed

requestFreeRevealCard

Requests a secret card to be revealed for free

Emits RevealFreeCardRequested event

Parameters

Name
Type
Description

_index

uint256

Index of the card

getGuessRate

Returns the rate of betting with selected numbers without considering the house edge

Parameters

Name
Type
Description

_numbers

uint256

Selected numbers out of 13

Returns

Name
Type
Description

rate

UD60x18

The pure rate without considering the house edge

claimWin

Claims the player as the winner for a specific card if the revealer does not reveal the card after the claimableAfter duration

Emits CardClaimed event

Parameters

Name
Type
Description

_index

uint256

Index of the card

revealCard

Reveals a card and decides the winner and transfers rewards to the player

Emits CardRevealed event

Parameters

Name
Type
Description

_index

uint256

Index of the card

_number

uint256

The revealed number of the card

_salt

bytes32

The salt that was used to hash the card

isFreeReveal

bool

cards

Get cards by their index from 0 to 51

Parameters

Name
Type
Description

_index

uint256

Index of the card

Last updated