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_v2 source realm

package connect4\_v2 is a staked Connect 4 game. A creator posts an offer with a ugnot stake; anyone (or a named oppo...

Overview

package connect4_v2 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 commit-reveal: the creator offers with sha256(passphrase) and must Reveal the passphrase within 90s of Accept, or forfeit. Randomness computed in Accept could be re-rolled by an acceptor who bundles [Accept, Play] in one atomic tx and lets it revert.

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: an unrevealed game is won by the acceptor, a game whose first mover never moved is void and both stakes are refunded, otherwise the player who ran out of time forfeits.

Constants 1

Functions 13

func Accept

crossing Action
1func Accept(cur realm, id int)
source

Accept joins an open offer by sending exactly its stake. The creator then has 90s to Reveal, which picks the first mover.

func ActiveJSON

Action
1func ActiveJSON(offset, limit int) string
source

ActiveJSON returns {"now":<unix>,"games":[...]}: Open and Playing games in id order, skipping offset and returning at most limit (clamped to 1-100).

func Cancel

crossing Action
1func Cancel(cur realm, id int)
source

Cancel withdraws an open offer and refunds the creator. The creator may cancel at any time; anyone may once the offer has expired.

func ClaimTimeout

crossing Action
1func ClaimTimeout(cur realm, id int)
source

ClaimTimeout settles a game whose move clock ran out. Anyone may call it.

func GameJSON

Action
1func GameJSON(id int) string
source

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

func Offer

crossing Action
1func Offer(cur realm, opponent address, validFor int, commitment string) int
source

Offer posts a game open for validFor minutes. The stake is the ugnot sent with the call. A non-empty opponent makes the offer private. commitment is the lowercase hex sha256 of a secret passphrase, revealed after Accept.

func Play

crossing Action
1func Play(cur realm, id, column int)
source

Play drops a piece in column (1-7).

func Render

1func Render(path string) string
source

Render serves "" (lobby and leaderboards), "new" (offer form) and "game/<id>" (one game with every action its state allows). Everything written comes from realm state or from query values that have been validated and re-formatted; raw path input is never echoed.

func Resign

crossing Action
1func Resign(cur realm, id int)
source

Resign concedes a game in progress.

func Reveal

crossing Action
1func Reveal(cur realm, id int, passphrase string)
source

Reveal discloses the creator's passphrase, which picks the first mover. It must come within 90s of Accept.

func SetFee

crossing Action
1func SetFee(cur realm, amount int64)
source

SetFee changes the flat house fee, in ugnot, for new offers. Games already offered keep the fee they were created with.

Types 3

type Game

struct
 1type Game struct {
 2	ID        int
 3	Creator   address
 4	Opponent  address // optional; if set, only this address may accept
 5	Acceptor  address
 6	Stake     int64 // ugnot, per player
 7	Fee       int64 // ugnot house fee, fixed at offer time
 8	ExpiresAt time.Time
 9	// Commitment is the lowercase hex sha256 of the creator's passphrase.
10	Commitment string
11
12	Board    board
13	Turn     byte // 0 = awaiting Reveal, 1 = creator, 2 = acceptor
14	Moves    int
15	LastCol  int // column and row of the last piece dropped, valid if Moves > 0
16	LastRow  int
17	LastMove time.Time
18	Status   Status
19	Winner   address
20}
source

type Stats

struct
1type Stats struct {
2	Games, Wins, Draws int
3	GnotWon            int64 // total ugnot received from wins
4}
source

type Status

ident
1type Status int
source

Methods on Status

func String

method on Status
1func (s Status) String() string
source

Imports 14

Source Files 10