本文整理汇总了C#中Position.piece_on方法的典型用法代码示例。如果您正苦于以下问题:C# Position.piece_on方法的具体用法?C# Position.piece_on怎么用?C# Position.piece_on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.piece_on方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: search
//.........这里部分代码省略.........
var ci2 = new CheckInfo(pos);
while ((move = mp2.next_move(false)) != Move.MOVE_NONE)
if (pos.legal(move, ci2.pinned))
{
stack.currentMove = move;
pos.do_move(move, st, pos.gives_check(move, ci2));
value =
-search(NodeType.NonPV, false, pos, new StackArrayWrapper(ss.table, ss.current + 1), -rbeta,
-rbeta + 1, rdepth, !cutNode);
pos.undo_move(move);
if (value >= rbeta)
return value;
}
}
// Step 10. Internal iterative deepening (skipped when in check)
if (depth >= (PvNode ? 5*Depth.ONE_PLY_C : 8*Depth.ONE_PLY_C)
&& ttMove == 0
&& (PvNode || stack.staticEval + 256 >= beta))
{
var d = depth - 2*Depth.ONE_PLY - (PvNode ? Depth.DEPTH_ZERO : depth/4);
stack.skipEarlyPruning = true;
search(PvNode ? NodeType.PV : NodeType.NonPV, false, pos, ss, alpha, beta, d, true);
stack.skipEarlyPruning = false;
tte = TranspositionTable.probe(posKey, out ttHit);
ttMove = ttHit ? tte.move() : Move.MOVE_NONE;
}
moves_loop: // When in check and at SpNode search starts from here
var prevMoveSq = Move.to_sq(stackMinus1.currentMove);
var countermove = Countermoves.table[pos.piece_on(prevMoveSq), prevMoveSq];
var mp = new MovePicker(pos, ttMove, depth, History, CounterMovesHistory, countermove, ss);
var ci = new CheckInfo(pos);
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
var improving = stack.staticEval >= stackMinus2.staticEval
|| stack.staticEval == Value.VALUE_NONE
|| stackMinus2.staticEval == Value.VALUE_NONE;
var singularExtensionNode = !RootNode
&& !SpNode
&& depth >= 8*Depth.ONE_PLY_C
&& ttMove != Move.MOVE_NONE
/* && ttValue != Value.VALUE_NONE Already implicit in the next condition */
&& Math.Abs(ttValue) < Value.VALUE_KNOWN_WIN
&& excludedMove == 0// Recursive singular search is not allowed
&& ((tte.bound() & Bound.BOUND_LOWER) != 0)
&& tte.depth() >= depth - 3*Depth.ONE_PLY_C;
var quietsSearched = new MoveT[64];
// Step 11. Loop through moves
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
while ((move = mp.next_move(SpNode)) != Move.MOVE_NONE)
{
Utils.WriteToLog($"mp.next_move = {(int) move}");
Debug.Assert(Move.is_ok(move));
if (move == excludedMove)
continue;
// At root obey the "searchmoves" option and skip moves not listed in Root
// Move List. As a consequence any illegal move is also skipped. In MultiPV
// mode we also skip PV moves which have been already searched.
示例2: 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)
{
//.........这里部分代码省略.........
示例3: update_stats
// update_stats() updates killers, history, countermove history and
// countermoves stats for a quiet best move.
private static void update_stats(Position pos, StackArrayWrapper ss, MoveT move,
Depth depth, MoveT[] quiets, int quietsCnt)
{
if (ss[ss.current].killers0 != move)
{
ss[ss.current].killers1 = ss[ss.current].killers0;
ss[ss.current].killers0 = move;
}
var bonus = Value.Create((depth/Depth.ONE_PLY)*(depth/Depth.ONE_PLY));
var prevSq = Move.to_sq(ss[ss.current - 1].currentMove);
var cmh = CounterMovesHistory.table[pos.piece_on(prevSq), prevSq];
History.updateH(pos.moved_piece(move), Move.to_sq(move), bonus);
if (Move.is_ok(ss[ss.current - 1].currentMove))
{
Countermoves.update(pos.piece_on(prevSq), prevSq, move);
cmh.updateCMH(pos.moved_piece(move), Move.to_sq(move), bonus);
}
// Decrease all the other played quiet moves
for (var i = 0; i < quietsCnt; ++i)
{
History.updateH(pos.moved_piece(quiets[i]), Move.to_sq(quiets[i]), -bonus);
if (Move.is_ok(ss[ss.current - 1].currentMove))
cmh.updateCMH(pos.moved_piece(quiets[i]), Move.to_sq(quiets[i]), -bonus);
}
// Extra penalty for PV move in previous ply when it gets refuted
if (Move.is_ok(ss[ss.current - 2].currentMove) && ss[ss.current - 1].moveCount == 1 &&
pos.captured_piece_type()==0)
{
var prevPrevSq = Move.to_sq(ss[ss.current - 2].currentMove);
var ttMoveCmh = CounterMovesHistory.table[pos.piece_on(prevPrevSq), prevPrevSq];
ttMoveCmh.updateCMH(pos.piece_on(prevSq), prevSq, -bonus - 2*depth/Depth.ONE_PLY - 1);
}
}
示例4: qsearch
//.........这里部分代码省略.........
// 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;
}
// Initialize a MovePicker object for the current position, and prepare
// to search the moves. Because the depth is <= 0 here, only captures,
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
// be generated.
var mp = new MovePicker(pos, ttMove, depth, History, CounterMovesHistory,
Move.to_sq(previousStack.currentMove));
var ci = new CheckInfo(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs
MoveT move;
MoveT bestMove = Move.MOVE_NONE;
while ((move = mp.next_move(false)) != Move.MOVE_NONE)
{
Debug.Assert(Move.is_ok(move));
var givesCheck = Move.type_of(move) == MoveType.NORMAL && ci.dcCandidates == 0
? Bitboard.AndWithSquare(ci.checkSquares[Piece.type_of(pos.piece_on(Move.from_sq(move)))], Move.to_sq(move))!=0
: pos.gives_check(move, ci);
// Futility pruning
if (!InCheck
&& !givesCheck
&& futilityBase > -Value.VALUE_KNOWN_WIN
&& !pos.advanced_pawn_push(move))
{
Debug.Assert(Move.type_of(move) != MoveType.ENPASSANT); // Due to !pos.advanced_pawn_push
var futilityValue = futilityBase + Value.PieceValue[(int) Phase.EG][pos.piece_on(Move.to_sq(move))];
if (futilityValue <= alpha)
{
bestValue = Value.Create(Math.Max(bestValue, futilityValue));
continue;
}
if (futilityBase <= alpha && pos.see(move) <= Value.VALUE_ZERO)
{
bestValue = Value.Create(Math.Max(bestValue, futilityBase));
continue;
}
}
// Detect non-capture evasions that are candidates to be pruned
var evasionPrunable = InCheck
&& bestValue > Value.VALUE_MATED_IN_MAX_PLY
&& !pos.capture(move);
// Don't search moves with negative SEE values
if ((!InCheck || evasionPrunable)
示例5: 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);
}
示例6: evaluate_threats
// evaluate_threats() assigns bonuses according to the type of attacking piece
// and the type of attacked one.
private static ScoreT evaluate_threats(ColorT Us, bool DoTrace, Position pos, EvalInfo ei)
{
var Them = (Us == Color.WHITE ? Color.BLACK : Color.WHITE);
var Up = (Us == Color.WHITE ? Square.DELTA_N : Square.DELTA_S);
var Left = (Us == Color.WHITE ? Square.DELTA_NW : Square.DELTA_SE);
var Right = (Us == Color.WHITE ? Square.DELTA_NE : Square.DELTA_SW);
var TRank2BB = (Us == Color.WHITE ? Bitboard.Rank2BB : Bitboard.Rank7BB);
var TRank7BB = (Us == Color.WHITE ? Bitboard.Rank7BB : Bitboard.Rank2BB);
const int Defended = 0;
const int Weak = 1;
const int Minor = 0;
const int Rook = 1;
BitboardT b;
var score = Score.SCORE_ZERO;
// Non-pawn enemies attacked by a pawn
var weak = (pos.pieces_Ct(Them) ^ pos.pieces_CtPt(Them, PieceType.PAWN)) & ei.attackedBy[Us, PieceType.PAWN];
if (weak!=0)
{
b = pos.pieces_CtPt(Us, PieceType.PAWN)
& (~ei.attackedBy[Them, PieceType.ALL_PIECES] | ei.attackedBy[Us, PieceType.ALL_PIECES]);
var safeThreats = (Bitboard.shift_bb(Right, b) | Bitboard.shift_bb(Left, b)) & weak;
if ((weak ^ safeThreats)!=0)
{
score += ThreatenedByHangingPawn;
}
while (safeThreats!=0)
{
score += ThreatenedByPawn[Piece.type_of(pos.piece_on(Utils.pop_lsb(ref safeThreats)))];
}
}
// Non-pawn enemies defended by a pawn
var defended = (pos.pieces_Ct(Them) ^ pos.pieces_CtPt(Them, PieceType.PAWN)) & ei.attackedBy[Them, PieceType.PAWN];
// Add a bonus according to the kind of attacking pieces
if (defended!=0)
{
b = defended & (ei.attackedBy[Us, PieceType.KNIGHT] | ei.attackedBy[Us, PieceType.BISHOP]);
while (b!=0)
{
score += Threat[Defended][Minor][Piece.type_of(pos.piece_on(Utils.pop_lsb(ref b)))];
}
b = defended & ei.attackedBy[Us, PieceType.ROOK];
while (b!=0)
{
score += Threat[Defended][Rook][Piece.type_of(pos.piece_on(Utils.pop_lsb(ref b)))];
}
}
// Enemies not defended by a pawn and under our attack
weak = pos.pieces_Ct(Them) & ~ei.attackedBy[Them, PieceType.PAWN] & ei.attackedBy[Us, PieceType.ALL_PIECES];
// Add a bonus according to the kind of attacking pieces
if (weak!=0)
{
b = weak & (ei.attackedBy[Us, PieceType.KNIGHT] | ei.attackedBy[Us, PieceType.BISHOP]);
while (b!=0)
{
score += Threat[Weak][Minor][Piece.type_of(pos.piece_on(Utils.pop_lsb(ref b)))];
}
b = weak & ei.attackedBy[Us, PieceType.ROOK];
while (b!=0)
{
score += Threat[Weak][Rook][Piece.type_of(pos.piece_on(Utils.pop_lsb(ref b)))];
}
b = weak & ~ei.attackedBy[Them, PieceType.ALL_PIECES];
if (b!=0)
{
score += Hanging*Bitcount.popcount_Max15(b);
}
b = weak & ei.attackedBy[Us, PieceType.KING];
if (b!=0)
{
score += Bitboard.more_than_one(b) ? KingOnMany : KingOnOne;
}
}
// Bonus if some pawns can safely push and attack an enemy piece
b = pos.pieces_CtPt(Us, PieceType.PAWN) & ~TRank7BB;
b = Bitboard.shift_bb(Up, b | (Bitboard.shift_bb(Up, b & TRank2BB) & ~pos.pieces()));
b &= ~pos.pieces() & ~ei.attackedBy[Them, PieceType.PAWN]
& (ei.attackedBy[Us, PieceType.ALL_PIECES] | ~ei.attackedBy[Them, PieceType.ALL_PIECES]);
b = (Bitboard.shift_bb(Left, b) | Bitboard.shift_bb(Right, b)) & pos.pieces_Ct(Them)
& ~ei.attackedBy[Us, PieceType.PAWN];
//.........这里部分代码省略.........
示例7: 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);
}