Example #1
0
        static public ulong GetPossibleMoveBitboard(PositionManager board, int square)
        {
            ulong positionBitboard = Util.GetBitBoardFromSquare(square);

            foreach (PieceEnum type in (PieceEnum[])Enum.GetValues(typeof(PieceEnum)))
            {
                if ((board.whitePositions[type] & positionBitboard) != 0 || (board.blackPositions[type] & positionBitboard) != 0)
                {
                    ulong alliedPositions;
                    if ((board.whitePositions[type] & positionBitboard) != 0)
                    {
                        alliedPositions = board.GetAllWhite();
                    }
                    else
                    {
                        alliedPositions = board.GetAllBlack();
                    }

                    switch (type)
                    {
                    case PieceEnum.Pawn:
                        if ((board.whitePositions[type] & positionBitboard) != 0)
                        {
                            return(whitePawnMoveboards[square][GetWhitePawnIndexFromBoard(board.GetAll(), square)] & ~alliedPositions);
                        }
                        else
                        {
                            return(blackPawnMoveboards[square][GetBlackPawnIndexFromBoard(board.GetAll(), square)] & ~alliedPositions);
                        }

                    case PieceEnum.Knight:
                        return(pieceMovements[PieceEnum.Knight][square] & ~alliedPositions);

                    case PieceEnum.Bishop:
                        return(bishopMoveboards[square][GetBishopIndexFromBoard(board.GetAll(), square)] & ~alliedPositions);

                    case PieceEnum.Rook:
                        return(rookMoveboards[square][GetRookIndexFromBoard(board.GetAll(), square)] & ~alliedPositions);

                    case PieceEnum.Queen:
                        return((bishopMoveboards[square][GetBishopIndexFromBoard(board.GetAll(), square)] | rookMoveboards[square][GetRookIndexFromBoard(board.GetAll(), square)]) & ~alliedPositions);

                    case PieceEnum.King:
                        return(pieceMovements[PieceEnum.King][square] & ~alliedPositions);

                    default:
                        break;
                    }
                }
            }

            return(0);
        }
Example #2
0
        static public List <(int, int)> GetAllPossibleMoves(PositionManager board, bool isPlayer, bool isFalsePlayer)
        {
            List <(int, int)> allPossibleMoves = new List <(int, int)>();

            ulong alliedPositions = (isPlayer || isFalsePlayer) ? board.GetAllWhite() : board.GetAllBlack();

            for (int i = 63; i >= 0; i--)
            {
                if ((alliedPositions & 1UL) == 1)
                {
                    List <int> possibleMoves = MoveManager.GetPossibleMoveList(board, i, isPlayer);
                    foreach (int target in possibleMoves)
                    {
                        allPossibleMoves.Add((i, target));
                    }
                }
                alliedPositions = alliedPositions >> 1;
            }

            return(allPossibleMoves);
        }