本文整理汇总了C#中Position.can_castle方法的典型用法代码示例。如果您正苦于以下问题:C# Position.can_castle方法的具体用法?C# Position.can_castle怎么用?C# Position.can_castle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.can_castle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: do_king_safety
/// Entry::do_king_safety() calculates a bonus for king safety. It is called only
/// when king square changes, which is about 20% of total king_safety() calls.
private ScoreT do_king_safety(ColorT Us, Position pos, SquareT ksq)
{
kingSquares[Us] = ksq;
castlingRights[Us] = pos.can_castle(Us);
var minKingPawnDistance = 0;
var pawns = pos.pieces_CtPt(Us, PieceType.PAWN);
if (pawns != 0)
{
while ((Utils.DistanceRingBB[ksq, minKingPawnDistance++] & pawns) == 0)
{
}
}
if (Rank.relative_rank_CtSt(Us, ksq) > Rank.RANK_4)
{
return Score.make_score(0, -16*minKingPawnDistance);
}
var bonus = shelter_storm(Us, pos, ksq);
// If we can castle use the bonus after the castling if it is bigger
if (pos.can_castle(Movegen.MakeCastling(Us, CastlingSide.KING_SIDE)))
{
bonus = Value.Create(
Math.Max(bonus, shelter_storm(Us, pos, Square.relative_square(Us, Square.SQ_G1))));
}
if (pos.can_castle(Movegen.MakeCastling(Us, CastlingSide.QUEEN_SIDE)))
{
bonus = Value.Create(
Math.Max(bonus, shelter_storm(Us, pos, Square.relative_square(Us, Square.SQ_C1))));
}
return Score.make_score(bonus, -16*minKingPawnDistance);
}
示例3: king_safety
internal ScoreT king_safety(ColorT Us, Position pos, SquareT ksq)
{
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
? kingSafety[Us]
: (kingSafety[Us] = do_king_safety(Us, pos, ksq));
}
示例4: generate_all
internal static ExtMoveArrayWrapper generate_all(
ColorT Us,
GenType Type,
Position pos,
ExtMoveArrayWrapper moveList,
BitboardT target,
CheckInfo ci = null)
{
var Checks = Type == GenType.QUIET_CHECKS;
moveList = generate_pawn_moves(Us, Type, pos, moveList, target, ci);
moveList = generate_moves(PieceType.KNIGHT, Checks, pos, moveList, Us, target, ci);
moveList = generate_moves(PieceType.BISHOP, Checks, pos, moveList, Us, target, ci);
moveList = generate_moves(PieceType.ROOK, Checks, pos, moveList, Us, target, ci);
moveList = generate_moves(PieceType.QUEEN, Checks, pos, moveList, Us, target, ci);
if (Type != GenType.QUIET_CHECKS && Type != GenType.EVASIONS)
{
var ksq = pos.square(PieceType.KING, Us);
var b = pos.attacks_from_PtS(PieceType.KING, ksq) & target;
while (b != 0)
{
(moveList).Add(Move.make_move(ksq, Utils.pop_lsb(ref b)));
}
}
if (Type != GenType.CAPTURES && Type != GenType.EVASIONS && pos.can_castle(Us) != 0)
{
if (pos.is_chess960())
{
moveList = generate_castling(
MakeCastling(Us, CastlingSide.KING_SIDE),
Checks,
true,
pos,
moveList,
Us,
ci);
moveList = generate_castling(
MakeCastling(Us, CastlingSide.QUEEN_SIDE),
Checks,
true,
pos,
moveList,
Us,
ci);
}
else
{
moveList = generate_castling(
MakeCastling(Us, CastlingSide.KING_SIDE),
Checks,
false,
pos,
moveList,
Us,
ci);
moveList = generate_castling(
MakeCastling(Us, CastlingSide.QUEEN_SIDE),
Checks,
false,
pos,
moveList,
Us,
ci);
}
}
return moveList;
}
示例5: evaluate_pieces
//.........这里部分代码省略.........
var bb = b & ei.attackedBy[Them, PieceType.KING];
if (bb!=0)
{
ei.kingAdjacentZoneAttacksCount[Us] += Bitcount.popcount_Max15(bb);
}
}
if (Pt == PieceType.QUEEN)
{
b &=
~(ei.attackedBy[Them, PieceType.KNIGHT] | ei.attackedBy[Them, PieceType.BISHOP]
| ei.attackedBy[Them, PieceType.ROOK]);
}
var mob = Pt == PieceType.QUEEN
? Bitcount.popcount_Full(b & mobilityArea[Us])
: Bitcount.popcount_Max15(b & mobilityArea[Us]);
mobility[Us] += MobilityBonus[Pt][mob];
if (Pt == PieceType.BISHOP || Pt == PieceType.KNIGHT)
{
// Bonus for outpost square
if (Rank.relative_rank_CtSt(Us, s) >= Rank.RANK_4 && Rank.relative_rank_CtSt(Us, s) <= Rank.RANK_6
&& (pos.pieces_CtPt(Them, PieceType.PAWN) & Utils.pawn_attack_span(Us, s))==0)
{
score +=
Outpost[Pt == PieceType.BISHOP ? 1 : 0][Bitboard.AndWithSquare(ei.attackedBy[Us, PieceType.PAWN], s)!=0 ? 1 : 0];
}
// Bonus when behind a pawn
if (Rank.relative_rank_CtSt(Us, s) < Rank.RANK_5 && Bitboard.AndWithSquare(pos.pieces_Pt(PieceType.PAWN), (s + Square.pawn_push(Us)))!=0)
{
score += MinorBehindPawn;
}
// Penalty for pawns on same color square of bishop
if (Pt == PieceType.BISHOP)
{
score -= BishopPawns*ei.pi.pawns_on_same_color_squares(Us, s);
}
// An important Chess960 pattern: A cornered bishop blocked by a friendly
// pawn diagonally in front of it is a very serious problem, especially
// when that pawn is also blocked.
if (Pt == PieceType.BISHOP && pos.is_chess960()
&& (s == Square.relative_square(Us, Square.SQ_A1) || s == Square.relative_square(Us, Square.SQ_H1)))
{
var d = Square.pawn_push(Us) + (Square.file_of(s) == File.FILE_A ? Square.DELTA_E : Square.DELTA_W);
if (pos.piece_on(s + d) == Piece.make_piece(Us, PieceType.PAWN))
{
score -= !pos.empty(s + d + Square.pawn_push(Us))
? TrappedBishopA1H1*4
: pos.piece_on(s + d + d) == Piece.make_piece(Us, PieceType.PAWN)
? TrappedBishopA1H1*2
: TrappedBishopA1H1;
}
}
}
if (Pt == PieceType.ROOK)
{
// Bonus for aligning with enemy pawns on the same rank/file
if (Rank.relative_rank_CtSt(Us, s) >= Rank.RANK_5)
{
var alignedPawns = pos.pieces_CtPt(Them, PieceType.PAWN) & Utils.PseudoAttacks[PieceType.ROOK, s];
if (alignedPawns!=0)
{
score += Bitcount.popcount_Max15(alignedPawns)*RookOnPawn;
}
}
// Bonus when on an open or semi-open file
if (ei.pi.semiopen_file(Us, Square.file_of(s)) != 0)
{
score += ei.pi.semiopen_file(Them, Square.file_of(s)) != 0 ? RookOnOpenFile : RookOnSemiOpenFile;
}
// Penalize when trapped by the king, even more if king cannot castle
if (mob <= 3 && 0 == ei.pi.semiopen_file(Us, Square.file_of(s)))
{
var ksq = pos.square(PieceType.KING, Us);
if (((Square.file_of(ksq) < File.FILE_E) == (Square.file_of(s) < Square.file_of(ksq)))
&& (Square.rank_of(ksq) == Square.rank_of(s) || Rank.relative_rank_CtSt(Us, ksq) == Rank.RANK_1)
&& 0 == ei.pi.semiopen_side(Us, Square.file_of(ksq), Square.file_of(s) < Square.file_of(ksq)))
{
score -= (TrappedRook - Score.make_score(mob*22, 0))*(1 + (pos.can_castle(Us) == 0 ? 1 : 0));
}
}
}
}
if (DoTrace)
{
add_IdxCtSt(Pt, Us, score);
}
// Recursively call evaluate_pieces() of next piece type until KING excluded
return score - evaluate_pieces(NextPt, Them, DoTrace, pos, ei, mobility, mobilityArea);
}