本文整理汇总了C#中Portfish.Position.pieces方法的典型用法代码示例。如果您正苦于以下问题:C# Position.pieces方法的具体用法?C# Position.pieces怎么用?C# Position.pieces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfish.Position
的用法示例。
在下文中一共展示了Position.pieces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: evaluate_pieces_of_color
// evaluate_pieces_of_color<>() assigns bonuses and penalties to all the
// pieces of a given color.
private static int evaluate_pieces_of_color(int Us, bool Trace, Position pos, EvalInfo ei, ref int mobility)
{
var Them = (Us == ColorC.WHITE ? ColorC.BLACK : ColorC.WHITE);
mobility = ScoreC.SCORE_ZERO;
// Do not include in mobility squares protected by enemy pawns or occupied by our pieces
var mobilityArea = ~(ei.attackedBy[Them][PieceTypeC.PAWN] | pos.byColorBB[Us]);
#region Evaluate pieces
ulong between = 0;
var plPos = 0;
int s, ksq;
int mob;
int f;
int score, scores = ScoreC.SCORE_ZERO;
var attackedByThemKing = ei.attackedBy[Them][PieceTypeC.KING];
var attackedByThemPawn = ei.attackedBy[Them][PieceTypeC.PAWN];
var kingRingThem = ei.kingRing[Them];
for (var Piece = PieceTypeC.KNIGHT; Piece < PieceTypeC.KING; Piece++)
{
score = ScoreC.SCORE_ZERO;
ei.attackedBy[Us][Piece] = 0;
var pl = pos.pieceList[Us][Piece];
plPos = 0;
while ((s = pl[plPos++]) != SquareC.SQ_NONE)
{
// Find attacked squares, including x-ray attacks for bishops and rooks
if (Piece == PieceTypeC.KNIGHT)
{
between = Utils.StepAttacksBB_KNIGHT[s];
}
else if (Piece == PieceTypeC.QUEEN)
{
#if X64
b = Utils.BAttacks[s][(((pos.occupied_squares & Utils.BMasks[s]) * Utils.BMagics[s]) >> Utils.BShifts[s])] | Utils.RAttacks[s][(((pos.occupied_squares & Utils.RMasks[s]) * Utils.RMagics[s]) >> Utils.RShifts[s])];
#else
between = Utils.bishop_attacks_bb(s, pos.occupied_squares)
| Utils.rook_attacks_bb(s, pos.occupied_squares);
#endif
}
else if (Piece == PieceTypeC.BISHOP)
{
#if X64
b = Utils.BAttacks[s][(((
(pos.occupied_squares ^ (pos.byTypeBB[PieceTypeC.QUEEN] & pos.byColorBB[Us]))
& Utils.BMasks[s]) * Utils.BMagics[s]) >> Utils.BShifts[s])];
#else
between = Utils.bishop_attacks_bb(s, pos.occupied_squares ^ pos.pieces_PTC(PieceTypeC.QUEEN, Us));
#endif
}
else if (Piece == PieceTypeC.ROOK)
{
#if X64
b = Utils.RAttacks[s][(((
(pos.occupied_squares ^ ((pos.byTypeBB[PieceTypeC.ROOK] | pos.byTypeBB[PieceTypeC.QUEEN]) & pos.byColorBB[Us]))
& Utils.RMasks[s]) * Utils.RMagics[s]) >> Utils.RShifts[s])];
#else
between = Utils.rook_attacks_bb(
s,
pos.occupied_squares ^ pos.pieces(PieceTypeC.ROOK, PieceTypeC.QUEEN, Us));
#endif
}
// Update attack info
ei.attackedBy[Us][Piece] |= between;
// King attacks
if ((between & kingRingThem) != 0)
{
ei.kingAttackersCount[Us]++;
ei.kingAttackersWeight[Us] += KingAttackWeights[Piece];
var bb = (between & attackedByThemKing); //ei.attackedBy[Them][PieceTypeC.KING]);
if (bb != 0)
{
#if X64
bb -= (bb >> 1) & 0x5555555555555555UL;
bb = ((bb >> 2) & 0x3333333333333333UL) + (bb & 0x3333333333333333UL);
ei.kingAdjacentZoneAttacksCount[Us] += (int)((bb * 0x1111111111111111UL) >> 60);
#else
ei.kingAdjacentZoneAttacksCount[Us] += Bitcount.popcount_1s_Max15(bb);
#endif
}
}
// Mobility
#if X64
Bitboard bmob = b & mobilityArea;
if (Piece != PieceTypeC.QUEEN)
{
bmob -= (bmob >> 1) & 0x5555555555555555UL;
bmob = ((bmob >> 2) & 0x3333333333333333UL) + (bmob & 0x3333333333333333UL);
mob = (int)((bmob * 0x1111111111111111UL) >> 60);
}
else
{
//.........这里部分代码省略.........
示例2: refutes
// refutes() tests whether a 'first' move is able to defend against a 'second'
// opponent's move. In this case will not be pruned. Normally the second move
// is the threat (the best move returned from a null search that fails low).
private static bool refutes(Position pos, int move, int threat)
{
Debug.Assert(Utils.is_ok_M(move));
Debug.Assert(Utils.is_ok_M(threat));
Square mfrom = Utils.from_sq(move);
Square mto = Utils.to_sq(move);
Square tfrom = Utils.from_sq(threat);
Square tto = Utils.to_sq(threat);
// Don't prune moves of the threatened piece
if (mfrom == tto)
{
return true;
}
// If the threatened piece has value less than or equal to the value of the
// threat piece, don't prune moves which defend it.
if (pos.is_capture(threat)
&& (Position.PieceValue[PhaseC.MG][pos.piece_on(tfrom)] >= Position.PieceValue[PhaseC.MG][pos.piece_on(tto)]
|| Utils.type_of(pos.piece_on(tfrom)) == PieceTypeC.KING))
{
// Update occupancy as if the piece and the threat are moving
var occ = Utils.xor_bit(Utils.xor_bit(Utils.xor_bit(pos.occupied_squares, mfrom), mto), tfrom);
Piece piece = pos.piece_on(mfrom);
// The piece moved in 'to' attacks the square 's' ?
if (Utils.bit_is_set(Position.attacks_from(piece, mto, occ), tto) != 0)
{
return true;
}
// Scan for possible X-ray attackers behind the moved piece
var xray = (Utils.rook_attacks_bb(tto, occ)
& pos.pieces(PieceTypeC.ROOK, PieceTypeC.QUEEN, Utils.color_of(piece)))
| (Utils.bishop_attacks_bb(tto, occ)
& pos.pieces(PieceTypeC.BISHOP, PieceTypeC.QUEEN, Utils.color_of(piece)));
// Verify attackers are triggered by our move and not already existing
if ((xray != 0) && ((xray ^ (xray & pos.attacks_from_QUEEN(tto))) != 0))
{
return true;
}
}
// Don't prune safe moves which block the threat path
if ((Utils.bit_is_set(Utils.between_bb(tfrom, tto), mto) != 0) && pos.see(move, true) >= 0)
{
return true;
}
return false;
}