butils

package
v0.0.0-...-1559631 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoColor Color = iota // 0
	Black                // 1
	White                // 2

	ColorArraySize = int(iota) // 3
	ColorMinValue  = Black
	ColorMaxValue  = White
)
View Source
const (
	SquareA1 = Square(iota)
	SquareB1
	SquareC1
	SquareD1
	SquareE1
	SquareF1
	SquareG1
	SquareH1
	SquareA2
	SquareB2
	SquareC2
	SquareD2
	SquareE2
	SquareF2
	SquareG2
	SquareH2
	SquareA3
	SquareB3
	SquareC3
	SquareD3
	SquareE3
	SquareF3
	SquareG3
	SquareH3
	SquareA4
	SquareB4
	SquareC4
	SquareD4
	SquareE4
	SquareF4
	SquareG4
	SquareH4
	SquareA5
	SquareB5
	SquareC5
	SquareD5
	SquareE5
	SquareF5
	SquareG5
	SquareH5
	SquareA6
	SquareB6
	SquareC6
	SquareD6
	SquareE6
	SquareF6
	SquareG6
	SquareH6
	SquareA7
	SquareB7
	SquareC7
	SquareD7
	SquareE7
	SquareF7
	SquareG7
	SquareH7
	SquareA8
	SquareB8
	SquareC8
	SquareD8
	SquareE8
	SquareF8
	SquareG8
	SquareH8

	SquareArraySize = int(iota)
	SquareMinValue  = SquareA1
	SquareMaxValue  = SquareH8
)
View Source
const (
	// Violent indicates captures (including en passant) and queen promotions
	Violent int = 1 << iota
	// Quiet are all other moves including minor promotions and castling
	Quiet
	// All moves
	All = Violent | Quiet
)
View Source
const ALLOW_SENTRY_PUSH = true
View Source
const BaseLancer = LancerMinValue
View Source
const BaseLancerFigure = Figure(LancerMinValue)
View Source
const LANCER_DIRECTION_MASK = 0b111

lancer direction mask

View Source
const LANCER_MASK = 0b11000

lancer mask

View Source
const MOVE_CAPTURE_SHIFT = MOVE_TARGET_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 24
View Source
const MOVE_FROM_SHIFT = 0

constants for recording the shifts of move representation parts

View Source
const MOVE_PIECE_SHIFT = MOVE_CAPTURE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 28
View Source
const MOVE_PROMOTION_CAPTURE_SHIFT = MOVE_PROMOTION_SQUARE_SHIFT + SQUARE_SIZE_IN_BITS // new
View Source
const MOVE_PROMOTION_SQUARE_SHIFT = MOVE_PIECE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // new
View Source
const MOVE_TARGET_SHIFT = MOVE_TYPE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 20
View Source
const MOVE_TO_SHIFT = SQUARE_SIZE_IN_BITS // originally 8
View Source
const MOVE_TYPE_SHIFT = MOVE_TO_SHIFT + SQUARE_SIZE_IN_BITS // originally 16
View Source
const NO_SQUARE = Square(0)

NO_SQUARE to be used as a square argument where there is no need to supply a square

View Source
const NUM_LANCER_DIRECTIONS = 8
View Source
const (
	NullMove = Move(0)
)
View Source
const PIECE_ARRAY_SIZE_IN_BITS = 6

PIECE_ARRAY_SIZE_IN_BITS tells how many bits to use for representing a piece

View Source
const PIECE_MASK = (1 << PIECE_ARRAY_SIZE_IN_BITS) - 1

piece mask

View Source
const SQUARE_MASK = SquareArraySize - 1

square mask

View Source
const SQUARE_SIZE_IN_BITS = 8

SQUARE_SIZE_IN_BITS is the size of the Square data structure in bits this should be used when constructing and deconstructing a move

Variables

View Source
var (
	// FENStartPos is the FEN string of the starting position
	//FENStartPos = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
	FENStartPos = "jlsesqkbnr/pppppppp/8/8/8/8/PPPPPPPP/JLneSQKBNR w KQkq - 0 1 -"
)
View Source
var FigureToSymbol = []string{
	".",
	"p",
	"n",
	"b",
	"r",
	"q",
	"k",
	"l",
	"ln",
	"lne",
	"le",
	"lse",
	"ls",
	"lsw",
	"lw",
	"lnw",
	"s",
	"j",
}
View Source
var LANCER_DIRECTION_TO_DELTA = [NUM_LANCER_DIRECTIONS][2]int{
	{1, 0},
	{1, 1},
	{0, 1},
	{-1, 1},
	{-1, 0},
	{-1, -1},
	{0, -1},
	{1, -1},
}

LANCER_DIRECTION_TO_DELTA maps lancer directions to corresponding deltas

View Source
var LancerDirectionMasksForSquares [SquareArraySize][NUM_LANCER_DIRECTIONS]Bitboard

LancerDirectionMasksForSquares maps squares and lancer directions to lancer attack masks

View Source
var PROMOTION_FIGURES_QUIET = []Figure{
	Knight,
	Bishop,
	Rook,
	Sentry,
	Jailer,
}
View Source
var PROMOTION_FIGURES_VIOLENT = []Figure{
	Queen,
	LancerN,
	LancerNE,
	LancerE,
	LancerSE,
	LancerS,
	LancerSW,
	LancerW,
	LancerNW,
}
View Source
var SymbolToFigureMap map[string]Figure

SymbolToFigureMap is a mapping from symbol to figure

Functions

func CastlingRook

func CastlingRook(kingEnd Square) (Piece, Square, Square)

CastlingRook returns the rook moved during castling together with starting and stopping squares

func FormatCastlingAbility

func FormatCastlingAbility(pos *Position) string

FormatCastlingAbility returns a string specifying the castling ability using standard FEN format

func FormatEnpassantSquare

func FormatEnpassantSquare(pos *Position) string

FormatEnpassantSquare converts position's castling ability to string

func FormatPiecePlacement

func FormatPiecePlacement(pos *Position) string

FormatPiecePlacement converts a position to FEN piece placement

func FormatSideToMove

func FormatSideToMove(pos *Position) string

FormatSideToMove returns "w" for white to play or "b" for black to play

func HomeRank

func HomeRank(col Color) int

HomeRank returns the rank of the king at the begining of the game by construction HomeRank(col)^1 returns the pawn rank result is undefined if c is not White or Black

func NormalizedDelta

func NormalizedDelta(fromSq, toSq Square) ([2]int, error)

NormalizedDelta returns the normalized delta of the move if the move is one of queen attacks returns an error otherwise

func ParseCastlingAbility

func ParseCastlingAbility(str string, pos *Position) error

ParseCastlingAbility sets castling ability for pos from str

func ParseEnpassantSquare

func ParseEnpassantSquare(str string, pos *Position) error

ParseEnpassantSquare parses the en passant square from str

func ParsePiecePlacement

func ParsePiecePlacement(str string, pos *Position) error

ParsePiecePlacement parse pieces from str (FEN like) into pos

func ParseSideToMove

func ParseSideToMove(str string, pos *Position) error

ParseSideToMove sets side to move for pos from str

Types

type Bitboard

type Bitboard uint64

Bitboard is a set representing the 8x8 chess board squares

const (
	BbEmpty              Bitboard = 0x0000000000000000
	BbFull               Bitboard = 0xffffffffffffffff
	BbBorder             Bitboard = 0xff818181818181ff
	BbPawnStartRank      Bitboard = 0x00ff00000000ff00
	BbPawnStartRankBlack Bitboard = 0x00ff000000000000
	BbPawnStartRankWhite Bitboard = 0x000000000000ff00
	BbPawnDoubleRank     Bitboard = 0x000000ffff000000
	BbBlackSquares       Bitboard = 0xaa55aa55aa55aa55
	BbWhiteSquares       Bitboard = 0x55aa55aa55aa55aa
)

useful bitboards

const (
	BbFileA Bitboard = 0x101010101010101 << iota
	BbFileB
	BbFileC
	BbFileD
	BbFileE
	BbFileF
	BbFileG
	BbFileH
)
const (
	BbRank1 Bitboard = 0x0000000000000FF << (8 * iota)
	BbRank2
	BbRank3
	BbRank4
	BbRank5
	BbRank6
	BbRank7
	BbRank8
)

func Backward

func Backward(col Color, bb Bitboard) Bitboard

Backward returns bb shifted one rank backward wrt color

func BackwardFill

func BackwardFill(col Color, bb Bitboard) Bitboard

BackwardFill computes forward fill wrt color

func BackwardPawns

func BackwardPawns(pos *Position, us Color) Bitboard

BackwardPawns returns the our backward pawns. a backward pawn is a pawn that has no pawns behind them on its file or adjacent file, it's not isolated and cannot advance safely

func BackwardSpan

func BackwardSpan(col Color, bb Bitboard) Bitboard

BackwardSpan computes backward span wrt color

func BishopMobility

func BishopMobility(sq Square, all Bitboard) Bitboard

BishopMobility returns the squares a bishop can reach from sq given all pieces

func Bishops

func Bishops(pos *Position, us Color) Bitboard

Bishops return the set of bishops of the given color

func ConnectedPawns

func ConnectedPawns(pos *Position, us Color) Bitboard

ConnectedPawns returns a bitboad with our connected pawns

func DoubledPawns

func DoubledPawns(pos *Position, us Color) Bitboard

DoubledPawns returns a bitboard with our doubled pawns

func East

func East(bb Bitboard) Bitboard

East shifts all squares one file right delete h-file, then shift left

func FileBb

func FileBb(file int) Bitboard

FileBb returns a bitboard with all bits on file set

func Fill

func Fill(bb Bitboard) Bitboard

Fill returns a bitboard with all files with squares filled.

func Forward

func Forward(col Color, bb Bitboard) Bitboard

Forward returns bb shifted one rank forward wrt color

func ForwardFill

func ForwardFill(col Color, bb Bitboard) Bitboard

ForwardFill computes forward fill wrt color.

func ForwardSpan

func ForwardSpan(col Color, bb Bitboard) Bitboard

ForwardSpan computes forward span wrt color.

func IsolatedPawns

func IsolatedPawns(pos *Position, us Color) Bitboard

IsolatedPawns returns a bitboard with our isolated pawns

func JailerMobility

func JailerMobility(sq Square, us Bitboard, them Bitboard) Bitboard

JailerMobility returns the squares a jailer can reach from sq given all pieces

func KingArea

func KingArea(pos *Position, us Color) Bitboard

KingArea returns an area around king

func KingMobility

func KingMobility(sq Square) Bitboard

KingMobility returns all squares a king can reach from sq doesn't include castling

func Kings

func Kings(pos *Position, us Color) Bitboard

Kings return the set of kings of the given color normally there is exactly on king for each side

func KnightMobility

func KnightMobility(sq Square) Bitboard

KnightMobility returns all squares a knight can reach from sq

func Knights

func Knights(pos *Position, us Color) Bitboard

Knights return the set of knights of the given color

func LancerMobility

func LancerMobility(sq Square, ld int, us Bitboard, them Bitboard) Bitboard

LancerMobility returns all squares the lancer of color us and of direction ld can reach from sq

func Majors

func Majors(pos *Position, us Color) Bitboard

Majors returns a bitboard with our rooks and queens

func Minors

func Minors(pos *Position, us Color) Bitboard

Minors returns a bitboard with our knights and bishops

func MinorsAndMajors

func MinorsAndMajors(pos *Position, col Color) Bitboard

MinorsAndMajors returns a bitboard with minor and major pieces

func North

func North(bb Bitboard) Bitboard

North shifts all squares one rank up

func NorthFill

func NorthFill(bb Bitboard) Bitboard

NorthFill returns a bitboard with all north bits set

func NorthSpan

func NorthSpan(bb Bitboard) Bitboard

NorthSpan is like NorthFill shifted on up

func OpenFiles

func OpenFiles(pos *Position, us Color) Bitboard

OpenFiles returns our fully set files with no pawns

func PassedPawns

func PassedPawns(pos *Position, us Color) Bitboard

PassedPawns returns a bitboard with our passed pawns

func PawnThreats

func PawnThreats(pos *Position, us Color) Bitboard

PawnThreats returns the squares threatened by our pawns

func Pawns

func Pawns(pos *Position, us Color) Bitboard

Pawns return the set of pawns of the given color

func QueenMobility

func QueenMobility(sq Square, all Bitboard) Bitboard

QueenMobility returns the squares a queen can reach from sq given all pieces

func Queens

func Queens(pos *Position, us Color) Bitboard

Queens return the set of queens of the given color

func RammedPawns

func RammedPawns(pos *Position, us Color) Bitboard

RammedPawns returns pawns on ranks 2, 3 for white and rank 6 and 7 blocking an advanced enemy pawn

func RankBb

func RankBb(rank int) Bitboard

RankBb returns a bitboard with all bits on rank set

func RookMobility

func RookMobility(sq Square, all Bitboard) Bitboard

RookMobility returns the squares a rook can reach from sq given all pieces

func Rooks

func Rooks(pos *Position, us Color) Bitboard

Rooks return the set of rooks of the given color

func SemiOpenFiles

func SemiOpenFiles(pos *Position, us Color) Bitboard

SemiOpenFiles returns our fully set files with enemy pawns, but no friendly pawns

func South

func South(bb Bitboard) Bitboard

South shifts all squares one rank down

func SouthFill

func SouthFill(bb Bitboard) Bitboard

SouthFill returns a bitboard with all south bits set

func SouthSpan

func SouthSpan(bb Bitboard) Bitboard

SouthSpan is like SouthFill shifted on up

func SuperQueenMobility

func SuperQueenMobility(sq Square) Bitboard

SuperQueenMobility returns the squares a queen can reach from sq on an empty board

func West

func West(bb Bitboard) Bitboard

West shifts all squares one file left delete a-file, then shift right

func (Bitboard) AsSquare

func (bb Bitboard) AsSquare() Square

AsSquare returns the occupied square if the bitboard has a single piece if the board has more then one piece the result is undefined https://golang.org/pkg/math/bits/#TrailingZeros64

func (Bitboard) Count

func (bb Bitboard) Count() int32

count returns the number of squares set in bb https://golang.org/pkg/math/bits/#OnesCount64

func (Bitboard) Has

func (bb Bitboard) Has(sq Square) bool

Has returns bb if sq is occupied in bitboard

func (Bitboard) LSB

func (bb Bitboard) LSB() Bitboard

LSB picks a square in the board returns empty board for empty board

func (*Bitboard) Pop

func (bb *Bitboard) Pop() Square

Pop pops a set square from the bitboard

type Castle

type Castle uint

Castle represents the castling rights mask

const (
	// WhiteOO indicates that White can castle on King side
	WhiteOO Castle = 1 << iota
	// WhiteOOO indicates that White can castle on Queen side
	WhiteOOO
	// BlackOO indicates that Black can castle on King side
	BlackOO
	// BlackOOO indicates that Black can castle on Queen side
	BlackOOO

	// NoCastle indicates no castling rights
	NoCastle Castle = 0
	// AnyCastle indicates all castling rights
	AnyCastle Castle = WhiteOO | WhiteOOO | BlackOO | BlackOOO

	CastleArraySize = int(AnyCastle + 1)
	CastleMinValue  = NoCastle
	CastleMaxValue  = AnyCastle
)

func (Castle) String

func (c Castle) String() string

type Color

type Color uint

Color represents a side

func (Color) Multiplier

func (c Color) Multiplier() int32

Multiplier returns -1 for Black, 1 for White useful for computing the position score relative to current player result is undefined if c is not White or Black

func (Color) Opposite

func (c Color) Opposite() Color

Opposite returns the reversed color result is undefined if c is not White or Black

type Figure

type Figure uint

Figure represents a piece without a color

const (
	NoFigure Figure = iota // 0
	Pawn                   // 1
	Knight                 // 2
	Bishop                 // 3
	Rook                   // 4
	Queen                  // 5
	King                   // 6
	Lancer                 // 7 - abstract; base figure of lancer
	LancerN                // 8
	LancerNE               // 9
	LancerE                // 10
	LancerSE               // 11
	LancerS                // 12
	LancerSW               // 13
	LancerW                // 14
	LancerNW               // 15
	Sentry                 // 16
	Jailer                 // 17

	FigureArraySize = int(iota) // 18
	LancerMinValue  = LancerN   // 8
	LancerMaxValue  = LancerNW  // 15
)

func SymbolToFigure

func SymbolToFigure(symbol string) Figure

SymbolToFigure returns the Figure for the symbol

func (Figure) AlgebLetter

func (f Figure) AlgebLetter() string

Figure.AlgebLetter returns the algeb letter of the figure ( lower case ) for lancer direction is omitted

func (Figure) BaseFigure

func (f Figure) BaseFigure() Figure

Figure.BaseFigure returns the base figure of the figure apart from lancer it is the same as figure

func (Figure) IsLancer

func (f Figure) IsLancer() bool

Figure.IsLancer determines whether figure is lancer

func (Figure) LancerDirection

func (lancer Figure) LancerDirection() int

Figure.LancerDirection determines the lancer direction of the figure figure has to be a lancer

func (Figure) SanLetter

func (f Figure) SanLetter() string

Figure.SanLetter returns the san letter of the figure ( upper case ) for lancer direction is omitted

func (Figure) SanSymbol

func (f Figure) SanSymbol() string

Figure.SanSymbol returns the san symbol of the figure ( letter upper case )

func (Figure) Symbol

func (f Figure) Symbol() string

Figure.Symbol returns the symbol of the figure ( lower case )

type Move

type Move uint64

Move stores a position dependent move

Bit representation

00.00.00.3f - from
00.00.3f.00 - to
00.0f.00.00 - move type
00.f0.00.00 - target
0f.00.00.00 - capture
f0.00.00.00 - piece

func MakeLancerMove

func MakeLancerMove(from, to Square, piece, capture, target Piece) Move

MakeLancerMove constructs a lancer move

func MakeMove

func MakeMove(moveType MoveType, from, to Square, target, capture, piece Piece, promSquare Square, promCapture Piece) Move

MakeMove constructs a move

func (Move) Capture

func (m Move) Capture() Piece

Capture returns the captured pieces

func (Move) CaptureSquare

func (m Move) CaptureSquare() Square

CaptureSquare returns the captured piece square if no piece is captured, the result is the destination square

func (Move) Color

func (m Move) Color() Color

Color returns which player is moving

func (Move) Figure

func (m Move) Figure() Figure

Figure returns which figure is moved

func (Move) From

func (m Move) From() Square

From returns the starting square

func (Move) IsQuiet

func (m Move) IsQuiet() bool

IsQuiet returns true if the move is not violent

func (Move) IsViolent

func (m Move) IsViolent() bool

IsViolent returns true if the move is a capture or a queen promotion castling and minor promotions (including captures) are not violent TODO: IsViolent should be in sync with GenerateViolentMoves

func (Move) LAN

func (m Move) LAN() string

LAN converts a move to Long Algebraic Notation http://en.wikipedia.org/wiki/Algebraic_notation_%28chess%29#Long_algebraic_notation e.g. a2-a3, b7-b8Q, Nb1xc3, Ke1-c1 (white king queen side castling)

func (Move) MoveType

func (m Move) MoveType() MoveType

MoveType returns the move type

func (Move) Piece

func (m Move) Piece() Piece

Piece returns the piece moved

func (Move) Promotion

func (m Move) Promotion() Piece

Promotion returns the promoted piece if any

func (Move) PromotionCapture

func (m Move) PromotionCapture() Piece

PromotionCapture returns the promotion capture of the move

func (Move) PromotionSquare

func (m Move) PromotionSquare() Square

PromotionSquare returns the promotion square of the move

func (Move) String

func (m Move) String() string

move as a string

func (Move) Target

func (m Move) Target() Piece

Target returns the piece on the to square after the move is executed

func (Move) To

func (m Move) To() Square

To returns the destination square

func (Move) UCI

func (m Move) UCI() string

UCI converts a move to UCI format the protocol specification at http://wbec-ridderkerk.nl/html/UCIProtocol.html incorrectly states that this is the long algebraic notation (LAN)

type MoveBuff

type MoveBuff []MoveBuffItem

MoveBuff holds a list of MoveBuffItems

type MoveBuffBySan

type MoveBuffBySan []MoveBuffItem

func (MoveBuffBySan) Len

func (mb MoveBuffBySan) Len() int

sorting functions to sort MoveBuff by SAN

func (MoveBuffBySan) Less

func (mb MoveBuffBySan) Less(i, j int) bool

func (MoveBuffBySan) Swap

func (mb MoveBuffBySan) Swap(i, j int)

type MoveBuffItem

type MoveBuffItem struct {
	Move  Move
	San   string
	Algeb string
	Lan   string
}

MoveBuffItem hold a move together with its SAN and algebraic representation

type MoveType

type MoveType uint8

MoveType defines the move type

const (
	NoMove     MoveType = iota // no move or null move
	Normal                     // regular move
	Promotion                  // pawn is promoted. Move.Promotion() gives the new piece
	Castling                   // king castles
	Enpassant                  // pawn takes enpassant
	SentryPush                 // sentry push
)

type Piece

type Piece uint

Piece is a figure owned by one side

const (
	NoPiece       Piece = iota // 0
	DummyPiece                 // 1
	BlackPawn                  // 2
	WhitePawn                  // 3
	BlackKnight                // 4
	WhiteKnight                // 5
	BlackBishop                // 6
	WhiteBishop                // 7
	BlackRook                  // 8
	WhiteRook                  // 9
	BlackQueen                 // 10
	WhiteQueen                 // 11
	BlackKing                  // 12
	WhiteKing                  // 13
	BlackLancer                // 14 abstract; base piece of black lancer
	WhiteLancer                // 15 abstract; base piece of white lancer
	BlackLancerN               // 16
	WhiteLancerN               // 17
	BlackLancerNE              // 18
	WhiteLancerNE              // 19
	BlackLancerE               // 20
	WhiteLancerE               // 21
	BlackLancerSE              // 22
	WhiteLancerSE              // 23
	BlackLancerS               // 24
	WhiteLancerS               // 25
	BlackLancerSW              // 26
	WhiteLancerSW              // 27
	BlackLancerW               // 28
	WhiteLancerW               // 29
	BlackLancerNW              // 30
	WhiteLancerNW              // 31
	BlackSentry                // 32
	WhiteSentry                // 33
	BlackJailer                // 34
	WhiteJailer                // 35

	PieceArraySize = int(iota)   // 36
	PieceMinValue  = BlackPawn   // 2
	PieceMaxValue  = WhiteJailer // 35
)

piece constants must stay in sync with ColorFigure the order of pieces must match Polyglot format: http://hgm.nubati.net/book_format.html

func ColorFigure

func ColorFigure(col Color, fig Figure) Piece

ColorFigure returns a piece with col and fig

func MakeLancer

func MakeLancer(color Color, direction int) Piece

MakeLancer creates a lancer piece from color and direction

func SymbolToPiece

func SymbolToPiece(symbol string) Piece

SymbolToPiece returns the Piece for the symbol

func (Piece) AlgebLetter

func (pi Piece) AlgebLetter() string

Piece.AlgebLetter returns the algeb letter of the piece ( upper case ) convenience function

func (Piece) AlgebSymbol

func (pi Piece) AlgebSymbol() string

AlgebSymbol returns the algebraic symbol of the piece

func (Piece) BaseFigure

func (pi Piece) BaseFigure() Figure

Piece.BaseFigure returns the base figure of the piece convenience function

func (Piece) Color

func (pi Piece) Color() Color

Color returns piece's color

func (Piece) ColorInverse

func (pi Piece) ColorInverse() Piece

ColorInverse returns the color inverse of the piece

func (Piece) FenSymbol

func (pi Piece) FenSymbol() string

FenSymbol returns the fen symbol of the piece ( letter case depends on color )

func (Piece) Figure

func (pi Piece) Figure() Figure

Figure returns the figure of the piece

func (Piece) LancerDirection

func (lancer Piece) LancerDirection() int

Piece.LancerDirection determines the lancer direction of the piece convenience function

func (Piece) PrettySymbol

func (pi Piece) PrettySymbol() string

PrettySymbol returns the pretty print symbol of the piece

func (Piece) SanLetter

func (pi Piece) SanLetter() string

Piece.SanLetter returns the san letter of the piece ( lower case ) convenience function

func (Piece) SanSymbol

func (pi Piece) SanSymbol() string

Piece.SanSymbol returns the san symbol of the piece ( letter upper case ) convenience function

type Position

type Position struct {
	Ply   int // current ply
	Nodes int // Perft nodes

	LegalMoveBuff MoveBuff // buffer to store legal moves; for sorting by SAN
	// contains filtered or unexported fields
}

Position represents the chess board and keeps track of the move history

func NewPosition

func NewPosition() *Position

NewPosition returns a new position representing an empty board

func PositionFromFEN

func PositionFromFEN(fen string) (*Position, error)

PositionFromFEN parses fen and returns the position

fen must contain the position using Forsyth–Edwards Notation http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

func (*Position) AppendMove

func (pos *Position) AppendMove(move Move, moves *[]Move)

AppendMove appends a move to a move list if the move is a disabled move, it does nothing

func (*Position) ByColor

func (pos *Position) ByColor(col Color) Bitboard

ByColor returns the bitboard occupied by color col

func (*Position) ByFigure

func (pos *Position) ByFigure(fig Figure) Bitboard

ByFigure returns the bitboard occupied by figure fig

func (*Position) ByPiece

func (pos *Position) ByPiece(col Color, fig Figure) Bitboard

ByPiece is a shortcut for ByColor(col)&ByFigure(fig)

func (*Position) ByPiece2

func (pos *Position) ByPiece2(col Color, fig0, fig1 Figure) Bitboard

ByPiece2 is a shortcut for ByColor(col)&(ByFigure(fig0)|ByFigure(fig1))

func (*Position) CastlingAbility

func (pos *Position) CastlingAbility() Castle

CastlingAbility returns kings' castling ability

func (*Position) CreateLegalMoveBuff

func (pos *Position) CreateLegalMoveBuff()

CreateLegalMoveBuff creates a move buffer for all legal moves, with SAN and UCI sorted by SAN

func (*Position) DoMove

func (pos *Position) DoMove(move Move)

DoMove executes a legal move

func (*Position) EnpassantSquare

func (pos *Position) EnpassantSquare() Square

EnpassantSquare returns the en passant square if none, return SquareA1 this uses the polyglot definition: if the en. passant square is not attacked by the enemy, then EnpassantSquare() returns SquareA1

func (*Position) FiftyMoveRule

func (pos *Position) FiftyMoveRule() bool

FiftyMoveRule returns true if 50 moves (on each side) were made without any capture of pawn move

if FiftyMoveRule returns true, the position is a draw

func (*Position) FormatDisabledMove

func (pos *Position) FormatDisabledMove() string

FormatDisabledMove formats disabled move as FEN field

func (*Position) FullmoveCounter

func (pos *Position) FullmoveCounter() int

FullmoveCounter returns the number of full moves, starts from 1

func (*Position) GenerateFigureMoves

func (pos *Position) GenerateFigureMoves(fig Figure, kind int, moves *[]Move, limitFrom Bitboard)

GenerateFigureMoves generate moves of kind for a given figure the generated moves are pseudo-legal, i.e. they can leave the king in check. kind is Quiet or Violent, or both limitFrom limits from squares

func (*Position) GenerateMoves

func (pos *Position) GenerateMoves(kind int, moves *[]Move)

generateMoves appends to moves all moves valid from pos the generated moves are pseudo-legal, i.e. they can leave the king in check. kind is Quiet or Violent, or both

func (*Position) Get

func (pos *Position) Get(sq Square) Piece

Get returns the piece at sq

func (*Position) GetAttacker

func (pos *Position) GetAttacker(sq Square, them Color) Figure

GetAttacker returns the smallest figure of color them that attacks sq

func (*Position) GivesCheck

func (pos *Position) GivesCheck(m Move) bool

GivesCheck returns true if the opposite side is in check after m is executed assumes that the position is legal and opposite side is not already in check

func (*Position) HalfmoveClock

func (pos *Position) HalfmoveClock() int

HalfmoveClock returns the number of halfmoves since the last capture or pawn advance

func (*Position) HasLegalMoves

func (pos *Position) HasLegalMoves() bool

HasLegalMoves returns true if current side has any legal moves this function is very expensive

func (*Position) InitMoveToSan

func (pos *Position) InitMoveToSan()

InitMoveToSan should be called before batch calls to MoveToSanBatch

func (*Position) InsufficientMaterial

func (pos *Position) InsufficientMaterial() bool

InsufficientMaterial returns true if the position is theoretical draw

func (*Position) InvertSideToMove

func (pos *Position) InvertSideToMove()

InvertSideToMove inverts the side to move

func (*Position) IsChecked

func (pos *Position) IsChecked(col Color) bool

IsChecked returns true if side's king is checked

func (*Position) IsEnpassantSquare

func (pos *Position) IsEnpassantSquare(sq Square) bool

IsEnpassantSquare returns true if sq is the en passant square

func (*Position) IsKingJailed

func (pos *Position) IsKingJailed(color Color) bool

IsKingJailed tells whether king is jailed for color

func (*Position) IsOurKingJailed

func (pos *Position) IsOurKingJailed() bool

IsOurKingJailed tells whether our king is jailed

func (*Position) IsPseudoLegal

func (pos *Position) IsPseudoLegal(m Move) bool

IsPseudoLegal returns true if m is a pseudo legal move for pos it returns true iff m can be executed even if own king is in check after the move, NullMove is not a valid move assumes that there exists a position for which this move is valid, e.g. not a rook moving diagonally or a pawn promoting on 4th rank

func (*Position) IsSquareEmpty

func (pos *Position) IsSquareEmpty(sq Square) bool

IsSquareEmpty tells whether a square is empty

func (*Position) IsSquareJailedForColor

func (pos *Position) IsSquareJailedForColor(sq Square, color Color) bool

IsSquareJailedForColor tells whether a square is jailed for color

func (*Position) IsSquareJailedForThem

func (pos *Position) IsSquareJailedForThem(sq Square) bool

IsSquareJailedForThem tells whether a square is jailed for them

func (*Position) IsSquareJailedForUs

func (pos *Position) IsSquareJailedForUs(sq Square) bool

IsSquareJailedForUs tells whether a square is jailed for us

func (*Position) IsTheirKingJailed

func (pos *Position) IsTheirKingJailed() bool

IsTheirKingJailed tells whether their king is jailed

func (*Position) JailedForColor

func (pos *Position) JailedForColor(color Color) Bitboard

JailedForColor tells squares jailed for color

func (*Position) JailedForThem

func (pos *Position) JailedForThem() Bitboard

JailedForThem tells squares jailed for them

func (*Position) JailedForUs

func (pos *Position) JailedForUs() Bitboard

JailedForUs tells squares jailed for us

func (*Position) LastMove

func (pos *Position) LastMove() Move

LastMove returns the last move played, if any

func (*Position) LegalMoves

func (pos *Position) LegalMoves() []Move

LegalMoves returns all legal moves from the position

func (*Position) LegalMovesString

func (pos *Position) LegalMovesString() string

LegalMovesString lists the legal moves fromt the position numbered and sorted by SAN as string

func (*Position) MoveToSan

func (pos *Position) MoveToSan(move Move) string

MoveToSan returns the move in SAN notation

func (*Position) MoveToSanBatch

func (pos *Position) MoveToSanBatch(move Move) string

MoveToSanBatch returns the move in SAN notation provided that InitMoveToSan was called for the position

func (*Position) Perft

func (pos *Position) Perft(maxDepth int, verbose bool) int

func (*Position) PerftRec

func (pos *Position) PerftRec(depth int, maxDepth int)

func (*Position) PrettyPrint

func (pos *Position) PrettyPrint()

PrettyPrint pretty prints the current position

func (*Position) PrettyPrintString

func (pos *Position) PrettyPrintString() string

PrettyPrint pretty prints the current position to string

func (*Position) Put

func (pos *Position) Put(sq Square, pi Piece)

put puts a piece on the board does nothing if pi is NoPiece, does not validate input

func (*Position) Remove

func (pos *Position) Remove(sq Square, pi Piece)

remove removes a piece from the table does nothing if pi is NoPiece, does not validate input

func (*Position) RetrieveSideToMove

func (pos *Position) RetrieveSideToMove()

RetrieveSideToMove retrieves side to move for switching turn for move generation

func (*Position) SaveSideToMove

func (pos *Position) SaveSideToMove()

SaveSideToMove saves side to move for switching turn for move generation

func (*Position) SetCastlingAbility

func (pos *Position) SetCastlingAbility(castle Castle)

SetCastlingAbility sets the side to move, correctly updating the Zobrist key

func (*Position) SetEnpassantSquare

func (pos *Position) SetEnpassantSquare(epsq Square)

SetEnpassantSquare sets the en passant square correctly updating the Zobrist key

func (*Position) SetFullmoveCounter

func (pos *Position) SetFullmoveCounter(n int)

SetFullmoveCounter sets the number of full moves

func (*Position) SetHalfmoveClock

func (pos *Position) SetHalfmoveClock(n int)

SetHalfmoveClock sets the number of halfmoves since the last capture or pawn advance

func (*Position) SetSideToMove

func (pos *Position) SetSideToMove(col Color)

SetSideToMove sets the side to move, correctly updating the Zobrist key

func (*Position) String

func (pos *Position) String() string

String returns position in FEN format for table format use PrettyPrint

func (*Position) Them

func (pos *Position) Them() Color

Them returns the player awaiting to move

func (*Position) ThemBb

func (pos *Position) ThemBb() Bitboard

ThemBb returns the bitboard for them

func (*Position) ThreeFoldRepetition

func (pos *Position) ThreeFoldRepetition() int

ThreeFoldRepetition returns whether current position was seen three times already returns minimum between 3 and the actual number of repetitions

func (*Position) UCIToMove

func (pos *Position) UCIToMove(s string) (Move, error)

UCIToMove parses a move given in UCI format s can be "a2a4" or "h7h8Q" for pawn promotion

func (*Position) UndoMove

func (pos *Position) UndoMove()

UndoMove takes back the last move, there should be at least one move on the stack

func (*Position) UndoMoveSafe

func (pos *Position) UndoMoveSafe()

UndoMoveSafe takes back the last move, does nothing if there is no move on the stack

func (*Position) Us

func (pos *Position) Us() Color

Us returns the current player to move Us/Them is based on Glaurung terminology

func (*Position) UsBb

func (pos *Position) UsBb() Bitboard

UsBb returns the bitboard for us

func (*Position) Verify

func (pos *Position) Verify() error

verify checks the validity of the position mostly used for debugging purposes

func (*Position) WhereIsKing

func (pos *Position) WhereIsKing(color Color) Square

WhereIsKing tells the position of the king for color

func (*Position) WhereIsOurKing

func (pos *Position) WhereIsOurKing() Square

WhereIsOurKing tells the position of our king

func (*Position) WhereTheirKing

func (pos *Position) WhereTheirKing() Square

WhereIsTheirKing tells the position of their king

func (*Position) Zobrist

func (pos *Position) Zobrist() uint64

Zobrist returns the zobrist key of the position, never returns 0

type Square

type Square uint

square identifies the location on the board

func PawnPromotionSquare

func PawnPromotionSquare(col Color, sq Square) Square

PawnPromotionSquare returns the propotion square of a col pawn on sq undefined behaviour if col is not White or Black

func RankFile

func RankFile(r, f int) Square

RankFile returns a square with rank r and file f r and f should be between 0 and 7

func SquareFromString

func SquareFromString(s string) (Square, error)

SquareFromString parses a square from a string the string has standard chess format [a-h][1-8]

func (Square) AddDelta

func (sq Square) AddDelta(delta [2]int) (Square, error)

AddDelta adds a delta to the square

func (Square) Bitboard

func (sq Square) Bitboard() Bitboard

Bitboard returns a bitboard that has sq set

func (Square) File

func (sq Square) File() int

File returns a number from 0 to 7 representing the file of the square

func (Square) POV

func (sq Square) POV(col Color) Square

POV returns the square from col's point of view that is for Black the rank is flipped, file stays the same useful in evaluation based on king's or pawns' positions

func (Square) Rank

func (sq Square) Rank() int

Rank returns a number from 0 to 7 representing the rank of the square

func (Square) String

func (sq Square) String() string

string representation of a Square

Jump to

Keyboard shortcuts

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