public IEnumerable <IMove> GetLegalMoves(ushort squareIndex, ulong[][] occupancy, ushort?enPassantIdx, CastlingAvailability castlingAvailability) { var pieceOfColor = occupancy.GetPieceOfColorAtIndex(squareIndex); if (pieceOfColor == null) { yield break; } var piece = pieceOfColor.Value.Piece; var color = pieceOfColor.Value.Color; var relevantOccupancy = occupancy.Occupancy(); if (piece == Piece.Pawn && enPassantIdx.HasValue) { var epValue = enPassantIdx.Value.GetBoardValueOfIndex(); relevantOccupancy |= epValue; } var pseudoLegalMoves = GetPseudoLegalMoves(squareIndex, piece, color, relevantOccupancy); var moves = new List <IMove>(); foreach (var destinationIndex in pseudoLegalMoves.GetSetBits()) { var moveType = BoardHelpers.GetMoveType(occupancy, squareIndex, destinationIndex, enPassantIdx); var move = MoveHelpers.GenerateMove(squareIndex, destinationIndex, moveType); moves.Add(move); } if (piece == Piece.King && IsKingSquare(squareIndex, color)) { moves.AddRange(GetPseudoLegalCastlingMoves(color, castlingAvailability)); } foreach (var move in moves) { var moveValidator = new MoveValidator( new Board(occupancy, 0, enPassantIdx, null, castlingAvailability, color, 0, true), move); var validationResult = moveValidator.Validate(); if (validationResult == MoveError.NoneSet) { yield return(move); } } }
public MoveType GetMoveTypeTest(Board board, ushort from, ushort to, ushort?epIndex) { return(BoardHelpers.GetMoveType(board.Occupancy, (ushort)@from, (ushort)to, (ushort?)epIndex)); }