dragontoothmg is a fast chess legal move generator library based on magic bitboards.
- 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
const Startpos = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
The starting position FEN
This section is empty.
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).
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.
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.
Performs the Perft move count division operation. Useful for debugging.
func IndexToAlgebraic ¶
Accepts a Dragontooth Square ID, and converts it to an algebraic square.
Contains bitboard representations of all the pieces for a side.
The board type, which uses little-endian rank-file mapping.
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.
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.
type Move uint16
Move bitwise structure; internal implementation is private.
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
type Piece uint8
Piece types; valid in range 0-6, as indicated by the constants for each piece.
This FEN parsing implementation doesn't handle malformed inputs.