Skip to content Search Apps Documentation Source Content 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.

minichess source realm

Package minichess is an on-chain chess game (standard 8x8 board).

Overview

Package minichess is an on-chain chess game (standard 8x8 board).

Two ways to play:

  • Solo: NewSoloGame starts a game against the built-in bot. The bot replies inside the same transaction as your move.
  • Two players: Challenge creates a game (open to anyone, or for one invited address); AcceptChallenge takes the empty seat.

Moves use coordinate notation: "e2e4", "g1f3", castling as the king's move ("e1g1"), en passant as the pawn's move to the target square, and promotion as "e7e8" (queen) or "e7e8n" (under-promotion). Visit the realm in gnoweb to see the board and click legal moves.

Constants 2

Functions 12

func AcceptChallenge

crossing Action
1func AcceptChallenge(cur realm, gameID int)
source

AcceptChallenge takes the open seat in a waiting two-player game.

func AcceptDraw

crossing Action
1func AcceptDraw(cur realm, gameID int)
source

AcceptDraw accepts your opponent's pending draw offer.

func CancelChallenge

crossing Action
1func CancelChallenge(cur realm, gameID int)
source

CancelChallenge withdraws a challenge nobody has accepted yet.

func Challenge

crossing Action
1func Challenge(cur realm, opponent string, color string) int
source

Challenge creates a two-player game. opponent may be empty (anyone can accept) or a g1... address (only they can accept). color is the challenger's side: "white", "black" or "random".

func GameFEN

Action
1func GameFEN(gameID int) string
source

GameFEN returns the current position of a game in FEN notation.

func LegalMoves

Action
1func LegalMoves(gameID int) string
source

LegalMoves returns the legal moves of a game as a space-separated list.

func Move

crossing Action
1func Move(cur realm, gameID int, move string) string
source

Move plays a move, e.g. "e2e4", "e1g1" (castling) or "e7e8q". In a solo game the bot answers in the same transaction. Returns a short summary.

func NewSoloGame

crossing Action
1func NewSoloGame(cur realm, color string, level int) int
source

NewSoloGame starts a game against the bot. color: "white", "black" or "random". level: 1 (easy) to 3 (hard). If you play black, the bot makes the first move immediately.

func OfferDraw

crossing Action
1func OfferDraw(cur realm, gameID int)
source

OfferDraw offers a draw in a two-player game. If your opponent has already offered one, this accepts it.

func Render

1func Render(path string) string
source

Render serves the gnoweb pages:

Example
1""               home: start a game, open challenges, recent games
2"game/<id>"      a board with clickable legal moves
3"player/<addr>"  a player's games
4"rules"          how to enter moves and the draw rules

func Resign

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

Resign ends the game as a loss for the caller.

Types 3

type Game

struct
 1type Game struct {
 2	ID        int
 3	Mode      Mode
 4	White     address // empty: the bot (solo) or an open seat (waiting)
 5	Black     address
 6	Creator   address
 7	Invitee   address // two-player challenge target; empty = open to all
 8	BotLevel  int     // solo only
 9	Pos       mc.Position
10	Moves     []string // coordinate notation, in order
11	History   []string // board keys since the last capture or pawn move
12	Hashes    []uint64 // position hashes since the last capture or pawn move (for the bot)
13	State     State
14	Reason    string  // how the game ended
15	DrawOffer address // player with a pending draw offer
16	CreatedAt int64   // block height
17	UpdatedAt int64
18}
source

Game is one game of minichess.

Methods on Game

func IsPlayer

method on Game
1func (g *Game) IsPlayer(a address) bool
source

IsPlayer reports whether a is one of the game's human players.

type Mode

ident
1type Mode int
source

Mode is how a game is played.

Methods on Mode

func String

method on Mode
1func (m Mode) String() string
source

type State

ident
1type State int
source

State is a game's lifecycle stage.

Methods on State

func Finished

method on State
1func (s State) Finished() bool
source

Finished reports whether the game is over.

func String

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

Dependencies

Source Files 4