本文整理汇总了C#中Position.square方法的典型用法代码示例。如果您正苦于以下问题:C# Position.square方法的具体用法?C# Position.square怎么用?C# Position.square使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.square方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: normalize
// Map the square as if strongSide is white and strongSide's only pawn
// is on the left half of the board.
protected static SquareT normalize(Position pos, ColorT strongSide, SquareT sq)
{
Debug.Assert(pos.count(PieceType.PAWN, strongSide) == 1);
if (Square.file_of(pos.square(PieceType.PAWN, strongSide)) >= File.FILE_E)
{
sq = Square.Create(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
}
if (strongSide == Color.BLACK)
{
sq = Square.opposite(sq);
}
return sq;
}
示例4: 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))
//.........这里部分代码省略.........
示例5: GetScaleFactor
internal override ScaleFactor GetScaleFactor(Position pos)
{
var pawnSq = pos.square(PieceType.PAWN, strongSide);
var bishopSq = pos.square(PieceType.BISHOP, weakSide);
var weakKingSq = pos.square(PieceType.KING, weakSide);
// King needs to get close to promoting pawn to prevent knight from blocking.
// Rules for this are very tricky, so just approximate.
if ((Utils.forward_bb(strongSide, pawnSq) & pos.attacks_from_PtS(PieceType.BISHOP, bishopSq))!=0)
{
return (ScaleFactor) (Utils.distance_Square(weakKingSq, pawnSq));
}
return ScaleFactor.SCALE_FACTOR_NONE;
}
示例6: evaluate
internal static ScoreT evaluate(ColorT Us, Position pos, Entry e)
{
var Them = (Us == Color.WHITE ? Color.BLACK : Color.WHITE);
var Up = (Us == Color.WHITE ? Square.DELTA_N : Square.DELTA_S);
var Right = (Us == Color.WHITE ? Square.DELTA_NE : Square.DELTA_SW);
var Left = (Us == Color.WHITE ? Square.DELTA_NW : Square.DELTA_SE);
BitboardT b;
var score = Score.SCORE_ZERO;
var ourPawns = pos.pieces_CtPt(Us, PieceType.PAWN);
var theirPawns = pos.pieces_CtPt(Them, PieceType.PAWN);
e.passedPawns[Us] = Bitboard.Create(0);
e.kingSquares[Us] = Square.SQ_NONE;
e.semiopenFiles[Us] = 0xFF;
e.pawnAttacks[Us] = Bitboard.shift_bb(Right, ourPawns) | Bitboard.shift_bb(Left, ourPawns);
e.pawnsOnSquares[Us, Color.BLACK] = Bitcount.popcount_Max15(ourPawns & Bitboard.DarkSquares);
e.pawnsOnSquares[Us, Color.WHITE] = pos.count(PieceType.PAWN, Us) - e.pawnsOnSquares[Us, Color.BLACK];
// Loop through all pawns of the current color and score each pawn
for (var idx = 0; idx < 16; idx++)
{
var s = pos.square(PieceType.PAWN, Us, idx);
if (s == Square.SQ_NONE)
{
break;
}
Debug.Assert(pos.piece_on(s) == Piece.make_piece(Us, PieceType.PAWN));
var f = Square.file_of(s);
// This file cannot be semi-open
e.semiopenFiles[Us] &= ~(1 << f);
// Flag the pawn
var neighbours = ourPawns & Utils.adjacent_files_bb(f);
var doubled = ourPawns & Utils.forward_bb(Us, s);
bool opposed = (theirPawns & Utils.forward_bb(Us, s)) != 0;
var passed = (theirPawns & Utils.passed_pawn_mask(Us, s)) == 0;
bool lever = (theirPawns & Utils.StepAttacksBB[Piece.make_piece(Us, PieceType.PAWN), s]) != 0;
var phalanx = neighbours & Utils.rank_bb_St(s);
var supported = neighbours & Utils.rank_bb_St(s - Up);
bool connected = (supported | phalanx) != 0;
var isolated = neighbours == 0;
// Test for backward pawn.
// If the pawn is passed, isolated, lever or connected it cannot be
// backward. If there are friendly pawns behind on adjacent files
// or if it is sufficiently advanced, it cannot be backward either.
bool backward;
if ((passed | isolated | lever | connected) || (ourPawns & Utils.pawn_attack_span(Them, s)) != 0
|| (Rank.relative_rank_CtSt(Us, s) >= Rank.RANK_5))
{
backward = false;
}
else
{
// We now know there are no friendly pawns beside or behind this
// pawn on adjacent files. We now check whether the pawn is
// backward by looking in the forward direction on the adjacent
// files, and picking the closest pawn there.
b = Utils.pawn_attack_span(Us, s) & (ourPawns | theirPawns);
b = Utils.pawn_attack_span(Us, s) & Utils.rank_bb_St(Utils.backmost_sq(Us, b));
// If we have an enemy pawn in the same or next rank, the pawn is
// backward because it cannot advance without being captured.
backward = ((b | Bitboard.shift_bb(Up, b)) & theirPawns) != 0;
}
Debug.Assert(opposed | passed | (Utils.pawn_attack_span(Us, s) & theirPawns) != 0);
// Passed pawns will be properly scored in evaluation because we need
// full attack info to evaluate passed pawns. Only the frontmost passed
// pawn on each file is considered a true passed pawn.
if (passed && doubled == 0)
{
e.passedPawns[Us] = Bitboard.OrWithSquare(e.passedPawns[Us], s);
}
// Score this pawn
if (isolated)
{
score -= Isolated[opposed ? 1 : 0][f];
}
else if (backward)
{
score -= Backward[opposed ? 1 : 0];
}
else if (supported == 0)
{
score -= UnsupportedPawnPenalty;
}
if (connected)
{
//.........这里部分代码省略.........
示例7: 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;
}
示例8: 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);
}
示例9: 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;
}
示例10: generate_moves
internal static ExtMoveArrayWrapper generate_moves(
PieceTypeT pieceType,
bool Checks,
Position pos,
ExtMoveArrayWrapper moveList,
ColorT us,
BitboardT target,
CheckInfo ci)
{
var Pt = (int) pieceType;
Debug.Assert(Pt != PieceType.KING && Pt != PieceType.PAWN);
for(var idx=0; idx<16;idx++)
{
var square = pos.square(pieceType, us, idx);
if (square == Square.SQ_NONE)
{
break;
}
if (Checks)
{
if ((Pt == PieceType.BISHOP || Pt == PieceType.ROOK || Pt == PieceType.QUEEN)
&& (Utils.PseudoAttacks[Pt, square] & target & ci.checkSquares[Pt]) == 0)
{
continue;
}
if (ci.dcCandidates != 0 && Bitboard.AndWithSquare(ci.dcCandidates, square)!=0)
{
continue;
}
}
var b = pos.attacks_from_PtS(pieceType, square) & target;
if (Checks)
{
b &= ci.checkSquares[Pt];
}
while (b != 0)
{
(moveList).Add(Move.make_move(square, Utils.pop_lsb(ref b)));
}
}
return moveList;
}
示例11: GetValue
internal override ValueT GetValue(Position pos)
{
Debug.Assert(verify_material(pos, strongSide, Value.QueenValueMg, 0));
Debug.Assert(verify_material(pos, weakSide, Value.RookValueMg, 0));
var winnerKSq = pos.square(PieceType.KING, strongSide);
var loserKSq = pos.square(PieceType.KING, weakSide);
var result = Value.QueenValueEg - Value.RookValueEg + PushToEdges[loserKSq]
+ PushClose[Utils.distance_Square(winnerKSq, loserKSq)];
return strongSide == pos.side_to_move() ? result : -result;
}
示例12: 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]);
}