Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

connect4 package

Overview

Package connect4 is a staked Connect 4 game. A creator posts an offer with a ugnot stake; anyone (or a named opponent) accepts with the same stake; the winner takes the pot minus a flat house fee.

The first mover is picked by a two-sided commit-reveal. The creator offers with sha256(passphrase), the acceptor accepts with sha256(seed). Then the creator reveals the passphrase (Reveal) and the acceptor the seed (RevealSeed), each within 90s, and the first mover is drawn from both. When a player commits, the other side's secret is still hidden, so neither can grind for an outcome, and once its secret is revealed nobody can change it; the only way out is to not reveal, which forfeits. Watching a pending Accept tells the creator nothing either, so it cannot cancel unfavourable games. Each address may use a commitment once: a reused secret is already public.

Calls signed by an account session key (Quick play) may only Play, Reveal, RevealSeed, ClaimTimeout and Cancel: a stolen session key must not resign games, move stakes or act as the owner.

Every move has a 90s clock measured in block time. Nothing on-chain fires by itself, so an expired clock is settled by anyone calling ClaimTimeout: whoever did not reveal in time forfeits, a game whose first mover never moved is void and both stakes are refunded, otherwise the player who ran out of time forfeits.

Function

GameJSON

func GameJSON(id int) string

GameJSON returns {"now":<unix>,"game":<game>|null}. It is a read-only accessor for clients querying over vm/qeval; now is the block time.

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/samcrew/connect4.GameJSON()"

Result