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


C# Position.gives_check方法代码示例

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


在下文中一共展示了Position.gives_check方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: generate_castling

    internal static ExtMoveArrayWrapper generate_castling(
        CastlingRight Cr,
        bool Checks,
        bool Chess960,
        Position pos,
        ExtMoveArrayWrapper moveList,
        ColorT us,
        CheckInfo ci)
    {
        var KingSide = (Cr == CastlingRight.WHITE_OO || Cr == CastlingRight.BLACK_OO);

        if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
        {
            return moveList;
        }

        // After castling, the rook and king final positions are the same in Chess960
        // as they would be in standard chess.
        var kfrom = pos.square(PieceType.KING, us);
        var rfrom = pos.castling_rook_square(Cr);
        var kto = Square.relative_square(us, KingSide ? Square.SQ_G1 : Square.SQ_C1);
        var enemies = pos.pieces_Ct(Color.opposite(us));

        Debug.Assert(pos.checkers() == 0);

        var K = Chess960 ? kto > kfrom ? Square.DELTA_W : Square.DELTA_E : KingSide ? Square.DELTA_W : Square.DELTA_E;

        for (var s = kto; s != kfrom; s += K)
        {
            if ((pos.attackers_to(s) & enemies) != 0)
            {
                return moveList;
            }
        }

        // Because we generate only legal castling moves we need to verify that
        // when moving the castling rook we do not discover some hidden checker.
        // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
        if (Chess960
            && ((Utils.attacks_bb_PtSBb(PieceType.ROOK, kto, Bitboard.XorWithSquare(pos.pieces(), rfrom))
                & pos.pieces_CtPtPt(Color.opposite(us), PieceType.ROOK, PieceType.QUEEN)))!= 0)
        {
            return moveList;
        }

        var m = Move.make(MoveType.CASTLING, kfrom, rfrom);

        if (Checks && !pos.gives_check(m, ci))
        {
            return moveList;
        }

        moveList.Add(m);
        return moveList;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:55,代码来源:Movegen.cs

示例3: 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

示例4: 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

示例5: position

    // position() is called when engine receives the "position" UCI command.
    // The function sets up the position described in the given FEN string ("fen")
    // or the starting position ("startpos") and then makes the moves given in the
    // following move list ("moves").
    internal static void position(Position pos, Stack<string> stack)
    {
        MoveT m;
        string fen = string.Empty;

        if (stack.Count == 0)
        {
            // do nothing for incomplete command
            return;
        }
        var token = stack.Pop();

        if (token == "startpos")
        {
            fen = StartFEN;
            if (stack.Count > 0)
            {
                token = stack.Pop();
            } // Consume "moves" token if any
        }
        else if (token == "fen")
        {
            while ((stack.Count > 0) && (token = stack.Pop()) != "moves")
            {
                fen += token + " ";
            }
        }
        else
        {
            return;
        }

        pos.set(fen, bool.Parse(OptionMap.Instance["UCI_Chess960"].v), ThreadPool.main());

        // Parse move list (if any)
        while ((stack.Count > 0) && (m = to_move(pos, token = stack.Pop())) != Move.MOVE_NONE)
        {
            pos.do_move(m, SetupStates[SetupStates.current], pos.gives_check(m, new CheckInfo(pos)));

            // Increment pointer to SetupStates circular buffer
            SetupStates++;
        }
        
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:48,代码来源:UCI.cs

示例6: search


//.........这里部分代码省略.........
                var v = depth - R < Depth.ONE_PLY
                    ? qsearch(NodeType.NonPV, false, pos, ss, beta - 1, beta, Depth.DEPTH_ZERO)
                    : search(NodeType.NonPV, false, pos, ss, beta - 1, beta, depth - R, false);
                stack.skipEarlyPruning = false;

                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
开发者ID:torfranz,项目名称:NetFish,代码行数:67,代码来源:Search.cs

示例7: 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

示例8: qsearch


//.........这里部分代码省略.........
            // 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;
        }

        // Initialize a MovePicker object for the current position, and prepare
        // to search the moves. Because the depth is <= 0 here, only captures,
        // queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
        // be generated.
        var mp = new MovePicker(pos, ttMove, depth, History, CounterMovesHistory,
            Move.to_sq(previousStack.currentMove));
        var ci = new CheckInfo(pos);

        // Loop through the moves until no moves remain or a beta cutoff occurs
        MoveT move;
        MoveT bestMove = Move.MOVE_NONE;
        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
开发者ID:torfranz,项目名称:NetFish,代码行数:67,代码来源:Search.cs


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