Documentation
¶
Overview ¶
dragontoothmg is a fast chess legal move generator library based on magic bitboards.
Index ¶
- Constants
- func AlgebraicToIndex(alg string) (uint8, error)
- func CalculateBishopMoveBitboard(currBishop uint8, allPieces uint64) uint64
- func CalculateRookMoveBitboard(currRook uint8, allPieces uint64) uint64
- func Divide(b *Board, n int)
- func IndexToAlgebraic(id Square) string
- func IsCapture(m Move, b *Board) bool
- func Perft(b *Board, n int) int64
- type Bitboards
- type Board
- func (b *Board) Apply(m Move) func()
- func (b *Board) Apply2(m Move) *MoveApplication
- func (b *Board) ApplyNullMove() func()
- func (b *Board) Enpassant() uint8
- func (b *Board) GenerateLegalMoves() []Move
- func (b *Board) GenerateLegalMoves2(onlyCapturesPromosCheckEvasion bool) ([]Move, bool)
- func (b *Board) Hash() uint64
- func (b *Board) OurKingInCheck() bool
- func (b *Board) PieceAt(pos uint8) Piece
- func (b *Board) ToFen() string
- func (b *Board) UnderDirectAttack(byBlack bool, origin uint8) bool
- type Move
- type MoveApplication
- type Piece
- type Square
- Bugs
Constants ¶
const ( Nothing = iota Pawn = iota Knight = iota // list before bishop for promotion loops Bishop = iota Rook = iota Queen = iota King = iota )
const Startpos = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
The starting position FEN
Variables ¶
This section is empty.
Functions ¶
func AlgebraicToIndex ¶
Accepts an algebraic notation chess square, and converts it to a square ID as used by Dragontooth (in both the board and move types).
func CalculateBishopMoveBitboard ¶
Calculates the attack bitboard for a bishop. This might include targeted squares that are actually friendly pieces, so the proper usage is: bishopTargets := CalculateBishopMoveBitboard(myBishopLoc, allPieces) & (^myPieces) Externally useful for evaluation functions.
func CalculateRookMoveBitboard ¶
Calculates the attack bitboard for a rook. This might include targeted squares that are actually friendly pieces, so the proper usage is: rookTargets := CalculateRookMoveBitboard(myRookLoc, allPieces) & (^myPieces) Externally useful for evaluation functions.
func IndexToAlgebraic ¶
Accepts a Dragontooth Square ID, and converts it to an algebraic square.
Types ¶
type Bitboards ¶
type Bitboards struct {
Pawns uint64
Bishops uint64
Knights uint64
Rooks uint64
Queens uint64
Kings uint64
All uint64
}
Contains bitboard representations of all the pieces for a side.
type Board ¶
type Board struct {
Wtomove bool
Halfmoveclock uint8
Fullmoveno uint16
White Bitboards
Black Bitboards
// contains filtered or unexported fields
}
The board type, which uses little-endian rank-file mapping.
func (*Board) Apply ¶
Applies a move to the board, and returns a function that can be used to unapply it. This function assumes that the given move is valid (i.e., is in the set of moves found by GenerateLegalMoves()). If the move is not valid, this function has undefined behavior.
func (*Board) Apply2 ¶
func (b *Board) Apply2(m Move) *MoveApplication
Applies a move to the board, and returns move application information and a function that can be used to unapply it. This function assumes that the given move is valid (i.e., is in the set of moves found by GenerateLegalMoves()). If the move is not valid, this function has undefined behavior.
func (*Board) ApplyNullMove ¶
func (b *Board) ApplyNullMove() func()
Applies a null move to the board, and returns a function that can be used to unapply it. A null move is just that - the current player skips his move. Used for Null Move Heuristic in the search engine.
func (*Board) GenerateLegalMoves ¶
The main API entrypoint. Generates all legal moves for a given board.
func (*Board) GenerateLegalMoves2 ¶
The main API entrypoint. Generates legal moves for a given board,
either all moves (onlyCapturesPromosCheckEvasion == false), or limited to captures, promotions, and check evasion for quiescence search.
Return moves, isInCheck
func (*Board) Hash ¶
Return the Zobrist hash value for the board. The hash value does NOT change with the turn number, nor the draw move counter. All other elements of the Board type affect the hash. This function is cheap to call, since the hash is incrementally updated.
func (*Board) OurKingInCheck ¶
type Move ¶
type Move uint16
Move bitwise structure; internal implementation is private.
func ParseMove ¶
Some example valid move strings: e1e2 b4d6 e7e8q a2a1n TODO(dylhunn): Make the parser more forgiving. Eg: 0-0, O-O-O, a2-a3, D3D4
func (*Move) Setpromote ¶
type MoveApplication ¶
type MoveApplication struct {
Unapply func()
FromPieceType Piece
ToPieceType Piece // Different from fromPieceType only for promotions
CapturedPieceType Piece // Nothing if this is not a capture
CaptureLocation uint8
IsCastling bool
RookCastleFrom uint8 // Only valid if IsCastling
RookCastleTo uint8 // Only valid if IsCastling
}
Move application data
Notes ¶
Bugs ¶
This FEN parsing implementation doesn't handle malformed inputs.
