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


C# Position.side_to_move方法代码示例

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


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

示例1: CheckInfo

    internal CheckInfo(Position pos)
    {
        var them = Color.opposite(pos.side_to_move());
        ksq = pos.square(PieceType.KING, them);

        pinned = pos.pinned_pieces(pos.side_to_move());
        dcCandidates = pos.discovered_check_candidates();

        checkSquares[PieceType.PAWN] = pos.attacks_from_PS(PieceType.PAWN, ksq, them);
        checkSquares[PieceType.KNIGHT] = pos.attacks_from_PtS(PieceType.KNIGHT, ksq);
        checkSquares[PieceType.BISHOP] = pos.attacks_from_PtS(PieceType.BISHOP, ksq);
        checkSquares[PieceType.ROOK] = pos.attacks_from_PtS(PieceType.ROOK, ksq);
        checkSquares[PieceType.QUEEN] = checkSquares[PieceType.BISHOP] | checkSquares[PieceType.ROOK];
        checkSquares[PieceType.KING] = Bitboard.Create(0);
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:15,代码来源:Checkinfo.cs

示例2: GetValue

    internal override ValueT GetValue(Position pos)
    {
        Debug.Assert(verify_material(pos, strongSide, Value.RookValueMg, 0));
        Debug.Assert(verify_material(pos, weakSide, Value.KnightValueMg, 0));

        var bksq = pos.square(PieceType.KING, weakSide);
        var bnsq = pos.square(PieceType.KNIGHT, weakSide);
        var result = Value.Create(PushToEdges[bksq] + PushAway[Utils.distance_Square(bksq, bnsq)]);
        return strongSide == pos.side_to_move() ? result : -result;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:10,代码来源:Endgame.cs

示例3: trace

    /// trace() is like evaluate(), but instead of returning a value, it returns
    /// a string (suitable for outputting to stdout) that contains the detailed
    /// descriptions and values of each evaluation term. Useful for debugging.
    internal static string trace(Position pos)
    {
        scores = new double[(int) Term.TERM_NB, Color.COLOR_NB, (int) Phase.PHASE_NB];

        var v = evaluate(true, pos);
        v = pos.side_to_move() == Color.WHITE ? v : -v; // White's point of view

        var ss = new StringBuilder();

        ss.AppendLine("      Eval term |    White    |    Black    |    Total    ");
        ss.AppendLine("                |   MG    EG  |   MG    EG  |   MG    EG  ");
        ss.AppendLine("----------------+-------------+-------------+-------------");
        ss.AppendLine($"       Material | {termString(Term.MATERIAL)}");
        ss.AppendLine($"      Imbalance | {termString(Term.IMBALANCE)}");
        ss.AppendLine($"          Pawns | {termString((Term) (int)PieceType.PAWN)}");
        ss.AppendLine($"        Knights | {termString((Term) (int)PieceType.KNIGHT)}");
        ss.AppendLine($"         Bishop | {termString((Term) (int)PieceType.BISHOP)}");
        ss.AppendLine($"          Rooks | {termString((Term) (int)PieceType.ROOK)}");
        ss.AppendLine($"         Queens | {termString((Term) (int)PieceType.QUEEN)}");
        ss.AppendLine($"       Mobility | {termString(Term.MOBILITY)}");
        ss.AppendLine($"    King safety | {termString((Term)(int) PieceType.KING)}");
        ss.AppendLine($"        Threats | {termString(Term.THREAT)}");
        ss.AppendLine($"   Passed pawns | {termString(Term.PASSED)}");
        ss.AppendLine($"          Space | {termString(Term.SPACE)}");
        ss.AppendLine("----------------+-------------+-------------+-------------");
        ss.AppendLine($"          Total | {termString(Term.TOTAL)}");

        ss.AppendLine();
        ss.AppendLine($"Total Evaluation: {to_cp(v),5:N2} (white side)");

        return ss.ToString();
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:35,代码来源:Eval.cs

示例4: GetScaleFactor

    internal override ScaleFactor GetScaleFactor(Position pos)
    {
        Debug.Assert(verify_material(pos, strongSide, Value.RookValueMg, 1));
        Debug.Assert(verify_material(pos, weakSide, Value.RookValueMg, 0));

        // Assume strongSide is white and the pawn is on files A-D
        var wksq = normalize(pos, strongSide, pos.square(PieceType.KING, strongSide));
        var bksq = normalize(pos, strongSide, pos.square(PieceType.KING, weakSide));
        var wrsq = normalize(pos, strongSide, pos.square(PieceType.ROOK, strongSide));
        var wpsq = normalize(pos, strongSide, pos.square(PieceType.PAWN, strongSide));
        var brsq = normalize(pos, strongSide, pos.square(PieceType.ROOK, weakSide));

        var f = Square.file_of(wpsq);
        var r = Square.rank_of(wpsq);
        var queeningSq = Square.make_square(f, Rank.RANK_8);
        var tempo = (pos.side_to_move() == strongSide) ? 1 : 0;

        // If the pawn is not too far advanced and the defending king defends the
        // queening square, use the third-rank defence.
        if (r <= Rank.RANK_5 && Utils.distance_Square(bksq, queeningSq) <= 1 && wksq <= Square.SQ_H5
            && (Square.rank_of(brsq) == Rank.RANK_6 || (r <= Rank.RANK_3 && Square.rank_of(wrsq) != Rank.RANK_6)))
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        // The defending side saves a draw by checking from behind in case the pawn
        // has advanced to the 6th rank with the king behind.
        if (r == Rank.RANK_6 && Utils.distance_Square(bksq, queeningSq) <= 1
            && (int)Square.rank_of(wksq) + tempo <= Rank.RANK_6
            && (Square.rank_of(brsq) == Rank.RANK_1 || (tempo == 0 && Utils.distance_File(brsq, wpsq) >= 3)))
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        if (r >= Rank.RANK_6 && bksq == queeningSq && Square.rank_of(brsq) == Rank.RANK_1
            && (tempo == 0 || Utils.distance_Square(wksq, wpsq) >= 2))
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        // White pawn on a7 and rook on a8 is a draw if black's king is on g7 or h7
        // and the black rook is behind the pawn.
        if (wpsq == Square.SQ_A7 && wrsq == Square.SQ_A8 && (bksq == Square.SQ_H7 || bksq == Square.SQ_G7)
            && Square.file_of(brsq) == File.FILE_A
            && (Square.rank_of(brsq) <= Rank.RANK_3 || Square.file_of(wksq) >= File.FILE_D
                || Square.rank_of(wksq) <= Rank.RANK_5))
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        // If the defending king blocks the pawn and the attacking king is too far
        // away, it's a draw.
        if (r <= Rank.RANK_5 && bksq == wpsq + Square.DELTA_N && Utils.distance_Square(wksq, wpsq) - tempo >= 2
            && Utils.distance_Square(wksq, brsq) - tempo >= 2)
        {
            return ScaleFactor.SCALE_FACTOR_DRAW;
        }

        // Pawn on the 7th rank supported by the rook from behind usually wins if the
        // attacking king is closer to the queening square than the defending king,
        // and the defending king cannot gain tempi by threatening the attacking rook.
        if (r == Rank.RANK_7 && f != File.FILE_A && Square.file_of(wrsq) == f && wrsq != queeningSq
            && (Utils.distance_Square(wksq, queeningSq) < Utils.distance_Square(bksq, queeningSq) - 2 + tempo)
            && (Utils.distance_Square(wksq, queeningSq) < Utils.distance_Square(bksq, wrsq) + tempo))
        {
            return ScaleFactor.SCALE_FACTOR_MAX - 2*Utils.distance_Square(wksq, queeningSq);
        }

        // Similar to the above, but with the pawn further back
        if (f != File.FILE_A && Square.file_of(wrsq) == f && wrsq < wpsq
            && (Utils.distance_Square(wksq, queeningSq) < Utils.distance_Square(bksq, queeningSq) - 2 + tempo)
            && (Utils.distance_Square(wksq, wpsq + Square.DELTA_N)
                < Utils.distance_Square(bksq, wpsq + Square.DELTA_N) - 2 + tempo)
            && (Utils.distance_Square(bksq, wrsq) + tempo >= 3
                || (Utils.distance_Square(wksq, queeningSq) < Utils.distance_Square(bksq, wrsq) + tempo
                    && (Utils.distance_Square(wksq, wpsq + Square.DELTA_N) < Utils.distance_Square(bksq, wrsq) + tempo))))
        {
            return ScaleFactor.SCALE_FACTOR_MAX - 8*Utils.distance_Square(wpsq, queeningSq)
                   - 2*Utils.distance_Square(wksq, queeningSq);
        }

        // If the pawn is not far advanced and the defending king is somewhere in
        // the pawn's path, it's probably a draw.
        if (r <= Rank.RANK_4 && bksq > wpsq)
        {
            if (Square.file_of(bksq) == Square.file_of(wpsq))
            {
                return (ScaleFactor) (10);
            }
            if (Utils.distance_File(bksq, wpsq) == 1 && Utils.distance_Square(wksq, bksq) > 2)
            {
                return (ScaleFactor) (24 - 2*Utils.distance_Square(wksq, bksq));
            }
        }
        return ScaleFactor.SCALE_FACTOR_NONE;
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:96,代码来源:Endgame.cs

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

示例6: generate_LEGAL

    /// generate
    /// LEGAL generates all the legal moves in the given position
    private static ExtMoveArrayWrapper generate_LEGAL(Position pos, ExtMoveArrayWrapper moveList)
    {
        var pinned = pos.pinned_pieces(pos.side_to_move());
        var ksq = pos.square(PieceType.KING, pos.side_to_move());
        var cur = moveList.current;

        moveList = pos.checkers() != 0
            ? generate(GenType.EVASIONS, pos, moveList)
            : generate(GenType.NON_EVASIONS, pos, moveList);

        while (cur != moveList.current)
        {
            if ((pinned != 0 || Move.from_sq(moveList[cur]) == ksq || Move.type_of(moveList[cur]) == MoveType.ENPASSANT)
                && !pos.legal(moveList[cur], pinned))
            {
                for (var idx = cur; idx < moveList.current; idx++)
                {
                    moveList.table[idx] = moveList.table[idx + 1];
                }
                --moveList;
            }
            else
            {
                ++cur;
            }
        }

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

示例7: generate_EVASIONS

    /// generate
    /// EVASIONS
    ///     generates all pseudo-legal check evasions when the side
    ///     to move is in check. Returns a pointer to the end of the move list.
    private static ExtMoveArrayWrapper generate_EVASIONS(Position pos, ExtMoveArrayWrapper moveList)
    {
        Debug.Assert(pos.checkers() != 0);

        var us = pos.side_to_move();
        var ksq = pos.square(PieceType.KING, us);
        var sliderAttacks = Bitboard.Create(0);
        var sliders = pos.checkers() & ~pos.pieces_PtPt(PieceType.KNIGHT, PieceType.PAWN);

        // Find all the squares attacked by slider checkers. We will remove them from
        // the king evasions in order to skip known illegal moves, which avoids any
        // useless legality checks later on.
        while (sliders != 0)
        {
            var checksq1 = Utils.pop_lsb(ref sliders);
            sliderAttacks |= Bitboard.XorWithSquare(Utils.LineBB[checksq1, ksq], checksq1);
        }

        // Generate evasions for king, capture and non capture moves
        var b = pos.attacks_from_PtS(PieceType.KING, ksq) & ~pos.pieces_Ct(us) & ~sliderAttacks;
        while (b != 0)
        {
            (moveList).Add(Move.make_move(ksq, Utils.pop_lsb(ref b)));
        }

        if (Bitboard.more_than_one(pos.checkers()))
        {
            return moveList; // Double check, only a king move can save the day
        }

        // Generate blocking evasions or captures of the checking piece
        var checksq = Utils.lsb(pos.checkers());
        var target = Bitboard.OrWithSquare(Utils.between_bb(checksq, ksq), checksq);

        return us == Color.WHITE
            ? generate_all(Color.WHITE, GenType.EVASIONS, pos, moveList, target)
            : generate_all(Color.BLACK, GenType.EVASIONS, pos, moveList, target);
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:42,代码来源:Movegen.cs

示例8: generate_QUIET_CHECKS

    /// generate
    /// QUIET_CHECKS
    ///     generates all pseudo-legal non-captures and knight
    ///     underpromotions that give check. Returns a pointer to the end of the move list.
    private static ExtMoveArrayWrapper generate_QUIET_CHECKS(Position pos, ExtMoveArrayWrapper moveList)
    {
        Debug.Assert(pos.checkers() == 0);

        var us = pos.side_to_move();
        var ci = new CheckInfo(pos);
        var dc = ci.dcCandidates;

        while (dc != 0)
        {
            var from = Utils.pop_lsb(ref dc);
            var pt = Piece.type_of(pos.piece_on(from));

            if (pt == PieceType.PAWN)
            {
                continue; // Will be generated together with direct checks
            }

            var b = pos.attacks_from_PtS(pt, from) & ~pos.pieces();

            if (pt == PieceType.KING)
            {
                b &= ~Utils.PseudoAttacks[PieceType.QUEEN, ci.ksq];
            }

            while (b != 0)
            {
                (moveList).Add(Move.make_move(from, Utils.pop_lsb(ref b)));
            }
        }

        return us == Color.WHITE
            ? generate_all(Color.WHITE, GenType.QUIET_CHECKS, pos, moveList, ~pos.pieces(), ci)
            : generate_all(Color.BLACK, GenType.QUIET_CHECKS, pos, moveList, ~pos.pieces(), ci);
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:39,代码来源:Movegen.cs

示例9: generate

    internal static ExtMoveArrayWrapper generate(GenType Type, Position pos, ExtMoveArrayWrapper moveList)
    {
        switch (Type)
        {
            case GenType.EVASIONS:
                return generate_EVASIONS(pos, moveList);
            case GenType.LEGAL:
                return generate_LEGAL(pos, moveList);
            case GenType.QUIET_CHECKS:
                return generate_QUIET_CHECKS(pos, moveList);
        }

        Debug.Assert(Type == GenType.CAPTURES || Type == GenType.QUIETS || Type == GenType.NON_EVASIONS);
        Debug.Assert(pos.checkers() == 0);

        var us = pos.side_to_move();

        var target = Type == GenType.CAPTURES
            ? pos.pieces_Ct(Color.opposite(us))
            : Type == GenType.QUIETS
                ? ~pos.pieces()
                : Type == GenType.NON_EVASIONS ? ~pos.pieces_Ct(us) : Bitboard.Create(0);

        return us == Color.WHITE
            ? generate_all(Color.WHITE, Type, pos, moveList, target)
            : generate_all(Color.BLACK, Type, pos, moveList, target);
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:27,代码来源:Movegen.cs

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

示例11: evaluate


//.........这里部分代码省略.........
        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))
        {
            if (pos.opposite_bishops())
            {
                // Endgame with opposite-colored bishops and no other pieces (ignoring pawns)
                // is almost a draw, in case of KBP vs KB is even more a draw.
                if (pos.non_pawn_material(Color.WHITE) == Value.BishopValueMg
                    && pos.non_pawn_material(Color.BLACK) == Value.BishopValueMg)
                {
                    sf = Bitboard.more_than_one(pos.pieces_Pt(PieceType.PAWN)) ? (ScaleFactor) (31) : (ScaleFactor) (9);
                }

                // Endgame with opposite-colored bishops, but also other pieces. Still
                // a bit drawish, but not as drawish as with only the two bishops.
                else
                {
                    sf = (ScaleFactor) (46*(int) sf/(int) ScaleFactor.SCALE_FACTOR_NORMAL);
                }
            }
            // Endings where weaker side can place his king in front of the opponent's
            // pawns are drawish.
            else if (Math.Abs(Score.eg_value(score)) <= Value.BishopValueEg && ei.pi.pawn_span(strongSide) <= 1
                     && !pos.pawn_passed(Color.opposite(strongSide), pos.square(PieceType.KING, Color.opposite(strongSide))))
            {
                sf = ei.pi.pawn_span(strongSide) != 0 ? (ScaleFactor) (51) : (ScaleFactor) (37);
            }
        }

        // Scale endgame by number of pawns
        var p = pos.count(PieceType.PAWN, Color.WHITE) + pos.count(PieceType.PAWN, Color.BLACK);
        var vEg = 1 + Math.Abs(Score.eg_value(score));
        sf = (ScaleFactor) (Math.Max((int) sf/2, (int) sf - 8*(int) ScaleFactor.SCALE_FACTOR_NORMAL*(12 - p)/vEg));

        // Interpolate between a middlegame and a (scaled by 'sf') endgame score
        var v = Score.mg_value(score)*(int) (me.game_phase())
                + Score.eg_value(score)*(Phase.PHASE_MIDGAME - me.game_phase())*(int) sf
                /(int) ScaleFactor.SCALE_FACTOR_NORMAL;

        v /= (int) (Phase.PHASE_MIDGAME);

        // In case of tracing add all single evaluation terms
        if (DoTrace)
        {
            add_IdxSt((int) Term.MATERIAL, pos.psq_score());
            add_IdxSt((int) Term.IMBALANCE, me.imbalance());
            add_IdxSt(PieceType.PAWN, ei.pi.pawns_score());
            add_IdxStSt(
                (int) Term.MOBILITY,
                Score.Multiply(mobility[Color.WHITE], Weights[Mobility]),
                Score.Multiply(mobility[Color.BLACK], Weights[Mobility]));
            add_IdxStSt(
                (int) Term.SPACE,
                Score.Multiply(evaluate_space(Color.WHITE, pos, ei), Weights[Space]),
                Score.Multiply(evaluate_space(Color.BLACK, pos, ei), Weights[Space]));
            add_IdxSt((int) Term.TOTAL, score);
        }

        return (pos.side_to_move() == Color.WHITE ? v : -v) + Tempo; // Side to move point of view
    }
开发者ID:torfranz,项目名称:NetFish,代码行数:101,代码来源:Eval.cs


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