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


C# Position.non_pawn_material方法代码示例

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


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

示例1: verify_material

 protected static bool verify_material(Position pos, ColorT c, ValueT npm, int pawnsCnt)
 {
     return pos.non_pawn_material(c) == npm && pos.count(PieceType.PAWN, c) == pawnsCnt;
 }
开发者ID:torfranz,项目名称:NetFish,代码行数:4,代码来源:Endgame.cs

示例2: GetScaleFactor

    internal override ScaleFactor GetScaleFactor(Position pos)
    {
        Debug.Assert(pos.non_pawn_material(strongSide) == Value.VALUE_ZERO);
        Debug.Assert(pos.count(PieceType.PAWN, strongSide) >= 2);
        Debug.Assert(verify_material(pos, weakSide, Value.VALUE_ZERO, 0));

        var ksq = pos.square(PieceType.KING, weakSide);
        var pawns = pos.pieces_CtPt(strongSide, PieceType.PAWN);

        // If all pawns are ahead of the king, on a single rook file and
        // the king is within one file of the pawns, it's a draw.
        if ((pawns & ~Utils.in_front_bb(weakSide, Square.rank_of(ksq)))==0
            && !((pawns & ~Bitboard.FileABB)!=0 && (pawns & ~Bitboard.FileHBB)!=0)
            && Utils.distance_File(ksq, Utils.lsb(pawns)) <= 1)
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        return ScaleFactor.SCALE_FACTOR_NONE;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:20,代码来源:Endgame.cs

示例3: GetValue

    internal override ValueT GetValue(Position pos)
    {
        Debug.Assert(verify_material(pos, weakSide, Value.VALUE_ZERO, 0));
        Debug.Assert(pos.checkers()==0); // Eval is never called when in check

        // Stalemate detection with lone king
        if (pos.side_to_move() == weakSide && new MoveList(GenType.LEGAL, pos).size() == 0)
        {
            return Value.VALUE_DRAW;
        }

        var winnerKSq = pos.square(PieceType.KING, strongSide);
        var loserKSq = pos.square(PieceType.KING, weakSide);

        var result = pos.non_pawn_material(strongSide)
                     + pos.count(PieceType.PAWN, strongSide)*Value.PawnValueEg + PushToEdges[loserKSq]
                     + PushClose[Utils.distance_Square(winnerKSq, loserKSq)];

        if (pos.count(PieceType.QUEEN, strongSide) > 0 || pos.count(PieceType.ROOK, strongSide) > 0
            || (pos.count(PieceType.BISHOP, strongSide) > 0 && pos.count(PieceType.KNIGHT, strongSide) > 0)
            || (pos.count(PieceType.BISHOP, strongSide) > 1
                && Square.opposite_colors(
                    pos.square(PieceType.BISHOP, strongSide, 0),
                    pos.square(PieceType.BISHOP, strongSide, 1))))
        {
            result += Value.VALUE_KNOWN_WIN;
        }

        return strongSide == pos.side_to_move() ? result : -result;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:30,代码来源:Endgame.cs

示例4: is_KBPsKs

 private static bool is_KBPsKs(Position pos, ColorT us)
 {
     return pos.non_pawn_material(us) == Value.BishopValueMg && pos.count(PieceType.BISHOP, us) == 1
            && pos.count(PieceType.PAWN, us) >= 1;
 }
开发者ID:torfranz,项目名称:NetFish,代码行数:5,代码来源:Material.cs

示例5: is_KQKRPs

 private static bool is_KQKRPs(Position pos, ColorT us)
 {
     return pos.count(PieceType.PAWN, us) == 0 && pos.non_pawn_material(us) == Value.QueenValueMg
            && pos.count(PieceType.QUEEN, us) == 1 && pos.count(PieceType.ROOK, Color.opposite(us)) == 1
            && pos.count(PieceType.PAWN, Color.opposite(us)) >= 1;
 }
开发者ID:torfranz,项目名称:NetFish,代码行数:6,代码来源:Material.cs

示例6: is_KXK

 // Helper used to detect a given material distribution
 private static bool is_KXK(Position pos, ColorT us)
 {
     return !Bitboard.more_than_one(pos.pieces_Ct(Color.opposite(us))) && pos.non_pawn_material(us) >= Value.RookValueMg;
 }
开发者ID:torfranz,项目名称:NetFish,代码行数:5,代码来源:Material.cs

示例7: probe

    /// Material::probe() looks up the current position's material configuration in
    /// the material hash table. It returns a pointer to the Entry if the position
    /// is found. Otherwise a new Entry is computed and stored there, so we don't
    /// have to recompute all when the same material configuration occurs again.
    internal static MaterialEntry probe(Position pos)
    {
        var key = pos.material_key();
        MaterialEntry e;
        if (!pos.this_thread().materialTable.TryGetValue(key, out e))
        {
            e = new MaterialEntry();
            pos.this_thread().materialTable.Add(key, e);
        }
        else if (e.key == key)
        {
            return e;
        }

        e.reset();

        e.key = key;
        e.factor[Color.WHITE] = e.factor[Color.BLACK] = (ushort) ScaleFactor.SCALE_FACTOR_NORMAL;
        e.gamePhase = pos.game_phase();

        // Let's look if we have a specialized evaluation function for this particular
        // material configuration. Firstly we look for a fixed configuration one, then
        // for a generic one if the previous search failed.
        if ((e.evaluationFunction = pos.this_thread().endgames.probeEndgameValue(key)) != null)
        {
            return e;
        }

        foreach (var c in Color.AllColors)
        {
            if (is_KXK(pos, c))
            {
                e.evaluationFunction = EvaluateKXK[c];
                return e;
            }
        }

        // OK, we didn't find any special evaluation function for the current material
        // configuration. Is there a suitable specialized scaling function?
        EndgameScaleFactor sf;

        if ((sf = pos.this_thread().endgames.probeEndgameScaleFactor(key)) != null)
        {
            e.scalingFunction[sf.strong_side()] = sf; // Only strong color assigned
            return e;
        }

        // We didn't find any specialized scaling function, so fall back on generic
        // ones that refer to more than one material distribution. Note that in this
        // case we don't return after setting the function.
        foreach (var c in Color.AllColors)
        {
            if (is_KBPsKs(pos, c))
            {
                e.scalingFunction[c] = ScaleKBPsK[c];
            }
            else if (is_KQKRPs(pos, c))
            {
                e.scalingFunction[c] = ScaleKQKRPs[c];
            }
        }

        var npm_w = pos.non_pawn_material(Color.WHITE);
        var npm_b = pos.non_pawn_material(Color.BLACK);

        if (npm_w + npm_b == Value.VALUE_ZERO && (pos.pieces_Pt(PieceType.PAWN) != 0)) // Only pawns on the board
        {
            if (pos.count(PieceType.PAWN, Color.BLACK) == 0)
            {
                Debug.Assert(pos.count(PieceType.PAWN, Color.WHITE) >= 2);

                e.scalingFunction[Color.WHITE] = ScaleKPsK[Color.WHITE];
            }
            else if (pos.count(PieceType.PAWN, Color.WHITE) == 0)
            {
                Debug.Assert(pos.count(PieceType.PAWN, Color.BLACK) >= 2);

                e.scalingFunction[Color.BLACK] = ScaleKPsK[Color.BLACK];
            }
            else if (pos.count(PieceType.PAWN, Color.WHITE) == 1 && pos.count(PieceType.PAWN, Color.BLACK) == 1)
            {
                // This is a special case because we set scaling functions
                // for both colors instead of only one.
                e.scalingFunction[Color.WHITE] = ScaleKPKP[Color.WHITE];
                e.scalingFunction[Color.BLACK] = ScaleKPKP[Color.BLACK];
            }
        }

        // Zero or just one pawn makes it difficult to win, even with a small material
        // advantage. This catches some trivial draws like KK, KBK and KNK and gives a
        // drawish scale factor for cases such as KRKBP and KmmKm (except for KBBKN).
        if (pos.count(PieceType.PAWN, Color.WHITE) == 0 && npm_w - npm_b <= Value.BishopValueMg)
        {
            e.factor[Color.WHITE] =
                (ushort)
                    (npm_w < Value.RookValueMg
//.........这里部分代码省略.........
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Material.cs

示例8: search


//.........这里部分代码省略.........
            eval = stack.staticEval =
                stackMinus1.currentMove != Move.MOVE_NULL
                    ? Eval.evaluate(false, pos)
                    : -stackMinus1.staticEval + 2*Eval.Tempo;

            tte.save(posKey, Value.VALUE_NONE, Bound.BOUND_NONE, Depth.DEPTH_NONE, Move.MOVE_NONE,
                stack.staticEval, TranspositionTable.generation());
        }

        if (stack.skipEarlyPruning)
            goto moves_loop;

        // Step 6. Razoring (skipped when in check)
        if (!PvNode
            && depth < 4*Depth.ONE_PLY
            && eval + razor_margin(depth) <= alpha
            && ttMove == Move.MOVE_NONE)
        {
            if (depth <= Depth.ONE_PLY_C
                && eval + razor_margin(3*Depth.ONE_PLY) <= alpha)
                return qsearch(NodeType.NonPV, false, pos, ss, alpha, beta, Depth.DEPTH_ZERO);

            var ralpha = alpha - razor_margin(depth);
            var v = qsearch(NodeType.NonPV, false, pos, ss, ralpha, ralpha + 1, Depth.DEPTH_ZERO);
            if (v <= ralpha)
                return v;
        }

        // Step 7. Futility pruning: child node (skipped when in check)
        if (!RootNode
            && depth < 7*Depth.ONE_PLY
            && eval - futility_margin(depth) >= beta
            && eval < Value.VALUE_KNOWN_WIN // Do not return unproven wins
            && pos.non_pawn_material(pos.side_to_move())!=0)
            return eval - futility_margin(depth);

        // Step 8. Null move search with verification search (is omitted in PV nodes)
        if (!PvNode
            && depth >= 2*Depth.ONE_PLY_C
            && eval >= beta
            && pos.non_pawn_material(pos.side_to_move())!=0)
        {
            stack.currentMove = Move.MOVE_NULL;

            Debug.Assert(eval - beta >= 0);

            // Null move dynamic reduction based on depth and value
            var R = ((823 + 67*depth)/256 + Math.Min((eval - beta)/Value.PawnValueMg, 3))*(int) Depth.ONE_PLY;

            pos.do_null_move(st);
            stackPlus1.skipEarlyPruning = true;
            var nullValue = depth - R < Depth.ONE_PLY
                ? -qsearch(NodeType.NonPV, false, pos, new StackArrayWrapper(ss.table, ss.current + 1), -beta, -beta + 1,
                    Depth.DEPTH_ZERO)
                : -search(NodeType.NonPV, false, pos, new StackArrayWrapper(ss.table, ss.current + 1), -beta, -beta + 1,
                    depth - R, !cutNode);
            stackPlus1.skipEarlyPruning = false;
            pos.undo_null_move();

            if (nullValue >= beta)
            {
                // Do not return unproven mate scores
                if (nullValue >= Value.VALUE_MATE_IN_MAX_PLY)
                    nullValue = beta;

                if (depth < 12*Depth.ONE_PLY && Math.Abs(beta) < Value.VALUE_KNOWN_WIN)
开发者ID:torfranz,项目名称:NetFish,代码行数:67,代码来源:Search.cs

示例9: evaluate

    /// evaluate() is the main evaluation function. It returns a static evaluation
    /// of the position always from the point of view of the side to move.
    internal static ValueT evaluate(bool DoTrace, Position pos)
    {
        Debug.Assert(pos.checkers() == 0);

        var ei = new EvalInfo();
        ScoreT[] mobility = {Score.SCORE_ZERO, Score.SCORE_ZERO};

        // Initialize score by reading the incrementally updated scores included
        // in the position object (material + piece square tables).
        // Score is computed from the point of view of white.
        var score = pos.psq_score();

        // Probe the material hash table
        var me = Material.probe(pos);
        score += me.imbalance();

        // If we have a specialized evaluation function for the current material
        // configuration, call it and return.
        if (me.specialized_eval_exists())
        {
            return me.evaluate(pos);
        }

        // Probe the pawn hash table
        ei.pi = Pawns.probe(pos);
        score += Score.Multiply(ei.pi.pawns_score(), Weights[PawnStructure]);

        // Initialize attack and king safety bitboards
        ei.attackedBy[Color.WHITE, PieceType.ALL_PIECES] =
            ei.attackedBy[Color.BLACK, PieceType.ALL_PIECES] = Bitboard.Create(0);
        init_eval_info(Color.WHITE, pos, ei);
        init_eval_info(Color.BLACK, pos, ei);

        // Pawns blocked or on ranks 2 and 3. Will be excluded from the mobility area
        BitboardT[] blockedPawns =
        {
            pos.pieces_CtPt(Color.WHITE, PieceType.PAWN)
            & (Bitboard.shift_bb(Square.DELTA_S, pos.pieces()) | Bitboard.Rank2BB
               | Bitboard.Rank3BB),
            pos.pieces_CtPt(Color.BLACK, PieceType.PAWN)
            & (Bitboard.shift_bb(Square.DELTA_N, pos.pieces()) | Bitboard.Rank7BB
               | Bitboard.Rank6BB)
        };

        // Do not include in mobility squares protected by enemy pawns, or occupied
        // by our blocked pawns or king.
        BitboardT[] mobilityArea =
        {
            ~(Bitboard.OrWithSquare(ei.attackedBy[Color.BLACK, PieceType.PAWN] | blockedPawns[Color.WHITE]
              , pos.square(PieceType.KING, Color.WHITE))),
            ~(Bitboard.OrWithSquare(ei.attackedBy[Color.WHITE, PieceType.PAWN] | blockedPawns[Color.BLACK]
              , pos.square(PieceType.KING, Color.BLACK)))
        };

        // Evaluate pieces and mobility
        score += evaluate_pieces(PieceType.KNIGHT, Color.WHITE, DoTrace, pos, ei, mobility, mobilityArea);
        score += Score.Multiply(mobility[Color.WHITE] - mobility[Color.BLACK], Weights[Mobility]);

        // Evaluate kings after all other pieces because we need complete attack
        // information when computing the king safety evaluation.
        score += evaluate_king(Color.WHITE, DoTrace, pos, ei) - evaluate_king(Color.BLACK, DoTrace, pos, ei);

        // Evaluate tactical threats, we need full attack information including king
        score += evaluate_threats(Color.WHITE, DoTrace, pos, ei) - evaluate_threats(Color.BLACK, DoTrace, pos, ei);

        // Evaluate passed pawns, we need full attack information including king
        score += evaluate_passed_pawns(Color.WHITE, DoTrace, pos, ei)
                 - evaluate_passed_pawns(Color.BLACK, DoTrace, pos, ei);

        // If both sides have only pawns, score for potential unstoppable pawns
        if (pos.non_pawn_material(Color.WHITE) == 0 && pos.non_pawn_material(Color.BLACK) == 0)
        {
            BitboardT b;
            if ((b = ei.pi.passed_pawns(Color.WHITE)) != 0)
            {
                score += Rank.relative_rank_CtSt(Color.WHITE, Utils.frontmost_sq(Color.WHITE, b)) * Unstoppable;
            }

            if ((b = ei.pi.passed_pawns(Color.BLACK)) != 0)
            {
                score -= Rank.relative_rank_CtSt(Color.BLACK, Utils.frontmost_sq(Color.BLACK, b)) * Unstoppable;
            }
        }

        // Evaluate space for both sides, only during opening
        if (pos.non_pawn_material(Color.WHITE) + pos.non_pawn_material(Color.BLACK) >= 12222)
        {
            score += Score.Multiply(evaluate_space(Color.WHITE, pos, ei) - evaluate_space(Color.BLACK, pos, ei), Weights[Space]);
        }

        // Scale winning side if position is more drawish than it appears
        var strongSide = Score.eg_value(score) > Value.VALUE_DRAW ? Color.WHITE : Color.BLACK;
        var sf = me.scale_factor(pos, strongSide);

        // If we don't already have an unusual scale factor, check for certain
        // types of endgames, and use a lower scale for those.
        if (me.game_phase() < Phase.PHASE_MIDGAME
            && (sf == ScaleFactor.SCALE_FACTOR_NORMAL || sf == ScaleFactor.SCALE_FACTOR_ONEPAWN))
//.........这里部分代码省略.........
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Eval.cs

示例10: init_eval_info

    // init_eval_info() initializes king bitboards for given color adding
    // pawn attacks. To be done at the beginning of the evaluation.

    private static void init_eval_info(ColorT Us, Position pos, EvalInfo ei)
    {
        var Them = (Us == Color.WHITE ? Color.BLACK : Color.WHITE);
        var Down = (Us == Color.WHITE ? Square.DELTA_S : Square.DELTA_N);

        ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
        var b = ei.attackedBy[Them, PieceType.KING] = pos.attacks_from_PtS(PieceType.KING, pos.square(PieceType.KING, Them));
        ei.attackedBy[Them, PieceType.ALL_PIECES] |= b;
        ei.attackedBy[Us, PieceType.ALL_PIECES] |= ei.attackedBy[Us, PieceType.PAWN] = ei.pi.pawn_attacks(Us);

        // Init king safety tables only if we are going to use them
        if (pos.non_pawn_material(Us) >= Value.QueenValueMg)
        {
            ei.kingRing[Them] = b | Bitboard.shift_bb(Down, b);
            b &= ei.attackedBy[Us, PieceType.PAWN];
            ei.kingAttackersCount[Us] = b!=0 ? Bitcount.popcount_Max15(b) : 0;
            ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0;
        }
        else
        {
            ei.kingRing[Them] = Bitboard.Create(0);
            ei.kingAttackersCount[Us] = 0;
        }
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:27,代码来源:Eval.cs


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