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


C# Position.undo_move方法代码示例

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


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

示例1: insert_pv_in_tt

    /// RootMove::insert_pv_in_tt() is called at the end of a search iteration, and
    /// inserts the PV back into the TT. This makes sure the old PV moves are searched
    /// first, even if the old TT entries have been overwritten.
    internal void insert_pv_in_tt(Position pos)
    {
        var st = new StateInfoWrapper();

        foreach (var m in pv)
        {
            Debug.Assert(new MoveList(GenType.LEGAL, pos).contains(m));

            bool ttHit;
            var tte = TranspositionTable.probe(pos.key(), out ttHit);

            if (!ttHit || tte.move() != m) // Don't overwrite correct entries
            {
                tte.save(
                    pos.key(),
                    Value.VALUE_NONE,
                    Bound.BOUND_NONE,
                    Depth.DEPTH_NONE,
                    m,
                    Value.VALUE_NONE,
                    TranspositionTable.generation());
            }

            var current = st[st.current];
            st++;
            pos.do_move(m, current, pos.gives_check(m, new CheckInfo(pos)));
        }

        for (var i = pv.Count; i > 0;)
        {
            pos.undo_move(pv[--i]);
        }
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:36,代码来源:Rootmove.cs

示例2: update

    internal void update(Position pos, List<MoveT> newPv)
    {
        Debug.Assert(newPv.Count >= 3);

        // Keep track of how many times in a row 3rd ply remains stable
        stableCnt = (newPv[2] == pv[2]) ? stableCnt + 1 : 0;

        if (pv[0] != newPv[0] || pv[1] != newPv[1] || pv[2] != newPv[2])
        {
            pv[0] = newPv[0];
            pv[1] = newPv[1];
            pv[2] = newPv[2];

            var st = new StateInfo[2];
            pos.do_move(newPv[0], st[0], pos.gives_check(newPv[0], new CheckInfo(pos)));
            pos.do_move(newPv[1], st[1], pos.gives_check(newPv[1], new CheckInfo(pos)));
            expectedPosKey = pos.key();
            pos.undo_move(newPv[1]);
            pos.undo_move(newPv[0]);
        }
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:21,代码来源:EasyMoveManager.cs

示例3: extract_ponder_from_tt

    /// RootMove::extract_ponder_from_tt() is called in case we have no ponder move before
    /// exiting the search, for instance in case we stop the search during a fail high at
    /// root. We try hard to have a ponder move to return to the GUI, otherwise in case of
    /// 'ponder on' we have nothing to think on.
    internal bool extract_ponder_from_tt(Position pos)
    {
        var st = new StateInfo();
        bool ttHit;

        Debug.Assert(pv.Count == 1);

        pos.do_move(pv[0], st, pos.gives_check(pv[0], new CheckInfo(pos)));
        var tte = TranspositionTable.probe(pos.key(), out ttHit);
        pos.undo_move(pv[0]);

        if (ttHit)
        {
            var m = tte.move(); // Local copy to be SMP safe
            if (new MoveList(GenType.LEGAL, pos).contains(m))
            {
                pv.Add(m);
                return true;
            }
        }

        return false;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:27,代码来源:Rootmove.cs

示例4: search


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

                if (v >= beta)
                    return nullValue;
            }
        }

        // Step 9. ProbCut (skipped when in check)
        // If we have a very good capture (i.e. SEE > seeValues[captured_piece_type])
        // and a reduced search returns a value much above beta, we can (almost) safely
        // prune the previous move.
        if (!PvNode
            && depth >= 5*Depth.ONE_PLY_C
            && Math.Abs(beta) < Value.VALUE_MATE_IN_MAX_PLY)
        {
            var rbeta = Value.Create(Math.Min(beta + 200, Value.VALUE_INFINITE));
            var rdepth = depth - 4*Depth.ONE_PLY;

            Debug.Assert(rdepth >= Depth.ONE_PLY_C);
            Debug.Assert(stackMinus1.currentMove != Move.MOVE_NONE);
            Debug.Assert(stackMinus1.currentMove != Move.MOVE_NULL);

            var mp2 = new MovePicker(pos, ttMove, History, CounterMovesHistory,
                Value.PieceValue[(int) Phase.MG][pos.captured_piece_type()]);
            var ci2 = new CheckInfo(pos);

            while ((move = mp2.next_move(false)) != Move.MOVE_NONE)
                if (pos.legal(move, ci2.pinned))
                {
                    stack.currentMove = move;
                    pos.do_move(move, st, pos.gives_check(move, ci2));
                    value =
                        -search(NodeType.NonPV, false, pos, new StackArrayWrapper(ss.table, ss.current + 1), -rbeta,
                            -rbeta + 1, rdepth, !cutNode);
                    pos.undo_move(move);
                    if (value >= rbeta)
                        return value;
                }
        }

        // Step 10. Internal iterative deepening (skipped when in check)
        if (depth >= (PvNode ? 5*Depth.ONE_PLY_C : 8*Depth.ONE_PLY_C)
            && ttMove == 0
            && (PvNode || stack.staticEval + 256 >= beta))
        {
            var d = depth - 2*Depth.ONE_PLY - (PvNode ? Depth.DEPTH_ZERO : depth/4);
            stack.skipEarlyPruning = true;
            search(PvNode ? NodeType.PV : NodeType.NonPV, false, pos, ss, alpha, beta, d, true);
            stack.skipEarlyPruning = false;

            tte = TranspositionTable.probe(posKey, out ttHit);
            ttMove = ttHit ? tte.move() : Move.MOVE_NONE;
        }

 moves_loop: // When in check and at SpNode search starts from here

        var prevMoveSq = Move.to_sq(stackMinus1.currentMove);
        var countermove = Countermoves.table[pos.piece_on(prevMoveSq), prevMoveSq];

        var mp = new MovePicker(pos, ttMove, depth, History, CounterMovesHistory, countermove, ss);
        var ci = new CheckInfo(pos);
        value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
        var improving = stack.staticEval >= stackMinus2.staticEval
                         || stack.staticEval == Value.VALUE_NONE
                         || stackMinus2.staticEval == Value.VALUE_NONE;

        var singularExtensionNode = !RootNode
开发者ID:torfranz,项目名称:NetFish,代码行数:67,代码来源:Search.cs

示例5: perft

    /// Search::perft() is our utility to verify move generation. All the leaf nodes
    /// up to the given depth are generated and counted and the sum returned.
    internal static long perft(bool Root, Position pos, Depth depth)
    {
        var st = new StateInfo();
        long nodes = 0;
        var ci = new CheckInfo(pos);
        var leaf = (depth == 2*Depth.ONE_PLY);

        var ml = new MoveList(GenType.LEGAL, pos);
        for (var index = ml.begin(); index < ml.end(); index++)
        {
            var m = ml.moveList.table[index];
            long cnt;
            if (Root && depth <= Depth.ONE_PLY_C)
            {
                cnt = 1;
                nodes++;
            }
            else
            {
                pos.do_move(m, st, pos.gives_check(m, ci));
                cnt = leaf ? new MoveList(GenType.LEGAL, pos).size() : perft(false, pos, depth - Depth.ONE_PLY);
                nodes += cnt;
                pos.undo_move(m);
            }
            if (Root)
            {
                Output.WriteLine($"{UCI.move(m, pos.is_chess960())}: {cnt}");
            }
        }
        return nodes;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:33,代码来源:Search.cs

示例6: qsearch


//.........这里部分代码省略.........
        while ((move = mp.next_move(false)) != Move.MOVE_NONE)
        {
            Debug.Assert(Move.is_ok(move));

            var givesCheck = Move.type_of(move) == MoveType.NORMAL && ci.dcCandidates == 0
                ? Bitboard.AndWithSquare(ci.checkSquares[Piece.type_of(pos.piece_on(Move.from_sq(move)))], Move.to_sq(move))!=0
                : pos.gives_check(move, ci);

            // Futility pruning
            if (!InCheck
                && !givesCheck
                && futilityBase > -Value.VALUE_KNOWN_WIN
                && !pos.advanced_pawn_push(move))
            {
                Debug.Assert(Move.type_of(move) != MoveType.ENPASSANT); // Due to !pos.advanced_pawn_push

                var futilityValue = futilityBase + Value.PieceValue[(int) Phase.EG][pos.piece_on(Move.to_sq(move))];

                if (futilityValue <= alpha)
                {
                    bestValue = Value.Create(Math.Max(bestValue, futilityValue));
                    continue;
                }

                if (futilityBase <= alpha && pos.see(move) <= Value.VALUE_ZERO)
                {
                    bestValue = Value.Create(Math.Max(bestValue, futilityBase));
                    continue;
                }
            }

            // Detect non-capture evasions that are candidates to be pruned
            var evasionPrunable = InCheck
                                   && bestValue > Value.VALUE_MATED_IN_MAX_PLY
                                   && !pos.capture(move);

            // Don't search moves with negative SEE values
            if ((!InCheck || evasionPrunable)
                && Move.type_of(move) != MoveType.PROMOTION
                && pos.see_sign(move) < Value.VALUE_ZERO)
                continue;

            // Speculative prefetch as early as possible
            //prefetch(TT.first_entry(pos.key_after(move)));

            // Check for legality just before making the move
            if (!pos.legal(move, ci.pinned))
                continue;

            ss[ss.current].currentMove = move;

            // Make and search the move
            pos.do_move(move, new StateInfo(), givesCheck);
            var value = givesCheck
                ? -qsearch(NT, true, pos, new StackArrayWrapper(ss.table, ss.current + 1), -beta, -alpha,
                    depth - Depth.ONE_PLY)
                : -qsearch(NT, false, pos, new StackArrayWrapper(ss.table, ss.current + 1), -beta, -alpha,
                    depth - Depth.ONE_PLY);
            pos.undo_move(move);

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

            // Check for new best move
            if (value <= bestValue) continue;

            bestValue = value;

            if (value > alpha)
            {
                if (PvNode) // Update pv even in fail-high case
                    update_pv(currentStack.pv, move, nextStack.pv);

                if (PvNode && value < beta) // Update alpha here! Always alpha < beta
                {
                    alpha = value;
                    bestMove = move;
                }
                else // Fail high
                {
                    tte.save(posKey, value_to_tt(value, currentPly), Bound.BOUND_LOWER,
                        ttDepth, move, currentStack.staticEval, TranspositionTable.generation());

                    return value;
                }
            }
        }

        // All legal moves have been searched. A special case: If we're in check
        // and no legal moves were found, it is checkmate.
        if (InCheck && bestValue == -Value.VALUE_INFINITE)
            return Value.mated_in(currentPly); // Plies to mate from the root

        tte.save(posKey, value_to_tt(bestValue, currentPly),
            PvNode && bestValue > oldAlpha ? Bound.BOUND_EXACT : Bound.BOUND_UPPER,
            ttDepth, bestMove, ss[ss.current].staticEval, TranspositionTable.generation());

        Debug.Assert(bestValue > -Value.VALUE_INFINITE && bestValue < Value.VALUE_INFINITE);

        return bestValue;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Search.cs


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