コード例 #1
0
ファイル: MoveGenerator.cs プロジェクト: wgwine/ChessGen
        public static ulong GenerateMovesForPieceBitboard(int piece, int[] board)
        {
            PieceType pt = Util.GetPieceType(piece);

            switch (pt)
            {
            case PieceType.Pawn:
                return(PawnMoveGenerator.PossiblePositionsBitboard(piece, board));

            case PieceType.Night:
                return(KnightMoveGenerator.PossiblePositionsBitboard(piece, board));

            case PieceType.Bishop:
                return(BishopMoveGenerator.PossiblePositionsBitboard(piece, board));

            case PieceType.Rook:
                return(RookMoveGenerator.PossiblePositionsBitboard(piece, board));

            case PieceType.Queen:
                return(QueenMoveGenerator.PossiblePositionsBitboard(piece, board));

            case PieceType.King:
                return(KingMoveGenerator.PossiblePositionsBitboard(piece, board));

            default:
                break;
            }
            return(0);
        }
コード例 #2
0
ファイル: MoveGenerator.cs プロジェクト: wgwine/ChessGen
        public static List <Move> GenerateMovesForPiece(int piece, int[] board)
        {
            PieceType   pt     = Util.GetPieceType(piece);
            List <int>  temp   = new List <int>();
            List <Move> result = new List <Move>();

            switch (pt)
            {
            case PieceType.Pawn:
                temp = PawnMoveGenerator.PossiblePositions(piece, board);
                break;

            case PieceType.Night:
                temp = KnightMoveGenerator.PossiblePositions(piece, board);
                break;

            case PieceType.Bishop:
                temp = BishopMoveGenerator.PossiblePositions(piece, board);
                break;

            case PieceType.Rook:
                temp = RookMoveGenerator.PossiblePositions(piece, board);
                break;

            case PieceType.Queen:
                temp = QueenMoveGenerator.PossiblePositions(piece, board);
                break;

            case PieceType.King:
                temp = KingMoveGenerator.PossiblePositions(piece, board);
                break;

            default:
                break;
            }

            foreach (int m in temp)
            {
                result.Add(new Move(piece, m));
            }
            return(result);
        }
コード例 #3
0
        //generate bitboard of moves
        public static ulong PseudomoveBitboard(int piece, int[] board)
        {
            bool  isWhite   = Util.IsWhite(piece);
            int   position  = Util.GetPieceOffset(piece);
            int   positionX = Util.GetXForPosition(position);
            int   positionY = Util.GetYForPosition(position);
            ulong result    = 0;
            ulong one       = 1;

            if (isWhite)
            {
                if (positionY < 6)
                {
                    if (board[position + 8] == 0)
                    {
                        result |= (one << (position + 8));
                    }

                    //captures
                    if (positionX > 0)
                    {
                        result |= (one << (position + 7));
                    }

                    if (positionX < 7)
                    {
                        result |= (one << (position + 9));
                    }
                    //initial double move
                    if (positionY == 1)
                    {
                        result |= (one << (position + (2 * 8)));
                    }
                }
                else if (positionY == 6)
                {
                    //pawn promotion
                    result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('Q') + position + 8));

                    if (positionX > 0)
                    {
                        result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('Q') + position + 7));
                    }

                    if (positionX < 7)
                    {
                        result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('Q') + position + 9));
                    }
                }
            }
            else
            {
                if (positionY > 1)
                {
                    if (board[position - 8] == 0)
                    {
                        result |= (one << (position - 8));
                    }

                    //captures
                    if (positionX < 7)
                    {
                        result |= (one << (position - 7));
                    }

                    if (positionX > 0)
                    {
                        result |= (one << (position - 9));
                    }

                    //initial double move
                    if (positionY == 6)
                    {
                        result |= (one << (position - (2 * 8)));
                    }
                }
                else if (positionY == 1)
                {
                    //pawn promotion
                    result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('q') + position - 8));

                    if (positionX < 7)
                    {
                        result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('q') + position - 7));
                    }

                    if (positionX > 0)
                    {
                        result |= QueenMoveGenerator.PseudomoveBitboard((PieceTypeFENMap.PieceValue('q') + position - 9));
                    }
                }
            }

            return(result);
        }