本文整理汇总了C#中Position.pawn_passed方法的典型用法代码示例。如果您正苦于以下问题:C# Position.pawn_passed方法的具体用法?C# Position.pawn_passed怎么用?C# Position.pawn_passed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.pawn_passed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
示例2: GetScaleFactor
internal override ScaleFactor GetScaleFactor(Position pos)
{
Debug.Assert(verify_material(pos, strongSide, Value.RookValueMg, 2));
Debug.Assert(verify_material(pos, weakSide, Value.RookValueMg, 1));
var wpsq1 = pos.square(PieceType.PAWN, strongSide, 0);
var wpsq2 = pos.square(PieceType.PAWN, strongSide, 1);
var bksq = pos.square(PieceType.KING, weakSide);
// Does the stronger side have a passed pawn?
if (pos.pawn_passed(strongSide, wpsq1) || pos.pawn_passed(strongSide, wpsq2))
{
return ScaleFactor.SCALE_FACTOR_NONE;
}
var r = Math.Max(Rank.relative_rank_CtSt(strongSide, wpsq1), Rank.relative_rank_CtSt(strongSide, wpsq2));
if (Utils.distance_File(bksq, wpsq1) <= 1 && Utils.distance_File(bksq, wpsq2) <= 1
&& Rank.relative_rank_CtSt(strongSide, bksq) > r)
{
switch (r)
{
case 1 /*Rank.RANK_2*/:
return (ScaleFactor) (9);
case 2 /*Rank.RANK_3*/:
return (ScaleFactor) (10);
case 3 /*Rank.RANK_4*/:
return (ScaleFactor) (14);
case 4 /*Rank.RANK_5*/:
return (ScaleFactor) (21);
case 5 /*Rank.RANK_6*/:
return (ScaleFactor) (44);
default:
Debug.Assert(false);
break;
}
}
return ScaleFactor.SCALE_FACTOR_NONE;
}
示例3: evaluate_passed_pawns
// evaluate_passed_pawns() evaluates the passed pawns of the given color
private static ScoreT evaluate_passed_pawns(ColorT Us, bool DoTrace, Position pos, EvalInfo ei)
{
var Them = (Us == Color.WHITE ? Color.BLACK : Color.WHITE);
var score = Score.SCORE_ZERO;
var b = ei.pi.passed_pawns(Us);
while (b!=0)
{
var s = Utils.pop_lsb(ref b);
Debug.Assert(pos.pawn_passed(Us, s));
int r = Rank.relative_rank_CtSt(Us, s) - Rank.RANK_2;
var rr = r*(r - 1);
ValueT mbonus = Passed[(int) Phase.MG][r], ebonus = Passed[(int) Phase.EG][r];
if (rr != 0)
{
var blockSq = s + Square.pawn_push(Us);
// Adjust bonus based on the king's proximity
ebonus += Utils.distance_Square(pos.square(PieceType.KING, Them), blockSq)*5*rr
- Utils.distance_Square(pos.square(PieceType.KING, Us), blockSq)*2*rr;
// If blockSq is not the queening square then consider also a second push
if (Rank.relative_rank_CtSt(Us, blockSq) != Rank.RANK_8)
{
ebonus -= Utils.distance_Square(pos.square(PieceType.KING, Us), blockSq + Square.pawn_push(Us))*rr;
}
// If the pawn is free to advance, then increase the bonus
if (pos.empty(blockSq))
{
// If there is a rook or queen attacking/defending the pawn from behind,
// consider all the squaresToQueen. Otherwise consider only the squares
// in the pawn's path attacked or occupied by the enemy.
BitboardT squaresToQueen;
BitboardT unsafeSquares;
var defendedSquares = unsafeSquares = squaresToQueen = Utils.forward_bb(Us, s);
var bb = Utils.forward_bb(Them, s) & pos.pieces_PtPt(PieceType.ROOK, PieceType.QUEEN)
& pos.attacks_from_PtS(PieceType.ROOK, s);
if ((pos.pieces_Ct(Us) & bb)==0)
{
defendedSquares &= ei.attackedBy[Us, PieceType.ALL_PIECES];
}
if ((pos.pieces_Ct(Them) & bb) == 0)
{
unsafeSquares &= ei.attackedBy[Them, PieceType.ALL_PIECES] | pos.pieces_Ct(Them);
}
// If there aren't any enemy attacks, assign a big bonus. Otherwise
// assign a smaller bonus if the block square isn't attacked.
var k = unsafeSquares == 0 ? 18 : Bitboard.AndWithSquare(unsafeSquares, blockSq)==0 ? 8 : 0;
// If the path to queen is fully defended, assign a big bonus.
// Otherwise assign a smaller bonus if the block square is defended.
if (defendedSquares == squaresToQueen)
{
k += 6;
}
else if (Bitboard.AndWithSquare(defendedSquares, blockSq)!=0)
{
k += 4;
}
mbonus += k*rr;
ebonus += k*rr;
}
else if (Bitboard.AndWithSquare(pos.pieces_Ct(Us), blockSq)!=0)
{
mbonus += rr*3 + r*2 + 3;
ebonus += rr + r*2;
}
} // rr != 0
if (pos.count(PieceType.PAWN, Us) < pos.count(PieceType.PAWN, Them))
{
ebonus += ebonus/4;
}
score += Score.make_score(mbonus, ebonus) + PassedFile[Square.file_of(s)];
}
if (DoTrace)
{
add_IdxCtSt((int) Term.PASSED, Us, Score.Multiply(score, Weights[PassedPawns]));
}
// Add the scores to the middlegame and endgame eval
return Score.Multiply(score, Weights[PassedPawns]);
}