Example #1
0
        static public List <int> GetPossibleMoveList(PositionManager board, int square, bool isPlayer)
        {
            List <int> moveList = new List <int>();
            ulong      bitboard = GetPossibleMoveBitboard(board, square);

            for (int i = 0; i < 64; i++)
            {
                if ((bitboard & Util.GetBitBoardFromSquare(i)) != 0)
                {
                    if (isPlayer) //"Check" control for player only to improve ai speed
                    {
                        PositionManager fictionnalBoard = new PositionManager(board);
                        fictionnalBoard.MovePiece(square, i);
                        if (!fictionnalBoard.IsCheck())
                        {
                            moveList.Add(i);
                        }
                    }
                    else
                    {
                        moveList.Add(i);
                    }
                }
            }
            return(moveList);
        }
Example #2
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 #3
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);
        }
Example #4
0
 public PositionManager(PositionManager pm) //create a copy
 {
     this.blackPositions = new Dictionary <PieceEnum, ulong>(pm.blackPositions);
     this.whitePositions = new Dictionary <PieceEnum, ulong>(pm.whitePositions);
 }