本文整理汇总了C#中Portfish.Position.piece_moved方法的典型用法代码示例。如果您正苦于以下问题:C# Position.piece_moved方法的具体用法?C# Position.piece_moved怎么用?C# Position.piece_moved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfish.Position
的用法示例。
在下文中一共展示了Position.piece_moved方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: move_to_san
/// move_to_san() takes a position and a move as input, where it is assumed
/// that the move is a legal move for the position. The return value is
/// a string containing the move in short algebraic notation.
internal static string move_to_san(Position pos, Move m)
{
if (m == MoveC.MOVE_NONE)
return "(none)";
if (m == MoveC.MOVE_NULL)
return "(null)";
Debug.Assert(is_ok_M(m));
Bitboard attackers;
bool ambiguousMove, ambiguousFile, ambiguousRank;
Square sq, from = from_sq(m);
Square to = to_sq(m);
PieceType pt = type_of(pos.piece_moved(m));
StringBuilder san = new StringBuilder();
if (is_castle(m))
san.Append((to_sq(m) < from_sq(m) ? "O-O-O" : "O-O"));
else
{
if (pt != PieceTypeC.PAWN)
{
san.Append(piece_type_to_char(pt).ToString());
// Disambiguation if we have more then one piece with destination 'to'
// note that for pawns is not needed because starting file is explicit.
attackers = pos.attackers_to(to) & pos.pieces_PTC(pt, pos.sideToMove);
xor_bit(ref attackers, from);
ambiguousMove = ambiguousFile = ambiguousRank = false;
while (attackers != 0)
{
sq = pop_1st_bit(ref attackers);
// Pinned pieces are not included in the possible sub-set
if (!pos.pl_move_is_legal(make_move(sq, to), pos.pinned_pieces()))
continue;
if (file_of(sq) == file_of(from))
ambiguousFile = true;
if (rank_of(sq) == rank_of(from))
ambiguousRank = true;
ambiguousMove = true;
}
if (ambiguousMove)
{
if (!ambiguousFile)
san.Append(file_to_char(file_of(from)));
else if (!ambiguousRank)
san.Append(rank_to_char(rank_of(from)));
else
san.Append(square_to_string(from));
}
}
if (pos.is_capture(m))
{
if (pt == PieceTypeC.PAWN)
san.Append(file_to_char(file_of(from)));
san.Append('x');
}
san.Append(square_to_string(to));
if (is_promotion(m))
{
san.Append('=');
san.Append(piece_type_to_char(promotion_type(m)));
}
}
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
if (pos.move_gives_check(m, ci))
{
StateInfo st = new StateInfo();
pos.do_move(m, st);
MList mlist = MListBroker.GetObject(); mlist.pos = 0;
Movegen.generate_legal(pos, mlist.moves, ref mlist.pos);
san.Append(mlist.pos > 0 ? "+" : "#");
MListBroker.Free();
pos.undo_move(m);
}
CheckInfoBroker.Free();
return san.ToString();
}
示例2: search
//.........这里部分代码省略.........
ss[ssPos].skipNullMove = 0;
ss[ssPos].excludedMove = MoveC.MOVE_NONE;
if (value < rBeta)
ext = DepthC.ONE_PLY;
}
}
// Update current move (this must be done after singular extension search)
newDepth = depth - DepthC.ONE_PLY + ext;
// Step 13. Futility pruning (is omitted in PV nodes)
if (!PvNode && !inCheck
&& !captureOrPromotion
&& !dangerous
&& move != ttMove
&& (bestValue > ValueC.VALUE_MATED_IN_MAX_PLY || bestValue == -ValueC.VALUE_INFINITE)
&& !Utils.is_castle(move))
{
// Move count based pruning
if (moveCount >= futility_move_count(depth)
&& ((threatMove == 0) || !connected_threat(pos, move, threatMove)))
{
if (SpNode)
ThreadHelper.lock_grab(sp.Lock);
continue;
}
// Value based pruning
// We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
// but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction(PvNode, depth, moveCount);
futilityValue = futilityBase + futility_margin(predictedDepth, moveCount)
+ H.gain(pos.piece_moved(move), Utils.to_sq(move));
if (futilityValue < beta)
{
if (SpNode)
ThreadHelper.lock_grab(sp.Lock);
continue;
}
// Prune moves with negative SEE at low depths
if (predictedDepth < 2 * DepthC.ONE_PLY
&& pos.see(move, true) < 0)
{
if (SpNode)
ThreadHelper.lock_grab(sp.Lock);
continue;
}
}
// Check for legality only before to do the move
if (!pos.pl_move_is_legal(move, ci.pinned))
{
moveCount--;
continue;
}
ss[ssPos].currentMove = move;
if (!SpNode && !captureOrPromotion && playedMoveCount < 64)
movesSearched[playedMoveCount++] = move;
// Step 14. Make the move
示例3: search
//.........这里部分代码省略.........
ext = DepthC.ONE_PLY;
}
}
// Update current move (this must be done after singular extension search)
newDepth = depth - DepthC.ONE_PLY + ext;
// Step 13. Futility pruning (is omitted in PV nodes)
if (!PvNode
&& !captureOrPromotion
&& !inCheck
&& !dangerous
&& move != ttMove
&& (bestValue > ValueC.VALUE_MATED_IN_MAX_PLY || (bestValue == -ValueC.VALUE_INFINITE && alpha > ValueC.VALUE_MATED_IN_MAX_PLY)))
{
// Move count based pruning
if (depth < 16 * DepthC.ONE_PLY
&& moveCount >= FutilityMoveCounts[depth]
&& ((threatMove == 0) || !refutes(pos, move, threatMove)))
{
if (SpNode)
{
ThreadHelper.lock_grab(sp.Lock);
}
continue;
}
// Value based pruning
// We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
// but fixing this made program slightly weaker.
var predictedDepth = newDepth - reduction(PvNode, depth, moveCount);
futilityValue = ss[ssPos].staticEval + ss[ssPos].evalMargin + futility_margin(predictedDepth, moveCount)
+ H.gain(pos.piece_moved(move), Utils.to_sq(move));
if (futilityValue < beta)
{
if (SpNode)
{
ThreadHelper.lock_grab(sp.Lock);
}
continue;
}
// Prune moves with negative SEE at low depths
if (predictedDepth < 2 * DepthC.ONE_PLY && pos.see(move, true) < 0)
{
if (SpNode)
{
ThreadHelper.lock_grab(sp.Lock);
}
continue;
}
}
// Check for legality only before to do the move
if (!RootNode && !SpNode && !pos.pl_move_is_legal(move, ci.pinned))
{
moveCount--;
continue;
}
pvMove = (PvNode && moveCount == 1);
ss[ssPos].currentMove = move;
示例4: check_is_dangerous
// check_is_dangerous() tests if a checking move can be pruned in qsearch().
// bestValue is updated only when returning false because in that case move
// will be pruned.
static bool check_is_dangerous(Position pos, Move move, Value futilityBase, Value beta)
{
Bitboard b, occ, oldAtt, newAtt, kingAtt;
Square from, to, ksq;
Piece pc;
Color them;
from = Utils.from_sq(move);
to = Utils.to_sq(move);
them = Utils.flip_C(pos.sideToMove);
ksq = pos.king_square(them);
kingAtt = Position.attacks_from_KING(ksq);
pc = pos.piece_moved(move);
occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
oldAtt = Position.attacks_from(pc, from, occ);
newAtt = Position.attacks_from(pc, to, occ);
// Rule 1. Checks which give opponent's king at most one escape square are dangerous
b = kingAtt & ~pos.pieces_C(them) & ~newAtt & ~(1UL << to);
if ((b & (b - 1)) == 0) // Catches also !b
return true;
// Rule 2. Queen contact check is very dangerous
if (Utils.type_of(pc) == PieceTypeC.QUEEN
&& (Utils.bit_is_set(kingAtt, to) != 0))
return true;
// Rule 3. Creating new double threats with checks
b = pos.pieces_C(them) & newAtt & ~oldAtt & ~(1UL << ksq);
while (b != 0)
{
// Note that here we generate illegal "double move"!
if (futilityBase + Position.PieceValueEndgame[pos.piece_on(Utils.pop_1st_bit(ref b))] >= beta)
return true;
}
return false;
}
示例5: check_is_dangerous
// check_is_dangerous() tests if a checking move can be pruned in qsearch().
// bestValue is updated only when returning false because in that case move
// will be pruned.
private static bool check_is_dangerous(Position pos, int move, int futilityBase, int beta)
{
//ulong b, occ, oldAtt, newAtt, kingAtt;
//int from, to, ksq;
//int pc;
//int them;
//from = Utils.from_sq(move);
//to = Utils.to_sq(move);
//them = Utils.flip_C(pos.sideToMove);
//ksq = pos.king_square(them);
//kingAtt = Position.attacks_from_KING(ksq);
//pc = pos.piece_moved(move);
//occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
//oldAtt = Position.attacks_from(pc, from, occ);
//newAtt = Position.attacks_from(pc, to, occ);
//// Rule 1. Checks which give opponent's king at most one escape square are dangerous
//b = kingAtt & ~pos.pieces_C(them) & ~newAtt & ~(1UL << to);
//if ((b & (b - 1)) == 0) // Catches also !b
Piece pc = pos.piece_moved(move);
Square from = Utils.from_sq(move);
Square to = Utils.to_sq(move);
Color them = pos.sideToMove ^ 1;
Square ksq = pos.king_square(them);
Bitboard enemies = pos.pieces_C(them);
Bitboard kingAtt = Position.attacks_from_KING(ksq);
Bitboard occ = pos.occupied_squares ^ Utils.SquareBB[from] ^ Utils.SquareBB[ksq];
Bitboard oldAtt = Position.attacks_from(pc, from, occ);
Bitboard newAtt = Position.attacks_from(pc, to, occ);
// Checks which give opponent's king at most one escape square are dangerous
if (!Utils.more_than_one(kingAtt & ~(enemies | newAtt | (ulong)to)))
{
return true;
}
// Queen contact check is very dangerous
if (Utils.type_of(pc) == PieceTypeC.QUEEN && (Utils.bit_is_set(kingAtt, to) != 0))
{
return true;
}
// Creating new double threats with checks is dangerous
Bitboard b = (enemies ^ (ulong)ksq) & newAtt & ~oldAtt;
while (b != 0)
{
// Note that here we generate illegal "double move"!
if (futilityBase + Position.PieceValue[PhaseC.EG][pos.piece_on(Utils.pop_lsb(ref b))] >= beta)
{
return true;
}
}
return false;
}