Documentation ¶
Index ¶
- Constants
- Variables
- func CastlingRook(kingEnd Square) (Piece, Square, Square)
- func FormatCastlingAbility(pos *Position) string
- func FormatEnpassantSquare(pos *Position) string
- func FormatPiecePlacement(pos *Position) string
- func FormatSideToMove(pos *Position) string
- func HomeRank(col Color) int
- func NormalizedDelta(fromSq, toSq Square) ([2]int, error)
- func ParseCastlingAbility(str string, pos *Position) error
- func ParseEnpassantSquare(str string, pos *Position) error
- func ParsePiecePlacement(str string, pos *Position) error
- func ParseSideToMove(str string, pos *Position) error
- type Bitboard
- func Backward(col Color, bb Bitboard) Bitboard
- func BackwardFill(col Color, bb Bitboard) Bitboard
- func BackwardPawns(pos *Position, us Color) Bitboard
- func BackwardSpan(col Color, bb Bitboard) Bitboard
- func BishopMobility(sq Square, all Bitboard) Bitboard
- func Bishops(pos *Position, us Color) Bitboard
- func ConnectedPawns(pos *Position, us Color) Bitboard
- func DoubledPawns(pos *Position, us Color) Bitboard
- func East(bb Bitboard) Bitboard
- func FileBb(file int) Bitboard
- func Fill(bb Bitboard) Bitboard
- func Forward(col Color, bb Bitboard) Bitboard
- func ForwardFill(col Color, bb Bitboard) Bitboard
- func ForwardSpan(col Color, bb Bitboard) Bitboard
- func IsolatedPawns(pos *Position, us Color) Bitboard
- func JailerMobility(sq Square, us Bitboard, them Bitboard) Bitboard
- func KingArea(pos *Position, us Color) Bitboard
- func KingMobility(sq Square) Bitboard
- func Kings(pos *Position, us Color) Bitboard
- func KnightMobility(sq Square) Bitboard
- func Knights(pos *Position, us Color) Bitboard
- func LancerMobility(sq Square, ld int, us Bitboard, them Bitboard) Bitboard
- func Majors(pos *Position, us Color) Bitboard
- func Minors(pos *Position, us Color) Bitboard
- func MinorsAndMajors(pos *Position, col Color) Bitboard
- func North(bb Bitboard) Bitboard
- func NorthFill(bb Bitboard) Bitboard
- func NorthSpan(bb Bitboard) Bitboard
- func OpenFiles(pos *Position, us Color) Bitboard
- func PassedPawns(pos *Position, us Color) Bitboard
- func PawnThreats(pos *Position, us Color) Bitboard
- func Pawns(pos *Position, us Color) Bitboard
- func QueenMobility(sq Square, all Bitboard) Bitboard
- func Queens(pos *Position, us Color) Bitboard
- func RammedPawns(pos *Position, us Color) Bitboard
- func RankBb(rank int) Bitboard
- func RookMobility(sq Square, all Bitboard) Bitboard
- func Rooks(pos *Position, us Color) Bitboard
- func SemiOpenFiles(pos *Position, us Color) Bitboard
- func South(bb Bitboard) Bitboard
- func SouthFill(bb Bitboard) Bitboard
- func SouthSpan(bb Bitboard) Bitboard
- func SuperQueenMobility(sq Square) Bitboard
- func West(bb Bitboard) Bitboard
- type Castle
- type Color
- type Figure
- type Move
- func (m Move) Capture() Piece
- func (m Move) CaptureSquare() Square
- func (m Move) Color() Color
- func (m Move) Figure() Figure
- func (m Move) From() Square
- func (m Move) IsQuiet() bool
- func (m Move) IsViolent() bool
- func (m Move) LAN() string
- func (m Move) MoveType() MoveType
- func (m Move) Piece() Piece
- func (m Move) Promotion() Piece
- func (m Move) PromotionCapture() Piece
- func (m Move) PromotionSquare() Square
- func (m Move) String() string
- func (m Move) Target() Piece
- func (m Move) To() Square
- func (m Move) UCI() string
- type MoveBuff
- type MoveBuffBySan
- type MoveBuffItem
- type MoveType
- type Piece
- func (pi Piece) AlgebLetter() string
- func (pi Piece) AlgebSymbol() string
- func (pi Piece) BaseFigure() Figure
- func (pi Piece) Color() Color
- func (pi Piece) ColorInverse() Piece
- func (pi Piece) FenSymbol() string
- func (pi Piece) Figure() Figure
- func (lancer Piece) LancerDirection() int
- func (pi Piece) PrettySymbol() string
- func (pi Piece) SanLetter() string
- func (pi Piece) SanSymbol() string
- type Position
- func (pos *Position) AppendMove(move Move, moves *[]Move)
- func (pos *Position) ByColor(col Color) Bitboard
- func (pos *Position) ByFigure(fig Figure) Bitboard
- func (pos *Position) ByPiece(col Color, fig Figure) Bitboard
- func (pos *Position) ByPiece2(col Color, fig0, fig1 Figure) Bitboard
- func (pos *Position) CastlingAbility() Castle
- func (pos *Position) CreateLegalMoveBuff()
- func (pos *Position) DoMove(move Move)
- func (pos *Position) EnpassantSquare() Square
- func (pos *Position) FiftyMoveRule() bool
- func (pos *Position) FormatDisabledMove() string
- func (pos *Position) FullmoveCounter() int
- func (pos *Position) GenerateFigureMoves(fig Figure, kind int, moves *[]Move, limitFrom Bitboard)
- func (pos *Position) GenerateMoves(kind int, moves *[]Move)
- func (pos *Position) Get(sq Square) Piece
- func (pos *Position) GetAttacker(sq Square, them Color) Figure
- func (pos *Position) GivesCheck(m Move) bool
- func (pos *Position) HalfmoveClock() int
- func (pos *Position) HasLegalMoves() bool
- func (pos *Position) InitMoveToSan()
- func (pos *Position) InsufficientMaterial() bool
- func (pos *Position) InvertSideToMove()
- func (pos *Position) IsChecked(col Color) bool
- func (pos *Position) IsEnpassantSquare(sq Square) bool
- func (pos *Position) IsKingJailed(color Color) bool
- func (pos *Position) IsOurKingJailed() bool
- func (pos *Position) IsPseudoLegal(m Move) bool
- func (pos *Position) IsSquareEmpty(sq Square) bool
- func (pos *Position) IsSquareJailedForColor(sq Square, color Color) bool
- func (pos *Position) IsSquareJailedForThem(sq Square) bool
- func (pos *Position) IsSquareJailedForUs(sq Square) bool
- func (pos *Position) IsTheirKingJailed() bool
- func (pos *Position) JailedForColor(color Color) Bitboard
- func (pos *Position) JailedForThem() Bitboard
- func (pos *Position) JailedForUs() Bitboard
- func (pos *Position) LastMove() Move
- func (pos *Position) LegalMoves() []Move
- func (pos *Position) LegalMovesString() string
- func (pos *Position) MoveToSan(move Move) string
- func (pos *Position) MoveToSanBatch(move Move) string
- func (pos *Position) Perft(maxDepth int, verbose bool) int
- func (pos *Position) PerftRec(depth int, maxDepth int)
- func (pos *Position) PrettyPrint()
- func (pos *Position) PrettyPrintString() string
- func (pos *Position) Put(sq Square, pi Piece)
- func (pos *Position) Remove(sq Square, pi Piece)
- func (pos *Position) RetrieveSideToMove()
- func (pos *Position) SaveSideToMove()
- func (pos *Position) SetCastlingAbility(castle Castle)
- func (pos *Position) SetEnpassantSquare(epsq Square)
- func (pos *Position) SetFullmoveCounter(n int)
- func (pos *Position) SetHalfmoveClock(n int)
- func (pos *Position) SetSideToMove(col Color)
- func (pos *Position) String() string
- func (pos *Position) Them() Color
- func (pos *Position) ThemBb() Bitboard
- func (pos *Position) ThreeFoldRepetition() int
- func (pos *Position) UCIToMove(s string) (Move, error)
- func (pos *Position) UndoMove()
- func (pos *Position) UndoMoveSafe()
- func (pos *Position) Us() Color
- func (pos *Position) UsBb() Bitboard
- func (pos *Position) Verify() error
- func (pos *Position) WhereIsKing(color Color) Square
- func (pos *Position) WhereIsOurKing() Square
- func (pos *Position) WhereTheirKing() Square
- func (pos *Position) Zobrist() uint64
- type Square
Constants ¶
const ( NoColor Color = iota // 0 Black // 1 White // 2 ColorArraySize = int(iota) // 3 ColorMinValue = Black ColorMaxValue = White )
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 )
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 )
const ALLOW_SENTRY_PUSH = true
const BaseLancer = LancerMinValue
const BaseLancerFigure = Figure(LancerMinValue)
const LANCER_DIRECTION_MASK = 0b111
lancer direction mask
const LANCER_MASK = 0b11000
lancer mask
const MOVE_CAPTURE_SHIFT = MOVE_TARGET_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 24
const MOVE_FROM_SHIFT = 0
constants for recording the shifts of move representation parts
const MOVE_PIECE_SHIFT = MOVE_CAPTURE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 28
const MOVE_PROMOTION_CAPTURE_SHIFT = MOVE_PROMOTION_SQUARE_SHIFT + SQUARE_SIZE_IN_BITS // new
const MOVE_PROMOTION_SQUARE_SHIFT = MOVE_PIECE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // new
const MOVE_TARGET_SHIFT = MOVE_TYPE_SHIFT + PIECE_ARRAY_SIZE_IN_BITS // originally 20
const MOVE_TO_SHIFT = SQUARE_SIZE_IN_BITS // originally 8
const MOVE_TYPE_SHIFT = MOVE_TO_SHIFT + SQUARE_SIZE_IN_BITS // originally 16
const NO_SQUARE = Square(0)
NO_SQUARE to be used as a square argument where there is no need to supply a square
const NUM_LANCER_DIRECTIONS = 8
const (
NullMove = Move(0)
)
const PIECE_ARRAY_SIZE_IN_BITS = 6
PIECE_ARRAY_SIZE_IN_BITS tells how many bits to use for representing a piece
const PIECE_MASK = (1 << PIECE_ARRAY_SIZE_IN_BITS) - 1
piece mask
const SQUARE_MASK = SquareArraySize - 1
square mask
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 ¶
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 -" )
var FigureToSymbol = []string{
".",
"p",
"n",
"b",
"r",
"q",
"k",
"l",
"ln",
"lne",
"le",
"lse",
"ls",
"lsw",
"lw",
"lnw",
"s",
"j",
}
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
var LancerDirectionMasksForSquares [SquareArraySize][NUM_LANCER_DIRECTIONS]Bitboard
LancerDirectionMasksForSquares maps squares and lancer directions to lancer attack masks
var PROMOTION_FIGURES_VIOLENT = []Figure{ Queen, LancerN, LancerNE, LancerE, LancerSE, LancerS, LancerSW, LancerW, LancerNW, }
var SymbolToFigureMap map[string]Figure
SymbolToFigureMap is a mapping from symbol to figure
Functions ¶
func CastlingRook ¶
CastlingRook returns the rook moved during castling together with starting and stopping squares
func FormatCastlingAbility ¶
FormatCastlingAbility returns a string specifying the castling ability using standard FEN format
func FormatEnpassantSquare ¶
FormatEnpassantSquare converts position's castling ability to string
func FormatPiecePlacement ¶
FormatPiecePlacement converts a position to FEN piece placement
func FormatSideToMove ¶
FormatSideToMove returns "w" for white to play or "b" for black to play
func HomeRank ¶
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 ¶
NormalizedDelta returns the normalized delta of the move if the move is one of queen attacks returns an error otherwise
func ParseCastlingAbility ¶
ParseCastlingAbility sets castling ability for pos from str
func ParseEnpassantSquare ¶
ParseEnpassantSquare parses the en passant square from str
func ParsePiecePlacement ¶
ParsePiecePlacement parse pieces from str (FEN like) into pos
func ParseSideToMove ¶
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
func BackwardFill ¶
BackwardFill computes forward fill wrt color
func BackwardPawns ¶
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 ¶
BackwardSpan computes backward span wrt color
func BishopMobility ¶
BishopMobility returns the squares a bishop can reach from sq given all pieces
func ConnectedPawns ¶
ConnectedPawns returns a bitboad with our connected pawns
func DoubledPawns ¶
DoubledPawns returns a bitboard with our doubled pawns
func ForwardFill ¶
ForwardFill computes forward fill wrt color.
func ForwardSpan ¶
ForwardSpan computes forward span wrt color.
func IsolatedPawns ¶
IsolatedPawns returns a bitboard with our isolated pawns
func JailerMobility ¶
JailerMobility returns the squares a jailer can reach from sq given all pieces
func KingMobility ¶
KingMobility returns all squares a king can reach from sq doesn't include castling
func Kings ¶
Kings return the set of kings of the given color normally there is exactly on king for each side
func KnightMobility ¶
KnightMobility returns all squares a knight can reach from sq
func LancerMobility ¶
LancerMobility returns all squares the lancer of color us and of direction ld can reach from sq
func MinorsAndMajors ¶
MinorsAndMajors returns a bitboard with minor and major pieces
func PassedPawns ¶
PassedPawns returns a bitboard with our passed pawns
func PawnThreats ¶
PawnThreats returns the squares threatened by our pawns
func QueenMobility ¶
QueenMobility returns the squares a queen can reach from sq given all pieces
func RammedPawns ¶
RammedPawns returns pawns on ranks 2, 3 for white and rank 6 and 7 blocking an advanced enemy pawn
func RookMobility ¶
RookMobility returns the squares a rook can reach from sq given all pieces
func SemiOpenFiles ¶
SemiOpenFiles returns our fully set files with enemy pawns, but no friendly pawns
func SuperQueenMobility ¶
SuperQueenMobility returns the squares a queen can reach from sq on an empty board
func (Bitboard) AsSquare ¶
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.ir/pkg/math/bits/#TrailingZeros64
func (Bitboard) Count ¶
count returns the number of squares set in bb https://golang.ir/pkg/math/bits/#OnesCount64
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 )
type Color ¶
type Color uint
Color represents a side
func (Color) Multiplier ¶
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
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 ¶
SymbolToFigure returns the Figure for the symbol
func (Figure) AlgebLetter ¶
Figure.AlgebLetter returns the algeb letter of the figure ( lower case ) for lancer direction is omitted
func (Figure) BaseFigure ¶
Figure.BaseFigure returns the base figure of the figure apart from lancer it is the same as figure
func (Figure) LancerDirection ¶
Figure.LancerDirection determines the lancer direction of the figure figure has to be a lancer
func (Figure) SanLetter ¶
Figure.SanLetter returns the san letter of the figure ( upper case ) for lancer direction is omitted
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 ¶
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) CaptureSquare ¶
CaptureSquare returns the captured piece square if no piece is captured, the result is the destination square
func (Move) IsViolent ¶
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 ¶
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) PromotionCapture ¶
PromotionCapture returns the promotion capture of the move
func (Move) PromotionSquare ¶
PromotionSquare returns the promotion square of the move
func (Move) UCI ¶
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 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 ¶
MoveBuffItem hold a move together with its SAN and algebraic representation
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 ¶
ColorFigure returns a piece with col and fig
func MakeLancer ¶
MakeLancer creates a lancer piece from color and direction
func SymbolToPiece ¶
SymbolToPiece returns the Piece for the symbol
func (Piece) AlgebLetter ¶
Piece.AlgebLetter returns the algeb letter of the piece ( upper case ) convenience function
func (Piece) AlgebSymbol ¶
AlgebSymbol returns the algebraic symbol of the piece
func (Piece) BaseFigure ¶
Piece.BaseFigure returns the base figure of the piece convenience function
func (Piece) ColorInverse ¶
ColorInverse returns the color inverse of the piece
func (Piece) FenSymbol ¶
FenSymbol returns the fen symbol of the piece ( letter case depends on color )
func (Piece) LancerDirection ¶
Piece.LancerDirection determines the lancer direction of the piece convenience function
func (Piece) PrettySymbol ¶
PrettySymbol returns the pretty print symbol of the piece
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 ¶
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 ¶
AppendMove appends a move to a move list if the move is a disabled move, it does nothing
func (*Position) CastlingAbility ¶
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) EnpassantSquare ¶
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 ¶
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 ¶
FormatDisabledMove formats disabled move as FEN field
func (*Position) FullmoveCounter ¶
FullmoveCounter returns the number of full moves, starts from 1
func (*Position) GenerateFigureMoves ¶
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 ¶
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) GetAttacker ¶
GetAttacker returns the smallest figure of color them that attacks sq
func (*Position) GivesCheck ¶
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 ¶
HalfmoveClock returns the number of halfmoves since the last capture or pawn advance
func (*Position) HasLegalMoves ¶
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 ¶
InsufficientMaterial returns true if the position is theoretical draw
func (*Position) InvertSideToMove ¶
func (pos *Position) InvertSideToMove()
InvertSideToMove inverts the side to move
func (*Position) IsEnpassantSquare ¶
IsEnpassantSquare returns true if sq is the en passant square
func (*Position) IsKingJailed ¶
IsKingJailed tells whether king is jailed for color
func (*Position) IsOurKingJailed ¶
IsOurKingJailed tells whether our king is jailed
func (*Position) IsPseudoLegal ¶
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 ¶
IsSquareEmpty tells whether a square is empty
func (*Position) IsSquareJailedForColor ¶
IsSquareJailedForColor tells whether a square is jailed for color
func (*Position) IsSquareJailedForThem ¶
IsSquareJailedForThem tells whether a square is jailed for them
func (*Position) IsSquareJailedForUs ¶
IsSquareJailedForUs tells whether a square is jailed for us
func (*Position) IsTheirKingJailed ¶
IsTheirKingJailed tells whether their king is jailed
func (*Position) JailedForColor ¶
JailedForColor tells squares jailed for color
func (*Position) JailedForThem ¶
JailedForThem tells squares jailed for them
func (*Position) JailedForUs ¶
JailedForUs tells squares jailed for us
func (*Position) LegalMoves ¶
LegalMoves returns all legal moves from the position
func (*Position) LegalMovesString ¶
LegalMovesString lists the legal moves fromt the position numbered and sorted by SAN as string
func (*Position) MoveToSanBatch ¶
MoveToSanBatch returns the move in SAN notation provided that InitMoveToSan was called for the position
func (*Position) PrettyPrint ¶
func (pos *Position) PrettyPrint()
PrettyPrint pretty prints the current position
func (*Position) PrettyPrintString ¶
PrettyPrint pretty prints the current position to string
func (*Position) Put ¶
put puts a piece on the board does nothing if pi is NoPiece, does not validate input
func (*Position) Remove ¶
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 ¶
SetCastlingAbility sets the side to move, correctly updating the Zobrist key
func (*Position) SetEnpassantSquare ¶
SetEnpassantSquare sets the en passant square correctly updating the Zobrist key
func (*Position) SetFullmoveCounter ¶
SetFullmoveCounter sets the number of full moves
func (*Position) SetHalfmoveClock ¶
SetHalfmoveClock sets the number of halfmoves since the last capture or pawn advance
func (*Position) SetSideToMove ¶
SetSideToMove sets the side to move, correctly updating the Zobrist key
func (*Position) ThreeFoldRepetition ¶
ThreeFoldRepetition returns whether current position was seen three times already returns minimum between 3 and the actual number of repetitions
func (*Position) UCIToMove ¶
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 ¶
Us returns the current player to move Us/Them is based on Glaurung terminology
func (*Position) Verify ¶
verify checks the validity of the position mostly used for debugging purposes
func (*Position) WhereIsKing ¶
WhereIsKing tells the position of the king for color
func (*Position) WhereIsOurKing ¶
WhereIsOurKing tells the position of our king
func (*Position) WhereTheirKing ¶
WhereIsTheirKing tells the position of their king
type Square ¶
type Square uint
square identifies the location on the board
func PawnPromotionSquare ¶
PawnPromotionSquare returns the propotion square of a col pawn on sq undefined behaviour if col is not White or Black
func SquareFromString ¶
SquareFromString parses a square from a string the string has standard chess format [a-h][1-8]
func (Square) POV ¶
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