当前位置: 首页>>代码示例>>C#>>正文


C# Position.piece_moved方法代码示例

本文整理汇总了C#中Portfish.Position.piece_moved方法的典型用法代码示例。如果您正苦于以下问题:C# Position.piece_moved方法的具体用法?C# Position.piece_moved怎么用?C# Position.piece_moved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Portfish.Position的用法示例。


在下文中一共展示了Position.piece_moved方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: move_to_san

        /// move_to_san() takes a position and a move as input, where it is assumed
        /// that the move is a legal move for the position. The return value is
        /// a string containing the move in short algebraic notation.
        internal static string move_to_san(Position pos, Move m)
        {
            if (m == MoveC.MOVE_NONE)
                return "(none)";

            if (m == MoveC.MOVE_NULL)
                return "(null)";

            Debug.Assert(is_ok_M(m));

            Bitboard attackers;
            bool ambiguousMove, ambiguousFile, ambiguousRank;
            Square sq, from = from_sq(m);
            Square to = to_sq(m);
            PieceType pt = type_of(pos.piece_moved(m));

            StringBuilder san = new StringBuilder();

            if (is_castle(m))
                san.Append((to_sq(m) < from_sq(m) ? "O-O-O" : "O-O"));
            else
            {
                if (pt != PieceTypeC.PAWN)
                {
                    san.Append(piece_type_to_char(pt).ToString());

                    // Disambiguation if we have more then one piece with destination 'to'
                    // note that for pawns is not needed because starting file is explicit.
                    attackers = pos.attackers_to(to) & pos.pieces_PTC(pt, pos.sideToMove);
                    xor_bit(ref attackers, from);
                    ambiguousMove = ambiguousFile = ambiguousRank = false;

                    while (attackers != 0)
                    {
                        sq = pop_1st_bit(ref attackers);

                        // Pinned pieces are not included in the possible sub-set
                        if (!pos.pl_move_is_legal(make_move(sq, to), pos.pinned_pieces()))
                            continue;

                        if (file_of(sq) == file_of(from))
                            ambiguousFile = true;

                        if (rank_of(sq) == rank_of(from))
                            ambiguousRank = true;

                        ambiguousMove = true;
                    }

                    if (ambiguousMove)
                    {
                        if (!ambiguousFile)
                            san.Append(file_to_char(file_of(from)));
                        else if (!ambiguousRank)
                            san.Append(rank_to_char(rank_of(from)));
                        else
                            san.Append(square_to_string(from));
                    }
                }

                if (pos.is_capture(m))
                {
                    if (pt == PieceTypeC.PAWN)
                        san.Append(file_to_char(file_of(from)));

                    san.Append('x');
                }

                san.Append(square_to_string(to));

                if (is_promotion(m))
                {
                    san.Append('=');
                    san.Append(piece_type_to_char(promotion_type(m)));
                }
            }

            CheckInfo ci = CheckInfoBroker.GetObject();
            ci.CreateCheckInfo(pos);
            if (pos.move_gives_check(m, ci))
            {
                StateInfo st = new StateInfo();
                pos.do_move(m, st);
                MList mlist = MListBroker.GetObject(); mlist.pos = 0;
                Movegen.generate_legal(pos, mlist.moves, ref mlist.pos);
                san.Append(mlist.pos > 0 ? "+" : "#");
                MListBroker.Free();
                pos.undo_move(m);
            }
            CheckInfoBroker.Free();

            return san.ToString();
        }
开发者ID:stevemulligan,项目名称:Portfish,代码行数:96,代码来源:Utils.cs

示例2: search


//.........这里部分代码省略.........
                        ss[ssPos].skipNullMove = 0;
                        ss[ssPos].excludedMove = MoveC.MOVE_NONE;
                        if (value < rBeta)
                            ext = DepthC.ONE_PLY;
                    }
                }

                // Update current move (this must be done after singular extension search)
                newDepth = depth - DepthC.ONE_PLY + ext;

                // Step 13. Futility pruning (is omitted in PV nodes)
                if (!PvNode && !inCheck
                    && !captureOrPromotion
                    && !dangerous
                    && move != ttMove
                    && (bestValue > ValueC.VALUE_MATED_IN_MAX_PLY || bestValue == -ValueC.VALUE_INFINITE)
                    && !Utils.is_castle(move))
                {
                    // Move count based pruning
                    if (moveCount >= futility_move_count(depth)
                        && ((threatMove == 0) || !connected_threat(pos, move, threatMove)))
                    {
                        if (SpNode)
                            ThreadHelper.lock_grab(sp.Lock);

                        continue;
                    }

                    // Value based pruning
                    // We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
                    // but fixing this made program slightly weaker.
                    Depth predictedDepth = newDepth - reduction(PvNode, depth, moveCount);
                    futilityValue = futilityBase + futility_margin(predictedDepth, moveCount)
                                                 + H.gain(pos.piece_moved(move), Utils.to_sq(move));

                    if (futilityValue < beta)
                    {
                        if (SpNode)
                            ThreadHelper.lock_grab(sp.Lock);

                        continue;
                    }

                    // Prune moves with negative SEE at low depths
                    if (predictedDepth < 2 * DepthC.ONE_PLY
                        && pos.see(move, true) < 0)
                    {
                        if (SpNode)
                            ThreadHelper.lock_grab(sp.Lock);

                        continue;
                    }
                }

                // Check for legality only before to do the move
                if (!pos.pl_move_is_legal(move, ci.pinned))
                {
                    moveCount--;
                    continue;
                }

                ss[ssPos].currentMove = move;
                if (!SpNode && !captureOrPromotion && playedMoveCount < 64)
                    movesSearched[playedMoveCount++] = move;

                // Step 14. Make the move
开发者ID:stevemulligan,项目名称:Portfish,代码行数:67,代码来源:Search.cs

示例3: search


//.........这里部分代码省略.........
                        ext = DepthC.ONE_PLY;
                    }
                }

                // Update current move (this must be done after singular extension search)
                newDepth = depth - DepthC.ONE_PLY + ext;

                // Step 13. Futility pruning (is omitted in PV nodes)
                if (!PvNode
                    && !captureOrPromotion
                    && !inCheck 
                    && !dangerous 
                    && move != ttMove
                    && (bestValue > ValueC.VALUE_MATED_IN_MAX_PLY || (bestValue == -ValueC.VALUE_INFINITE && alpha > ValueC.VALUE_MATED_IN_MAX_PLY)))
                {
                    // Move count based pruning
                    if (depth < 16 * DepthC.ONE_PLY
                        && moveCount >= FutilityMoveCounts[depth]
                        && ((threatMove == 0) || !refutes(pos, move, threatMove)))
                    {
                        if (SpNode)
                        {
                            ThreadHelper.lock_grab(sp.Lock);
                        }

                        continue;
                    }

                    // Value based pruning
                    // We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
                    // but fixing this made program slightly weaker.
                    var predictedDepth = newDepth - reduction(PvNode, depth, moveCount);
                    futilityValue = ss[ssPos].staticEval + ss[ssPos].evalMargin + futility_margin(predictedDepth, moveCount)
                                    + H.gain(pos.piece_moved(move), Utils.to_sq(move));

                    if (futilityValue < beta)
                    {
                        if (SpNode)
                        {
                            ThreadHelper.lock_grab(sp.Lock);
                        }

                        continue;
                    }

                    // Prune moves with negative SEE at low depths
                    if (predictedDepth < 2 * DepthC.ONE_PLY && pos.see(move, true) < 0)
                    {
                        if (SpNode)
                        {
                            ThreadHelper.lock_grab(sp.Lock);
                        }

                        continue;
                    }
                }

                // Check for legality only before to do the move
                if (!RootNode && !SpNode && !pos.pl_move_is_legal(move, ci.pinned))
                {
                    moveCount--;
                    continue;
                }

                pvMove = (PvNode && moveCount == 1);
                ss[ssPos].currentMove = move;
开发者ID:torfranz,项目名称:Portfish,代码行数:67,代码来源:Search.cs

示例4: check_is_dangerous

        // check_is_dangerous() tests if a checking move can be pruned in qsearch().
        // bestValue is updated only when returning false because in that case move
        // will be pruned.
        static bool check_is_dangerous(Position pos, Move move, Value futilityBase, Value beta)
        {
            Bitboard b, occ, oldAtt, newAtt, kingAtt;
            Square from, to, ksq;
            Piece pc;
            Color them;

            from = Utils.from_sq(move);
            to = Utils.to_sq(move);
            them = Utils.flip_C(pos.sideToMove);
            ksq = pos.king_square(them);
            kingAtt = Position.attacks_from_KING(ksq);
            pc = pos.piece_moved(move);

            occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
            oldAtt = Position.attacks_from(pc, from, occ);
            newAtt = Position.attacks_from(pc, to, occ);

            // Rule 1. Checks which give opponent's king at most one escape square are dangerous
            b = kingAtt & ~pos.pieces_C(them) & ~newAtt & ~(1UL << to);

            if ((b & (b - 1)) == 0) // Catches also !b
                return true;

            // Rule 2. Queen contact check is very dangerous
            if (Utils.type_of(pc) == PieceTypeC.QUEEN
                && (Utils.bit_is_set(kingAtt, to) != 0))
                return true;

            // Rule 3. Creating new double threats with checks
            b = pos.pieces_C(them) & newAtt & ~oldAtt & ~(1UL << ksq);

            while (b != 0)
            {
                // Note that here we generate illegal "double move"!
                if (futilityBase + Position.PieceValueEndgame[pos.piece_on(Utils.pop_1st_bit(ref b))] >= beta)
                    return true;
            }
            return false;
        }
开发者ID:stevemulligan,项目名称:Portfish,代码行数:43,代码来源:Search.cs

示例5: check_is_dangerous

        // check_is_dangerous() tests if a checking move can be pruned in qsearch().
        // bestValue is updated only when returning false because in that case move
        // will be pruned.
        private static bool check_is_dangerous(Position pos, int move, int futilityBase, int beta)
        {
            //ulong b, occ, oldAtt, newAtt, kingAtt;
            //int from, to, ksq;
            //int pc;
            //int them;

            //from = Utils.from_sq(move);
            //to = Utils.to_sq(move);
            //them = Utils.flip_C(pos.sideToMove);
            //ksq = pos.king_square(them);
            //kingAtt = Position.attacks_from_KING(ksq);
            //pc = pos.piece_moved(move);

            //occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
            //oldAtt = Position.attacks_from(pc, from, occ);
            //newAtt = Position.attacks_from(pc, to, occ);

            //// Rule 1. Checks which give opponent's king at most one escape square are dangerous
            //b = kingAtt & ~pos.pieces_C(them) & ~newAtt & ~(1UL << to);

            //if ((b & (b - 1)) == 0) // Catches also !b
            Piece pc = pos.piece_moved(move);
            Square from = Utils.from_sq(move);
            Square to = Utils.to_sq(move);
            Color them = pos.sideToMove ^ 1;
            Square ksq = pos.king_square(them);
            Bitboard enemies = pos.pieces_C(them);
            Bitboard kingAtt = Position.attacks_from_KING(ksq);
            Bitboard occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
            Bitboard oldAtt = Position.attacks_from(pc, from, occ);
            Bitboard newAtt = Position.attacks_from(pc, to, occ);

            // Checks which give opponent's king at most one escape square are dangerous
            if (!Utils.more_than_one(kingAtt & ~(enemies | newAtt | (ulong)to)))
            {
                return true;
            }

            // Queen contact check is very dangerous
            if (Utils.type_of(pc) == PieceTypeC.QUEEN && (Utils.bit_is_set(kingAtt, to) != 0))
            {
                return true;
            }

            // Creating new double threats with checks is dangerous
            Bitboard b = (enemies ^ (ulong)ksq) & newAtt & ~oldAtt;
            while (b != 0)
            {
                // Note that here we generate illegal "double move"!
                if (futilityBase + Position.PieceValue[PhaseC.EG][pos.piece_on(Utils.pop_lsb(ref b))] >= beta)
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:torfranz,项目名称:Portfish,代码行数:60,代码来源:Search.cs


注:本文中的Portfish.Position.piece_moved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。