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


C# Position.is_draw方法代码示例

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


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

示例1: search

    // search<>() is the main search function for both PV and non-PV nodes and for
    // normal and SplitPoint nodes. When called just after a split point the search
    // is simpler because we have already probed the hash table, done a null move
    // search, and searched the first move before splitting, so we don't have to
    // repeat all this work again. We also don't need to store anything to the hash
    // table here: This is taken care of after we return from the split point.

    private static ValueT search(NodeType NT, bool SpNode, Position pos, StackArrayWrapper ss, ValueT alpha, ValueT beta,
        Depth depth, bool cutNode)
    {
        Utils.WriteToLog($"search(NT={(int) NT}, SpNode={(SpNode ? 1 : 0)}, pos={pos.key()}, ss, alpha={alpha}, beta={beta}, depth={(int) depth}, cutNode={(cutNode ? 1 : 0)})");
        var RootNode = NT == NodeType.Root;
        var PvNode = RootNode || NT == NodeType.PV;

        Debug.Assert(-Value.VALUE_INFINITE <= alpha && alpha < beta && beta <= Value.VALUE_INFINITE);
        Debug.Assert(PvNode || (alpha == beta - 1));
        Debug.Assert(depth > Depth.DEPTH_ZERO);

        var st = new StateInfo();
        TTEntry tte;
        SplitPoint splitPoint = null;
        ulong posKey = 0;
        MoveT ttMove, move, excludedMove, bestMove;
        ValueT bestValue, value, ttValue, eval;
        bool ttHit;
        int moveCount = 0;
        int quietCount = 0;

        var stack = ss[ss.current];
        var stackPlus1 = ss[ss.current + 1];
        var stackPlus2 = ss[ss.current + 2];
        var stackMinus1 = ss[ss.current - 1];
        var stackMinus2 = ss[ss.current - 2];

        // Step 1. Initialize node
        var thisThread = pos.this_thread();
        bool inCheck = pos.checkers() != 0;

        if (SpNode)
        {
            splitPoint = stack.splitPoint;
            bestMove = Move.Create(splitPoint.bestMove);
            bestValue = Value.Create(splitPoint.bestValue);
            tte = new TTEntry();
            ttMove = excludedMove = Move.MOVE_NONE;
            ttValue = Value.VALUE_NONE;

            Debug.Assert(splitPoint.bestValue > -Value.VALUE_INFINITE && splitPoint.moveCount > 0);

            goto moves_loop;
        }

        moveCount = quietCount = stack.moveCount = 0;
        bestValue = -Value.VALUE_INFINITE;
        stack.ply = stackMinus1.ply + 1;

        // Used to send selDepth info to GUI
        if (PvNode && thisThread.maxPly < stack.ply)
            thisThread.maxPly = stack.ply;

        if (!RootNode)
        {
            // Step 2. Check for aborted search and immediate draw
            if (Signals.stop || pos.is_draw() || stack.ply >= _.MAX_PLY)
                return stack.ply >= _.MAX_PLY && !inCheck
                    ? Eval.evaluate(false, pos)
                    : DrawValue[pos.side_to_move()];

            // Step 3. Mate distance pruning. Even if we mate at the next move our score
            // would be at best mate_in(ss.ply+1), but if alpha is already bigger because
            // a shorter mate was found upward in the tree then there is no need to search
            // because we will never beat the current alpha. Same logic but with reversed
            // signs applies also in the opposite condition of being mated instead of giving
            // mate. In this case return a fail-high score.
            alpha = Value.Create(Math.Max(Value.mated_in(stack.ply), alpha));
            beta = Value.Create(Math.Min(Value.mate_in(stack.ply + 1), beta));
            if (alpha >= beta)
                return alpha;
        }

        Debug.Assert(0 <= stack.ply && stack.ply < _.MAX_PLY);

        stack.currentMove = stack.ttMove = stackPlus1.excludedMove = bestMove = Move.MOVE_NONE;
        stackPlus1.skipEarlyPruning = false;
        stackPlus1.reduction = Depth.DEPTH_ZERO;
        stackPlus2.killers0 = stackPlus2.killers1 = Move.MOVE_NONE;

        // 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 = stack.excludedMove;
        posKey = excludedMove != 0 ? pos.exclusion_key() : pos.key();
        tte = TranspositionTable.probe(posKey, out ttHit);
        stack.ttMove = ttMove = RootNode ? RootMoves[(int) PVIdx].pv[0] : ttHit ? tte.move() : Move.MOVE_NONE;
        ttValue = ttHit ? value_from_tt(tte.value(), stack.ply) : Value.VALUE_NONE;

        // At non-PV nodes we check for a fail high/low. We don't prune at PV nodes
        if (!PvNode
            && ttHit
            && tte.depth() >= depth
//.........这里部分代码省略.........
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Search.cs

示例2: qsearch

    private static ValueT qsearch(NodeType NT, bool InCheck, Position pos, StackArrayWrapper ss, ValueT alpha, ValueT beta,
        Depth depth)
    {
        Utils.WriteToLog($"qsearch(NT={(int) NT}, InCheck={(InCheck ? 1 : 0)}, pos={pos.key()}, ss, alpha={alpha}, beta={beta}, depth={(int) depth})");
        var PvNode = NT == NodeType.PV;

        Debug.Assert(NT == NodeType.PV || NT == NodeType.NonPV);
        Debug.Assert(InCheck == (pos.checkers() != 0));
        Debug.Assert(alpha >= -Value.VALUE_INFINITE && alpha < beta && beta <= Value.VALUE_INFINITE);
        Debug.Assert(PvNode || (alpha == beta - 1));
        Debug.Assert(depth <= Depth.DEPTH_ZERO_C);

        var currentStack = ss[ss.current];
        var nextStack = ss[ss.current+1];
        var previousStack = ss[ss.current - 1];
        var oldAlpha = 0;
        if (PvNode)
        {
            oldAlpha = alpha; // To flag BOUND_EXACT when eval above alpha and no available moves
            nextStack.pv = new List<MoveT>() { Move.MOVE_NONE };
            currentStack.pv[0] = Move.MOVE_NONE;
        }

        currentStack.currentMove = Move.MOVE_NONE;
        currentStack.ply = previousStack.ply + 1;
        var currentPly = currentStack.ply;
        // Check for an instant draw or if the maximum ply has been reached
        if (pos.is_draw() || currentPly >= _.MAX_PLY)
            return currentPly >= _.MAX_PLY && !InCheck
                ? Eval.evaluate(false, pos)
                : DrawValue[pos.side_to_move()];

        Debug.Assert(0 <= currentPly && currentPly < _.MAX_PLY);

        // Decide whether or not to include checks: this fixes also the type of
        // TT entry depth that we are going to use. Note that in qsearch we use
        // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
        var ttDepth = InCheck || (int)depth >= Depth.DEPTH_QS_CHECKS_C
            ? Depth.DEPTH_QS_CHECKS
            : Depth.DEPTH_QS_NO_CHECKS;

        // Transposition table lookup
        bool ttHit;
        var posKey = pos.key();
        var tte = TranspositionTable.probe(posKey, out ttHit);
        var ttMove = ttHit ? tte.move() : Move.MOVE_NONE;
        var ttValue = ttHit ? value_from_tt(tte.value(), currentPly) : Value.VALUE_NONE;

        if (!PvNode
            && ttHit
            && tte.depth() >= ttDepth
            && ttValue != Value.VALUE_NONE // Only in case of TT access race
            && ((ttValue >= beta ? (tte.bound() & Bound.BOUND_LOWER) : (tte.bound() & Bound.BOUND_UPPER))) != 0)
        {
            currentStack.currentMove = ttMove; // Can be MOVE_NONE
            return ttValue;
        }

        ValueT bestValue;
        ValueT futilityBase;
        // Evaluate the position statically
        if (InCheck)
        {
            currentStack.staticEval = Value.VALUE_NONE;
            bestValue = futilityBase = -Value.VALUE_INFINITE;
        }
        else
        {
            if (ttHit)
            {
                // Never assume anything on values stored in TT
                if ((currentStack.staticEval = bestValue = tte.eval()) == Value.VALUE_NONE)
                    currentStack.staticEval = bestValue = Eval.evaluate(false, pos);

                // Can ttValue be used as a better position evaluation?
                if (ttValue != Value.VALUE_NONE)
                    if ((tte.bound() & (ttValue > bestValue ? Bound.BOUND_LOWER : Bound.BOUND_UPPER)) != 0)
                        bestValue = ttValue;
            }
            else
                currentStack.staticEval = bestValue =
                    previousStack.currentMove != Move.MOVE_NULL
                        ? Eval.evaluate(false, pos)
                        : -previousStack.staticEval + 2*Eval.Tempo;

            // Stand pat. Return immediately if static value is at least beta
            if (bestValue >= beta)
            {
                if (!ttHit)
                    tte.save(pos.key(), value_to_tt(bestValue, currentPly), Bound.BOUND_LOWER,
                        Depth.DEPTH_NONE, Move.MOVE_NONE, currentStack.staticEval, TranspositionTable.generation());

                return bestValue;
            }

            if (PvNode && bestValue > alpha)
                alpha = bestValue;

            futilityBase = bestValue + 128;
        }
//.........这里部分代码省略.........
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Search.cs


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