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


C# Position.is_capture_or_promotion方法代码示例

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


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

示例1: search


//.........这里部分代码省略.........
            // in this case return a fail-high score.
            if (!RootNode)
            {
                alpha = Math.Max(Utils.mated_in(ss[ssPos].ply), alpha);
                beta = Math.Min(Utils.mate_in(ss[ssPos].ply + 1), beta);
                if (alpha >= beta)
                {
                    MovesSearchedBroker.Free();
                    return alpha;
                }
            }

            // Step 4. Transposition table lookup
            // We don't want the score of a partial search to overwrite a previous full search
            // TT value, so we use a different position key in case of an excluded move.
            excludedMove = ss[ssPos].excludedMove;
            posKey = (excludedMove != 0) ? pos.exclusion_key() : pos.key();
            tteHasValue = TT.probe(posKey, ref ttePos, out tte);
            ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tteHasValue ? tte.move() : MoveC.MOVE_NONE;
            ttValue = tteHasValue ? value_from_tt(tte.value(), ss[ssPos].ply) : ValueC.VALUE_ZERO;

            // At PV nodes we check for exact scores, while at non-PV nodes we check for
            // a fail high/low. Biggest advantage at probing at PV nodes is to have a
            // smooth experience in analysis mode. We don't probe at Root nodes otherwise
            // we should also update RootMoveList to avoid bogus output.
            if (!RootNode && tteHasValue && (PvNode ? tte.depth() >= depth && tte.type() == Bound.BOUND_EXACT
                                            : can_return_tt(tte, depth, ttValue, beta)))
            {
                TT.entries[ttePos].set_generation(TT.generation);
                ss[ssPos].currentMove = ttMove; // Can be MOVE_NONE

                if (ttValue >= beta
                    && (ttMove != 0)
                    && !pos.is_capture_or_promotion(ttMove)
                    && ttMove != ss[ssPos].killers0)
                {
                    ss[ssPos].killers1 = ss[ssPos].killers0;
                    ss[ssPos].killers0 = ttMove;
                }

                MovesSearchedBroker.Free();
                return ttValue;
            }

            // Step 5. Evaluate the position statically and update parent's gain statistics
            if (inCheck)
                ss[ssPos].eval = ss[ssPos].evalMargin = ValueC.VALUE_NONE;
            else if (tteHasValue)
            {
                Debug.Assert(tte.static_value() != ValueC.VALUE_NONE);
                ss[ssPos].eval = tte.static_value();
                ss[ssPos].evalMargin = tte.static_value_margin();
                refinedValue = refine_eval(tte, ttValue, ss[ssPos].eval);
            }
            else
            {
                refinedValue = ss[ssPos].eval = Evaluate.do_evaluate(false, pos, ref ss[ssPos].evalMargin);
                TT.store(posKey, ValueC.VALUE_NONE, Bound.BOUND_NONE, DepthC.DEPTH_NONE, MoveC.MOVE_NONE, ss[ssPos].eval, ss[ssPos].evalMargin);
            }

            // Update gain for the parent non-capture move given the static position
            // evaluation before and after the move.
            if ((move = ss[ssPos - 1].currentMove) != MoveC.MOVE_NULL
                && ss[ssPos - 1].eval != ValueC.VALUE_NONE
                && ss[ssPos].eval != ValueC.VALUE_NONE
                && (pos.captured_piece_type() == 0)
开发者ID:stevemulligan,项目名称:Portfish,代码行数:67,代码来源:Search.cs

示例2: connected_threat

        // connected_threat() tests whether it is safe to forward prune a move or if
        // is somehow connected to the threat move returned by null search.
        static bool connected_threat(Position pos, Move m, Move threat)
        {
            Debug.Assert(Utils.is_ok_M(m));
            Debug.Assert(Utils.is_ok_M(threat));
            Debug.Assert(!pos.is_capture_or_promotion(m));
            Debug.Assert(!pos.is_passed_pawn_push(m));

            Square mfrom, mto, tfrom, tto;

            mfrom = Utils.from_sq(m);
            mto = Utils.to_sq(m);
            tfrom = Utils.from_sq(threat);
            tto = Utils.to_sq(threat);

            // Case 1: Don't prune moves which move the threatened piece
            if (mfrom == tto)
                return true;

            // Case 2: If the threatened piece has value less than or equal to the
            // value of the threatening piece, don't prune moves which defend it.
            if (pos.is_capture(threat)
                && (Position.PieceValueMidgame[pos.piece_on(tfrom)] >= Position.PieceValueMidgame[pos.piece_on(tto)]
                    || Utils.type_of(pos.piece_on(tfrom)) == PieceTypeC.KING)
                && pos.move_attacks_square(m, tto))
                return true;

            // Case 3: If the moving piece in the threatened move is a slider, don't
            // prune safe moves which block its ray.
            if (piece_is_slider(pos.piece_on(tfrom))
                && (Utils.bit_is_set(Utils.between_bb(tfrom, tto), mto) != 0)
                && pos.see(m, true) >= 0)
                return true;

            return false;
        }
开发者ID:stevemulligan,项目名称:Portfish,代码行数:37,代码来源:Search.cs

示例3: search


//.........这里部分代码省略.........
                if (alpha >= beta)
                {
                    MovesSearchedBroker.Free();
                    return alpha;
                }
            }

            // Step 4. Transposition table lookup
            // We don't want the score of a partial search to overwrite a previous full search
            // TT value, so we use a different position key in case of an excluded move.
            excludedMove = ss[ssPos].excludedMove;
            posKey = (excludedMove != 0) ? pos.exclusion_key() : pos.key();
            tteHasValue = TT.probe(posKey, ref ttePos, out tte);
            ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tteHasValue ? tte.move() : MoveC.MOVE_NONE;
            ttValue = tteHasValue ? value_from_tt(tte.value(), ss[ssPos].ply) : ValueC.VALUE_NONE;

            // At PV nodes we check for exact scores, while at non-PV nodes we check for
            // a fail high/low. Biggest advantage at probing at PV nodes is to have a
            // smooth experience in analysis mode. We don't probe at Root nodes otherwise
            // we should also update RootMoveList to avoid bogus output.
            if (!RootNode 
                && tteHasValue 
                && tte.depth() >= depth
                && ttValue != ValueC.VALUE_NONE // Only in case of TT access race
                && (PvNode ? tte.type() == Bound.BOUND_EXACT 
                            : ttValue >= beta ? ((tte.type() & Bound.BOUND_LOWER) != 0 )
                                              : ((tte.type() & Bound.BOUND_UPPER) != 0)))
            {
                Debug.Assert(ttValue != ValueC.VALUE_NONE); // Due to depth > DEPTH_NONE

                TT.table[ttePos].set_generation(TT.generation);
                ss[ssPos].currentMove = ttMove; // Can be MOVE_NONE

                if (ttValue >= beta && (ttMove != 0) && !pos.is_capture_or_promotion(ttMove)
                    && ttMove != ss[ssPos].killers0)
                {
                    ss[ssPos].killers1 = ss[ssPos].killers0;
                    ss[ssPos].killers0 = ttMove;
                }

                MovesSearchedBroker.Free();
                return ttValue;
            }

            // Step 5. Evaluate the position statically and update parentSplitPoint's gain statistics
            if (inCheck)
            {
                ss[ssPos].staticEval = ss[ssPos].evalMargin = eval = ValueC.VALUE_NONE;
            }
            else if (tteHasValue)
            {
                // Never assume anything on values stored in TT
                if ((ss[ssPos].staticEval = eval = tte.eval_value()) == ValueC.VALUE_NONE
                    || (ss[ssPos].evalMargin = tte.eval_margin()) == ValueC.VALUE_NONE)
                {
                    eval = ss[ssPos].staticEval = Evaluate.do_evaluate(false, pos, ref ss[ssPos].evalMargin);
                }

                // Can ttValue be used as a better position evaluation?
                if (ttValue != ValueC.VALUE_NONE)
                {
                    if ((((tte.type() & Bound.BOUND_LOWER) != 0) && ttValue > eval)
                        || (((tte.type() & Bound.BOUND_UPPER) != 0) && ttValue < eval))
                    {
                        eval = ttValue;
                    }
开发者ID:torfranz,项目名称:Portfish,代码行数:67,代码来源:Search.cs

示例4: MovePickerC

        internal void MovePickerC(Position p, Move ttm, Depth d, History h,
                               Square sq)
        {
            pos = p;
            H = h;
            curMovePos = 0;
            lastMovePos = 0;

            Debug.Assert(d <= DepthC.DEPTH_ZERO);

            depth = 0;
            recaptureSquare = 0;
            captureThreshold = 0;
            lastQuietPos = 0; lastBadCapturePos = 0;
            mpos = 0;

            if (p.in_check())
                phase = SequencerC.EVASION;

            else if (d > DepthC.DEPTH_QS_NO_CHECKS)
                phase = SequencerC.QSEARCH_0;

            else if (d > DepthC.DEPTH_QS_RECAPTURES)
            {
                phase = SequencerC.QSEARCH_1;

                // Skip TT move if is not a capture or a promotion, this avoids qsearch
                // tree explosion due to a possible perpetual check or similar rare cases
                // when TT table is full.
                if ((ttm != 0) && !pos.is_capture_or_promotion(ttm))
                    ttm = MoveC.MOVE_NONE;
            }
            else
            {
                phase = SequencerC.RECAPTURE;
                recaptureSquare = sq;
                ttm = MoveC.MOVE_NONE;
            }

            ttMove = ((ttm != 0) && pos.is_pseudo_legal(ttm) ? ttm : MoveC.MOVE_NONE);
            lastMovePos += ((ttMove != MoveC.MOVE_NONE) ? 1 : 0);
        }
开发者ID:CVChrisWilson,项目名称:Portfish,代码行数:42,代码来源:MovePicker.cs

示例5: qsearch


//.........这里部分代码省略.........

                    // Prune moves with negative or equal SEE
                    if (futilityBase < beta 
                        && depth < DepthC.DEPTH_ZERO 
                        && pos.see(move, false) <= 0)
                    {
                        bestValue = Math.Max(bestValue, futilityBase);
                        continue;
                    }
                }

                // Detect non-capture evasions that are candidate to be pruned
                evasionPrunable = !PvNode 
                                    && InCheck 
                                    && bestValue > ValueC.VALUE_MATED_IN_MAX_PLY
                                    && !pos.is_capture(move)
                                    && (pos.can_castle_C(pos.sideToMove) == 0);
                
                // Don't search moves with negative SEE values
                if (!PvNode 
                    && move != ttMove 
                    && (!InCheck || evasionPrunable) 
                    && Utils.type_of_move(move) != MoveTypeC.PROMOTION
                    && pos.see(move, true) < 0)
                {
                    continue;
                }

                // Don't search useless checks
                if (!PvNode 
                    && !InCheck 
                    && givesCheck 
                    && move != ttMove
                    && !pos.is_capture_or_promotion(move)
                    && ss[ssPos].staticEval + Constants.PawnValueMidgame / 4 < beta
                    && !check_is_dangerous(pos, move, futilityBase, beta))
                {
                    continue;
                }

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

                ss[ssPos].currentMove = move;

                // Make and search the move
                if (st == null)
                {
                    st = StateInfoBroker.GetObject();
                }
                pos.do_move(move, st, ci, givesCheck);
                value = -qsearch(NT, givesCheck, pos, ss, ssPos + 1, -beta, -alpha, depth - DepthC.ONE_PLY);
                pos.undo_move(move);

                Debug.Assert(value > -ValueC.VALUE_INFINITE && value < ValueC.VALUE_INFINITE);

                // Check for new best move
                if (value > bestValue)
                {
                    bestValue = value;
                    
                    if (value > alpha)
                    {
开发者ID:torfranz,项目名称:Portfish,代码行数:67,代码来源:Search.cs


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