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 GetPieceType(square uint8, b *Board) (int, bool)
- func IndexToAlgebraic(id Square) string
- func IsCapture(m Move, b *Board) bool
- func Perft(b *Board, n int) int64
- type Bitboards
- type Board
- type Move
- 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) GenerateLegalMoves ¶
The main API entrypoint. Generates all legal moves for a given board.
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 ¶
Notes ¶
Bugs ¶
This FEN parsing implementation doesn't handle malformed inputs.