Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

chess source pure

Functions 20

func Abs

1func Abs(x int) int
source

Abs returns the absolute value of an integer

func GetPieceEmoji

1func GetPieceEmoji(p string) string
source

GetPieceEmoji converts a piece character string to a unicode chess emoji

func HasAnyLegalMoves

1func HasAnyLegalMoves(board Board, isWhite bool, rights CastlingRights, enPassantCol int) bool
source

HasAnyLegalMoves checks if the current player has at least one legal move

func IsBlackPiece

1func IsBlackPiece(p string) bool
source

IsBlackPiece returns true if the piece belongs to Black

func IsKingInCheck

1func IsKingInCheck(board Board, isWhite bool) bool
source

IsKingInCheck checks if the king of the specified color is under attack

func IsOpponentOrEmpty

1func IsOpponentOrEmpty(board Board, toRow, toCol int, isWhite bool) bool
source

IsOpponentOrEmpty checks if destination square is empty or has an opponent piece

func IsPathClear

1func IsPathClear(board Board, fromRow, fromCol, toRow, toCol int) bool
source

IsPathClear checks if all squares between from and to (exclusive) are empty

func IsValidBishopMove

1func IsValidBishopMove(board Board, fromRow, fromCol, toRow, toCol int) bool
source

IsValidBishopMove validates bishop diagonal moves

func IsValidKingMove

1func IsValidKingMove(board Board, fromRow, fromCol, toRow, toCol int, isWhite bool, rights CastlingRights) bool
source

IsValidKingMove validates king standard 1-square moves and castling (O-O and O-O-O)

func IsValidKnightMove

1func IsValidKnightMove(fromRow, fromCol, toRow, toCol int) bool
source

IsValidKnightMove validates knight L-shaped moves

func IsValidMove

1func IsValidMove(board Board, fromRow, fromCol, toRow, toCol int, isWhiteTurn bool, rights CastlingRights, enPassantCol int) bool
source

IsValidMove checks if a move from (fromRow, fromCol) to (toRow, toCol) is valid

func IsValidPawnMove

1func IsValidPawnMove(board Board, fromRow, fromCol, toRow, toCol int, isWhite bool, enPassantCol int) bool
source

IsValidPawnMove validates pawn movements including double step and en passant

func IsValidQueenMove

1func IsValidQueenMove(board Board, fromRow, fromCol, toRow, toCol int) bool
source

IsValidQueenMove validates queen diagonal or straight moves

func IsValidRookMove

1func IsValidRookMove(board Board, fromRow, fromCol, toRow, toCol int) bool
source

IsValidRookMove validates rook straight line moves

func IsWhitePiece

1func IsWhitePiece(p string) bool
source

IsWhitePiece returns true if the piece belongs to White

func NormalizePromotionPiece

1func NormalizePromotionPiece(promo string, isWhite bool) (string, error)
source

NormalizePromotionPiece validates and normalizes the promotion piece symbol

func ParseUCIMove

1func ParseUCIMove(uci string) (fromRow, fromCol, toRow, toCol int, promoPiece string, err error)
source

ParseUCIMove parses a standard UCI move string (e.g. "e2e4", "e7e8q")

func ApplyMove

1func ApplyMove(board Board, fromRow, fromCol, toRow, toCol int, promoPiece string, isWhiteTurn bool, rights *CastlingRights, enPassantCol *int) (Board, error)
source

ApplyMove applies a move to the board after validating it, updating castling rights and en passant.

func NewInitialBoard

1func NewInitialBoard() Board
source

NewInitialBoard returns the standard starting position for a chess game

func ReplayUCI

1func ReplayUCI(movesUCI string) (Board, bool, string, error)
source

ReplayUCI replays the entire sequence of chess moves from the beginning using UCI notation. Returns status ("PLAYING", "WHITE_WON", "BLACK_WON", "DRAW").

Types 2

type Board

array
1type Board [8][8]string
source

Board represents an 8x8 chess board matrix

type CastlingRights

struct
1type CastlingRights struct {
2	WhiteKingMoved      bool
3	WhiteLeftRookMoved  bool
4	WhiteRightRookMoved bool
5	BlackKingMoved      bool
6	BlackLeftRookMoved  bool
7	BlackRightRookMoved bool
8}
source

CastlingRights tracks whether king or rooks have moved

Imports 1

  • errors stdlib

Source Files 4