core

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PieceNone = iota
	PieceQueen
	PieceKing
	PieceBishop
	PieceKnight
	PieceRook
	PiecePawn
)
View Source
const (
	ColorBlack = iota
	ColorWhite
)

Variables

This section is empty.

Functions

func Perft

func Perft(g Game, depth int) int

Perft counts the number of leaf nodes in the move tree at the given depth. It is the standard method for validating move generation correctness in chess engines. https://www.chessprogramming.org/Perft

Types

type Action

type Action struct {
	FromPiece          Piece
	ToXY               XY
	IsCapture          bool
	IsResign           bool
	IsDraw             bool
	IsPromotion        bool
	IsEnPassantCapture bool
	IsCastle           bool
	IsKingsideCastle   bool
	IsQueensideCastle  bool
	PromotionPieceType PieceType
	CapturedPiece      Piece
}

func (Action) DebugString

func (a Action) DebugString() string

func (Action) ICCF

func (a Action) ICCF() string

func (Action) String

func (a Action) String() string

type Board

type Board struct {
	Board                   []string
	CanWhiteKingsideCastle  bool
	CanWhiteQueensideCastle bool
	CanBlackKingsideCastle  bool
	CanBlackQueensideCastle bool
	HalfMoveClock           int
	FullMoveNumber          int
	EnPassantTargetSquare   string // in Algebraic notation, or empty string
	Turn                    string // "Black" or "White"
}

type Color

type Color = color

Color is the exported name for the color of a player or piece (e.g. core.ColorWhite).

type Game

type Game struct {
	CanWhiteCastle          bool
	CanWhiteKingsideCastle  bool
	CanWhiteQueensideCastle bool
	CanBlackCastle          bool
	CanBlackKingsideCastle  bool
	CanBlackQueensideCastle bool
	HalfMoveClock           int
	FullMoveNumber          int
	IsLastMoveEnPassant     bool
	EnPassantTargetSquare   XY
	MoveNumber              int

	IsCheck         bool
	IsDoubleCheck   bool
	IsDiscoverCheck bool
	IsCheckmate     bool
	IsStalemate     bool
	IsDraw          bool
	CanClaimDraw    bool
	IsGameOver      bool
	GameOverWinner  color
	InCheckBy       []Piece
	Actions         []Action
	// contains filtered or unexported fields
}

func NewDefaultGame

func NewDefaultGame() Game

func NewGameFromBoard

func NewGameFromBoard(b Board) (Game, error)

func NewGameFromFEN

func NewGameFromFEN(s string) (Game, error)

func (Game) Clone

func (g Game) Clone() Game

func (Game) DoAction

func (g Game) DoAction(a Action) Game

doAction executes the given action on the given game. It assumes that the game is in a state where this action can be executed. It assumes that the action is fully-correctly created and it's valid. It fully updates the game context. This is an expensive method (due to having to check for check and checkmate), so use only if needed.

func (Game) King

func (g Game) King(c color) Piece

King returns the king of the given color.

func (Game) PieceAt

func (g Game) PieceAt(xy XY) Piece

PieceAt returns the piece at the given square, or the zero Piece (PieceNone) if empty.

func (Game) Pieces

func (g Game) Pieces(c color) []Piece

Pieces returns all pieces of the given color.

func (Game) PositionHistory

func (g Game) PositionHistory() []uint64

PositionHistory returns the Zobrist hashes of the positions reached since the last irreversible move, most recent last. It can be persisted and restored via WithPositionHistory to detect repetitions across stateless API calls.

func (Game) String

func (g Game) String() string

func (Game) ToBoard

func (g Game) ToBoard() Board

func (Game) ToFEN

func (g Game) ToFEN() string

func (Game) Turn

func (g Game) Turn() color

func (Game) WithPositionHistory

func (g Game) WithPositionHistory(history []uint64) Game

WithPositionHistory returns a copy of the game whose position history is the given hashes (as returned by PositionHistory of a previous game), and with draw flags recalculated accordingly. The current position is appended if it isn't already the last entry, so both "history up to and including this position" and "history of prior positions" are accepted.

type GameStep

type GameStep struct {
	StepString      string
	StepComment     string
	StepAction      Action
	StepGame        Game
	StepPreMoveGame Game
}

func (GameStep) Clone

func (s GameStep) Clone() GameStep

type Piece

type Piece struct {
	PieceType PieceType
	Owner     color
	XY        XY
}

func (Piece) String

func (p Piece) String() string

type PieceType

type PieceType int

func (PieceType) String

func (t PieceType) String() string

func (PieceType) ToAlgebraic

func (t PieceType) ToAlgebraic() string

func (PieceType) ToColorFigurine

func (t PieceType) ToColorFigurine(c color) string

func (PieceType) ToDescriptive

func (t PieceType) ToDescriptive(useKt bool) string

func (PieceType) ToFigurine

func (t PieceType) ToFigurine() string

func (PieceType) ToICCF

func (t PieceType) ToICCF() string

func (PieceType) ToSmith

func (t PieceType) ToSmith() string

type XY

type XY struct {
	X, Y int
}

func (XY) ToAlgebraic

func (c XY) ToAlgebraic() string

func (XY) ToDescriptive

func (c XY) ToDescriptive(turn color, useKt ...bool) string

func (XY) ToICCF

func (c XY) ToICCF() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL