minichess source realm
Package minichess is an on-chain chess game (standard 8x8 board).
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.
2
12
func AcceptChallenge
crossing ActionAcceptChallenge takes the open seat in a waiting two-player game.
func AcceptDraw
crossing ActionAcceptDraw accepts your opponent's pending draw offer.
func CancelChallenge
crossing ActionCancelChallenge withdraws a challenge nobody has accepted yet.
func Challenge
crossing ActionChallenge 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
ActionGameFEN returns the current position of a game in FEN notation.
func GameStatus
ActionGameStatus returns a one-line status for a game.
func LegalMoves
ActionLegalMoves returns the legal moves of a game as a space-separated list.
func Move
crossing ActionMove 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 ActionNewSoloGame 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 ActionOfferDraw offers a draw in a two-player game. If your opponent has already offered one, this accepts it.
func Render
func Resign
crossing ActionResign ends the game as a loss for the caller.
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}Game is one game of minichess.
type Mode
identMode is how a game is played.
type State
identState is a game's lifecycle stage.