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 state

Back to all declarations

N

untyped bigint

Value

(4 <untyped> bigint)

DIR_UP

untyped bigint

Value

(0 <untyped> bigint)

DIR_RIGHT

untyped bigint

Value

(1 <untyped> bigint)

DIR_DOWN

untyped bigint

Value

(2 <untyped> bigint)

DIR_LEFT

untyped bigint

Value

(3 <untyped> bigint)

Board

type

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

Value

v0.Board

NewBoard

func() v0.Board

NewBoard returns a fresh board with the two starting tiles.

Open
OID
0b3298…0ebc:3
NewBoard details

Inspect func

NewBoardSeeded

func(seed int) v0.Board

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

Open
OID
0b3298…0ebc:5
NewBoardSeeded details

Inspect func

slideRowLeft

func(row [4]int) (out [4]int, gained int)

slideRowLeft collapses a row to the left, merging equal neighbours once. Returns the new row and the points added by the merges.

Open
OID
0b3298…0ebc:6
slideRowLeft details

Inspect func

applyDir

func(b [4][4]int, dir int) (nb [4][4]int, gained int, moved bool)

applyDir runs a full-board move. It returns the new board, the gained score and whether the board changed at all.

Open
OID
0b3298…0ebc:7
applyDir details

Inspect func

HasMove

func(b [4][4]int) bool

HasMove reports whether any move is still possible.

Open
OID
0b3298…0ebc:8
HasMove details

Inspect func

lcg

func(seed int) int

lcg advances a deterministic PRNG from a seed; value in \[0,1024).

Open
OID
0b3298…0ebc:9
lcg details

Inspect func

Itoa

func(x int) string

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

Open
OID
0b3298…0ebc:10
Itoa details

Inspect func

realmPath

untyped string

realmPath is the gnoweb path of this realm, used for in-page links.

Value

"/r/g15crxnxd79syggtha6ymfhy8m8a4ytqel58cwkg/tavern2048/v0"

MaxPlayMoves

untyped bigint

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

Value

(64 <untyped> bigint)

TopN

untyped bigint

TopN is how many players the leaderboard shows.

Value

(10 <untyped> bigint)

Game

type

Game is one player's current game.

Value

v0.Game

games

*v0.Tree

// player address -> \*Game (current game)

Open
OID
0b3298…0ebc:12
games details

Inspect pointer

best

*v0.Tree

// player address -> int (best score ever)

Open
OID
0b3298…0ebc:15
best details

Inspect pointer

totalGames

int

Value

1

totalMoves

int

Value

35

NewGame

func() string

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

Open
OID
0b3298…0ebc:19
NewGame details

Inspect func

Move

func(dir string) string

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.

Open
OID
0b3298…0ebc:21
Move details

Inspect func

Play

func(moves string) string

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.

Open
OID
0b3298…0ebc:22
Play details

Inspect func

ScoreOf

func(player .uverse.address) int

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

Open
OID
0b3298…0ebc:23
ScoreOf details

Inspect func

BestOf

func(player .uverse.address) int

BestOf returns the best score a player ever reached.

Open
OID
0b3298…0ebc:24
BestOf details

Inspect func

mustGame

func(player string) *v0.Game
Open
OID
0b3298…0ebc:25
mustGame details

Inspect func

step

func(player string, g *v0.Game, d int) (bool, string)

step applies one direction and records score, best and events.

Open
OID
0b3298…0ebc:26
step details

Inspect func

BestOfKey

func(player string) int

BestOfKey is BestOf for a raw address string.

Open
OID
0b3298…0ebc:27
BestOfKey details

Inspect func

parseDir

func(s string) (int, bool)
Open
OID
0b3298…0ebc:28
parseDir details

Inspect func

addrSeed

func(a string) int

addrSeed folds an address into a small positive salt.

Open
OID
0b3298…0ebc:30
addrSeed details

Inspect func

shortAddr

func(a string) string
Open
OID
0b3298…0ebc:32
shortAddr details

Inspect func

Render

func(path string) string

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

Open
OID
0b3298…0ebc:33
Render details

Inspect func

entry

type

Value

v0.entry

renderLeaderboard

func() string
Open
OID
0b3298…0ebc:35
renderLeaderboard details

Inspect func

renderPlayer

func(player string) string
Open
OID
0b3298…0ebc:36
renderPlayer details

Inspect func

tileColors

func(v int) (bg string, fg string)
Open
OID
0b3298…0ebc:37
tileColors details

Inspect func

boardSVG

func(b v0.Board) string

boardSVG draws the board as an inline SVG image (data URI) for gnoweb.

Open
OID
0b3298…0ebc:38
boardSVG details

Inspect func
N : untyped bigint =(4 <untyped> bigint)
DIR_UP : untyped bigint =(0 <untyped> bigint)
DIR_RIGHT : untyped bigint =(1 <untyped> bigint)
DIR_DOWN : untyped bigint =(2 <untyped> bigint)
DIR_LEFT : untyped bigint =(3 <untyped> bigint)
Board : type =v0.Board
NewBoard : func() v0.Board Inspect
NewBoardSeeded : func(seed int) v0.Board Inspect
slideRowLeft : func(row [4]int) (out [4]int, gained int) Inspect
applyDir : func(b [4][4]int, dir int) (nb [4][4]int, gained int, moved bool) Inspect
HasMove : func(b [4][4]int) bool Inspect
lcg : func(seed int) int Inspect
Itoa : func(x int) string Inspect
realmPath : untyped string ="/r/g15crxnxd79syggtha6ymfhy8m8a4ytqel58cwkg/tavern2048/v0"
MaxPlayMoves : untyped bigint =(64 <untyped> bigint)
TopN : untyped bigint =(10 <untyped> bigint)
Game : type =v0.Game
games : *v0.Tree Inspect
best : *v0.Tree Inspect
totalGames : int =1
totalMoves : int =35
NewGame : func() string Inspect
Move : func(dir string) string Inspect
Play : func(moves string) string Inspect
ScoreOf : func(player .uverse.address) int Inspect
BestOf : func(player .uverse.address) int Inspect
mustGame : func(player string) *v0.Game Inspect
step : func(player string, g *v0.Game, d int) (bool, string) Inspect
BestOfKey : func(player string) int Inspect
parseDir : func(s string) (int, bool) Inspect
dirName : func(d int) string Inspect
addrSeed : func(a string) int Inspect
maxTile : func(b v0.Board) int Inspect
shortAddr : func(a string) string Inspect
Render : func(path string) string Inspect
renderHome : func() string Inspect
entry : type =v0.entry
renderLeaderboard : func() string Inspect
renderPlayer : func(player string) string Inspect
tileColors : func(v int) (bg string, fg string) Inspect
boardSVG : func(b v0.Board) string Inspect