chess

package
v0.0.0-...-f494f79 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyRanks = errors.New("too many ranks")
	ErrTooFewRanks  = errors.New("too few ranks")
	ErrTooLongRank  = errors.New("too long rank")
	ErrTooShortRank = errors.New("too short rank")
)

Functions

func OnDiag

func OnDiag(a Square, b Square) bool

Types

type IllegalMoveError

type IllegalMoveError struct {
	FullmoveIndex int
	Color         PieceColor
	Notation      string
}

func (IllegalMoveError) Error

func (err IllegalMoveError) Error() string

type InvalidRuneError

type InvalidRuneError struct {
	At   int
	Rune rune
}

func (InvalidRuneError) Error

func (err InvalidRuneError) Error() string

type InvalidSyntaxError

type InvalidSyntaxError struct {
	At     int
	Reason string
}

func (InvalidSyntaxError) Error

func (err InvalidSyntaxError) Error() string

type Move

type Move struct {
	From Square
	To   Square

	EnPassant bool
	Castle    bool
	Promotion Piece
}

func (Move) String

func (mov Move) String() string

type MoveParser

type MoveParser interface {
	Parse(start Position, r io.RuneReader) ([]Move, error)
}

MoveParser parses UTF-8 representation of series of chess moves

func Algebraic

func Algebraic() MoveParser

type PGNResult

type PGNResult struct {
	Start Position
	Moves []Move
	Tags  map[string]string
}

func ParsePGN

func ParsePGN(r io.Reader) (PGNResult, error)

type Piece

type Piece struct {
	Kind  PieceKind
	Color PieceColor
}

func (Piece) String

func (p Piece) String() string

type PieceColor

type PieceColor int
const (
	White PieceColor = iota
	Black
)

func (PieceColor) Name

func (color PieceColor) Name() string

func (PieceColor) String

func (color PieceColor) String() string

type PieceKind

type PieceKind int
const (
	None PieceKind = iota
	Pawn
	Rook
	Knight
	Bishop
	Queen
	King
)

func (PieceKind) Name

func (kind PieceKind) Name() string

func (PieceKind) String

func (kind PieceKind) String() string

type Position

type Position [8][8]Piece

func Apply

func Apply(pos Position, mov Move) Position

func StartingPosition

func StartingPosition() Position

func (Position) Get

func (pos Position) Get(s Square) Piece

func (Position) Set

func (pos Position) Set(s Square, p Piece) Position

func (Position) String

func (pos Position) String() string

type PositionParser

type PositionParser interface {
	Parse(r io.RuneReader) (Position, error)
}

PositionParser parses UTF-8 representation of chess position

func FEN

func FEN() PositionParser

type Square

type Square struct {
	// contains filtered or unexported fields
}

func MustNewSquare

func MustNewSquare(file int, rank int) Square

MustNewSquare acts like NewSquare, but silently ignores errors and returns zero-value ("A1") instead.

func MustNewSquareFromString

func MustNewSquareFromString(s string) Square

MustNewSquareFromString acts like NewSquareFromString, but silently ignores errors and returns zero-value ("A1") instead.

func NewSquare

func NewSquare(file int, rank int) (Square, error)

NewSquare creates Square from file and rank coordinates. Both coordinates are represented as integers from 0 ("A" file or 1st rank) to 7 ("H" file or 8th rank). If either of coordinates falls out of this range, an error is returned.

func NewSquareFromString

func NewSquareFromString(s string) (Square, error)

NewSquareFromString creates square from its string representation (e.g. "G5"). Both lowercase and uppercase file letters are allowed. If s is not a valid square string, an error is returned.

func (Square) String

func (sq Square) String() string

Jump to

Keyboard shortcuts

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