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
uint256[13] public revealedCardNumbersCount;usdc
Address of the USDC token
IERC20 public immutable usdc;vault
Address of the Vault token
Vault public immutable vault;player
Address of the player
address public immutable player;revealer
Address of the Revealer contract
address public immutable revealer;gameId
Game ID number
uint256 public immutable gameId;gameDuration
Duration of the game
uint256 public immutable gameDuration;gameCreatedAt
Game created timestamp
uint256 public immutable gameCreatedAt;claimableAfter
Duration at which the revealer can reveal the cards
uint256 public immutable claimableAfter;maxFreeReveals
Maximum amount of free reveals
uint256 public immutable maxFreeReveals;Functions
onlyPlayer
Modifier to restrict access to player only
modifier onlyPlayer();onlyRevealer
Modifier to restrict access to revealer only
modifier onlyRevealer();notExpired
Modifier to restrict the player from playing after the gameDuration passes
modifier notExpired();constructor
Sets contract and player addresses
constructor(
    IERC20 _usdc,
    Vault _vault,
    address _revealer,
    address _player,
    uint256 _gameId,
    uint256 _gameDuration,
    uint256 _claimableAfter,
    uint256 _maxFreeReveals
);Parameters
_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
function initialize(bytes32[52] calldata _hashedDeck) external onlyNotInitialized onlyRevealer;Parameters
_hashedDeck
bytes32[52]
The hash of a random deck of cards
guessCard
Stores the player's guess
Emits CardGuessed event
function guessCard(uint256 _index, uint256 _betAmount, uint256 _guessedNumbers)
    external
    onlyPlayer
    onlyInitialized
    notExpired;Parameters
_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
function requestFreeRevealCard(uint256 _index) external onlyPlayer onlyInitialized notExpired;Parameters
_index
uint256
Index of the card
getGuessRate
Returns the rate of betting with selected numbers without considering the house edge
function getGuessRate(uint256 _numbers) public view returns (UD60x18 rate);Parameters
_numbers
uint256
Selected numbers out of 13
Returns
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
function claimWin(uint256 _index) external onlyPlayer onlyInitialized;Parameters
_index
uint256
Index of the card
revealCard
Reveals a card and decides the winner and transfers rewards to the player
Emits CardRevealed event
function revealCard(uint256 _index, uint256 _number, bytes32 _salt, bool isFreeReveal)
    external
    onlyRevealer
    onlyInitialized;Parameters
_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
function cards(uint256 _index) public view returns (Card memory);Parameters
_index
uint256
Index of the card
Last updated