Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source realm

Constants 7

const MaxPlayMoves

1const MaxPlayMoves = 64
source

MaxPlayMoves caps how many moves a single Play transaction may apply.

const TopN

1const TopN = 10
source

TopN is how many players the leaderboard shows.

Functions 11

func BestOf

Action
1func BestOf(player address) int
source

BestOf returns the best score a player ever reached.

func HasMove

Action
1func HasMove(b [N][N]int) bool
source

HasMove reports whether any move is still possible.

func Itoa

Action
1func Itoa(x int) string
source

Itoa is a dependency-free int->string for realm Render.

func Move

crossing Action
1func Move(cur realm, dir string) string
source

Move slides the signer's board once: dir is up, down, left or right (or u, d, l, r). A move that changes nothing is not counted.

func NewGame

crossing Action
1func NewGame(cur realm) string
source

NewGame starts a fresh board for the signer, replacing any current game. The best score ever reached is kept for the leaderboard.

func Play

crossing Action
1func Play(cur realm, moves string) string
source

Play applies a sequence of moves in a single transaction, e.g. "lldrul" (u=up, d=down, l=left, r=right; spaces and commas are ignored). It stops early when the game is over. At most MaxPlayMoves moves per call.

func Render

1func Render(path string) string
source

Render serves the tavern home (path "") or a player's board (path = g1...).

func ScoreOf

Action
1func ScoreOf(player address) int
source

ScoreOf returns the current score of a player (0 if no game).

func NewBoard

Action
1func NewBoard() Board
source

NewBoard returns a fresh board with the two starting tiles.

func NewBoardSeeded

Action
1func NewBoardSeeded(seed int) Board
source

NewBoardSeeded returns a fresh board whose two starting tiles are placed from seed, so every game starts differently but reproducibly.

Types 2

type Board

struct
1type Board struct {
2	Cells [N][N]int `json:"cells"`
3	Score int       `json:"score"`
4	Moves int       `json:"moves"`
5	Over  bool      `json:"over"`
6}
source

Board is one 4x4 game. Zero is an empty cell.

Methods on Board

func Move

method on Board
1func (b *Board) Move(dir int, spawnSeed int) (ok bool, msg string)
source

Move applies a direction (0=up,1=right,2=down,3=left) to the board, awards merge points and spawns one new tile from the block-height seed. spawnSeed makes the spawn reproducible: pass blockheight() on chain. Returns the updated board and a human-readable outcome.

type Game

struct
1type Game struct {
2	Board   Board
3	Seed    int   // per-player spawn salt, derived from the address
4	Started int64 // block height of NewGame
5	Updated int64 // block height of the last applied move
6}
source

Game is one player's current game.

Dependencies

Source Files 5