本文整理汇总了C#中Portfish.Position.move_gives_check方法的典型用法代码示例。如果您正苦于以下问题:C# Position.move_gives_check方法的具体用法?C# Position.move_gives_check怎么用?C# Position.move_gives_check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfish.Position
的用法示例。
在下文中一共展示了Position.move_gives_check方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generate_castle
private static void generate_castle(CastlingSide Side, bool OnlyChecks, Position pos, MoveStack[] ms, ref int mpos, Color us)
{
if (pos.castle_impeded(us, Side) || (pos.can_castle_CR(Utils.make_castle_right(us, Side))==0) )
return;
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
Square kfrom = pos.king_square(us);
Square rfrom = pos.castle_rook_square(us, Side);
Square kto = Utils.relative_square(us, Side == CastlingSideC.KING_SIDE ? SquareC.SQ_G1 : SquareC.SQ_C1);
Bitboard enemies = pos.pieces_C(us ^ 1);
Debug.Assert(!pos.in_check());
for (Square s = Math.Min(kfrom, kto), e = Math.Max(kfrom, kto); s <= e; s++)
if (s != kfrom // We are not in check
&& ((pos.attackers_to(s) & enemies) != 0))
return;
// 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 (pos.chess960
&& ((pos.attackers_to(kto, Utils.xor_bit(pos.occupied_squares, rfrom)) & enemies) != 0))
return;
Move m = Utils.make_castle(kfrom, rfrom);
if (OnlyChecks)
{
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
bool givesCheck = pos.move_gives_check(m, ci);
CheckInfoBroker.Free();
if (!givesCheck) return;
}
ms[mpos++].move = m;
}
示例2: move_to_san
/// move_to_san() takes a position and a legal Move as input and returns its
/// short algebraic notation representation.
internal static string move_to_san(Position pos, int m)
{
if (m == MoveC.MOVE_NONE)
{
return "(none)";
}
if (m == MoveC.MOVE_NULL)
{
return "(null)";
}
Debug.Assert(pos.move_is_legal(m));
Bitboard others, b;
Color us = pos.sideToMove;
var san = new StringBuilder();
Square from = from_sq(m);
Square to = to_sq(m);
Piece pc = pos.piece_on(from);
PieceType pt = type_of(pc);
if (type_of_move(m) == MoveTypeC.CASTLING)
{
san.Append(to > from ? "O-O" : "O-O-O");
}
else
{
if (pt != PieceTypeC.PAWN)
{
san.Append(PieceToChar[ColorC.WHITE][pt]); // Upper case
// Disambiguation if we have more then one piece of type 'pt' that can
// reach 'to' with a legal move.
others = b = (pos.attacks_from_PS(pc, to) & pos.pieces_PTC(pt, us)) ^ (ulong)from;
while (others != 0)
{
Move move = make_move(pop_lsb(ref b), to);
if (!pos.pl_move_is_legal(move, pos.pinned_pieces()))
{
others ^= (ulong)from_sq(move);
}
}
if (others != 0)
{
if ((others & file_bb_S(from)) == 0)
{
san.Append(file_to_char(file_of(from)));
}
else if ((others & rank_bb_S(from)) == 0)
{
san.Append(rank_to_char(rank_of(from)));
}
else
{
san.Append(square_to_string(from));
}
}
}
else if (pos.is_capture(m))
{
san.Append(file_to_char(file_of(from)));
}
if (pos.is_capture(m))
{
san.Append('x');
}
san.Append(square_to_string(to));
if (type_of_move(m) == MoveTypeC.PROMOTION)
{
san.Append('=');
san.Append(PieceToChar[ColorC.WHITE][promotion_type(m)]);
}
}
var ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
if (pos.move_gives_check(m, ci))
{
var st = new StateInfo();
pos.do_move(m, st);
var 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();
}
示例3: 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();
}
示例4: search
//.........这里部分代码省略.........
return beta - 1;
}
}
}
// Step 9. ProbCut (is omitted in PV nodes)
// If we have a very good capture (i.e. SEE > seeValues[captured_piece_type])
// and a reduced search returns a value much above beta, we can (almost) safely
// prune the previous move.
if (!PvNode && !inCheck
&& excludedMove == MoveC.MOVE_NONE
&& depth >= RazorDepth + DepthC.ONE_PLY
&& (ss[ssPos].skipNullMove == 0)
&& Math.Abs(beta) < ValueC.VALUE_MATE_IN_MAX_PLY)
{
Value rbeta = beta + 200;
Depth rdepth = depth - DepthC.ONE_PLY - 3 * DepthC.ONE_PLY;
Debug.Assert(rdepth >= DepthC.ONE_PLY);
Debug.Assert(ss[ssPos - 1].currentMove != MoveC.MOVE_NONE);
Debug.Assert(ss[ssPos - 1].currentMove != MoveC.MOVE_NULL);
MovePicker mp2 = MovePickerBroker.GetObject();
mp2.MovePickerC(pos, ttMove, H, pos.captured_piece_type());
CheckInfo ci2 = CheckInfoBroker.GetObject();
ci2.CreateCheckInfo(pos);
while ((move = mp2.next_move()) != MoveC.MOVE_NONE)
{
if (pos.pl_move_is_legal(move, ci2.pinned))
{
ss[ssPos].currentMove = move;
if (st == null) { st = StateInfoBroker.GetObject(); }
pos.do_move(move, st, ci2, pos.move_gives_check(move, ci2));
value = -search(NodeTypeC.NonPV, pos, ss, ssPos + 1, -rbeta, -rbeta + 1, rdepth);
pos.undo_move(move);
if (value >= rbeta)
{
if (st != null) { st.previous = null; StateInfoBroker.Free(); }
CheckInfoBroker.Free();
MovePickerBroker.Free(mp2);
MovesSearchedBroker.Free();
return value;
}
}
}
CheckInfoBroker.Free();
MovePickerBroker.Free(mp2);
}
// Step 10. Internal iterative deepening
if (ttMove == MoveC.MOVE_NONE
&& depth >= IIDDepth[PvNode ? 1 : 0]
&& (PvNode || (!inCheck && ss[ssPos].eval + IIDMargin >= beta)))
{
Depth d = (PvNode ? depth - 2 * DepthC.ONE_PLY : depth / 2);
ss[ssPos].skipNullMove = 1;
search(PvNode ? NodeTypeC.PV : NodeTypeC.NonPV, pos, ss, ssPos, alpha, beta, d);
ss[ssPos].skipNullMove = 0;
tteHasValue = TT.probe(posKey, ref ttePos, out tte);
ttMove = (tteHasValue) ? tte.move() : MoveC.MOVE_NONE;
}
else
示例5: perft
/// Search::perft() is our utility to verify move generation. All the leaf nodes
/// up to the given depth are generated and counted and the sum returned.
internal static Int64 perft(Position pos, Depth depth)
{
StateInfo st = new StateInfo();
Int64 cnt = 0;
MList mlist = MListBroker.GetObject(); mlist.pos = 0;
Movegen.generate_legal(pos, mlist.moves, ref mlist.pos);
// At the last ply just return the number of moves (leaf nodes)
if (depth == DepthC.ONE_PLY)
{
int retval = mlist.pos;
MListBroker.Free();
return retval;
}
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
for (int i = 0; i < mlist.pos; ++i)
{
MoveStack ms = mlist.moves[i];
pos.do_move(ms.move, st, ci, pos.move_gives_check(ms.move, ci));
cnt += perft(pos, depth - DepthC.ONE_PLY);
pos.undo_move(ms.move);
}
CheckInfoBroker.Free();
MListBroker.Free();
return cnt;
}
示例6: qsearch
// qsearch() is the quiescence search function, which is called by the main
// search function when the remaining depth is zero (or, to be more precise,
// less than ONE_PLY).
static Value qsearch(NodeType NT, Position pos, Stack[] ss, int ssPos, Value alpha, Value beta, Depth depth)
{
bool PvNode = (NT == NodeTypeC.PV);
Debug.Assert(NT == NodeTypeC.PV || NT == NodeTypeC.NonPV);
Debug.Assert(alpha >= -ValueC.VALUE_INFINITE && alpha < beta && beta <= ValueC.VALUE_INFINITE);
Debug.Assert((alpha == beta - 1) || PvNode);
Debug.Assert(depth <= DepthC.DEPTH_ZERO);
StateInfo st = null;
Move ttMove, move, bestMove;
Value ttValue, bestValue, value, evalMargin = 0, futilityValue, futilityBase;
bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
bool tteHasValue = false;
TTEntry tte;
UInt32 ttePos = 0;
Depth ttDepth;
Bound bt;
Value oldAlpha = alpha;
ss[ssPos].currentMove = bestMove = MoveC.MOVE_NONE;
ss[ssPos].ply = ss[ssPos - 1].ply + 1;
// Check for an instant draw or maximum ply reached
if (pos.is_draw(true) || ss[ssPos].ply > Constants.MAX_PLY)
return ValueC.VALUE_DRAW;
// Decide whether or not to include checks, this fixes also the type of
// TT entry depth that we are going to use. Note that in qsearch we use
// only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
inCheck = pos.st.checkersBB != 0;
ttDepth = (inCheck || depth >= DepthC.DEPTH_QS_CHECKS ? DepthC.DEPTH_QS_CHECKS : DepthC.DEPTH_QS_NO_CHECKS);
// Transposition table lookup. At PV nodes, we don't use the TT for
// pruning, but only for move ordering.
tteHasValue = TT.probe(pos.key(), ref ttePos, out tte);
ttMove = (tteHasValue ? tte.move() : MoveC.MOVE_NONE);
ttValue = tteHasValue ? value_from_tt(tte.value(), ss[ssPos].ply) : ValueC.VALUE_ZERO;
if (!PvNode && tteHasValue && can_return_tt(tte, ttDepth, ttValue, beta))
{
ss[ssPos].currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
}
// Evaluate the position statically
if (inCheck)
{
bestValue = futilityBase = -ValueC.VALUE_INFINITE;
ss[ssPos].eval = evalMargin = ValueC.VALUE_NONE;
enoughMaterial = false;
}
else
{
if (tteHasValue)
{
Debug.Assert(tte.static_value() != ValueC.VALUE_NONE);
evalMargin = tte.static_value_margin();
ss[ssPos].eval = bestValue = tte.static_value();
}
else
ss[ssPos].eval = bestValue = Evaluate.do_evaluate(false, pos, ref evalMargin);
// Stand pat. Return immediately if static value is at least beta
if (bestValue >= beta)
{
if (!tteHasValue)
TT.store(pos.key(), value_to_tt(bestValue, ss[ssPos].ply), Bound.BOUND_LOWER, DepthC.DEPTH_NONE, MoveC.MOVE_NONE, ss[ssPos].eval, evalMargin);
return bestValue;
}
if (PvNode && bestValue > alpha)
alpha = bestValue;
futilityBase = ss[ssPos].eval + evalMargin + FutilityMarginQS;
enoughMaterial = (pos.sideToMove == 0 ? pos.st.npMaterialWHITE : pos.st.npMaterialBLACK) > Constants.RookValueMidgame;
}
// 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.
MovePicker mp = MovePickerBroker.GetObject();
mp.MovePickerC(pos, ttMove, depth, H, (ss[ssPos - 1].currentMove) & 0x3F);
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs
while (bestValue < beta
&& (move = mp.next_move()) != MoveC.MOVE_NONE)
{
Debug.Assert(Utils.is_ok_M(move));
givesCheck = pos.move_gives_check(move, ci);
//.........这里部分代码省略.........
示例7: generate_castle
private static void generate_castle(
int Side,
bool Checks,
Position pos,
MoveStack[] ms,
ref int mpos,
int us)
{
if (pos.castle_impeded(us, Side) || (pos.can_castle_CR(Utils.make_castle_right(us, Side)) == 0))
{
return;
}
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
var kfrom = pos.king_square(us);
var rfrom = pos.castle_rook_square(us, Side);
var kto = Utils.relative_square(us, Side == CastlingSideC.KING_SIDE ? SquareC.SQ_G1 : SquareC.SQ_C1);
var enemies = pos.pieces_C(us ^ 1);
Debug.Assert(!pos.in_check());
int K = pos.chess960 ? kto > kfrom ? -1 : 1 : Side == CastlingSideC.KING_SIDE ? -1 : 1;
for (Square s = kto; s != kfrom; s += (Square)K)
{
if ((pos.attackers_to(s) & enemies) != 0)
{
return;
}
}
// 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 (pos.chess960 && ((pos.attackers_to(kto, Utils.xor_bit(pos.occupied_squares, rfrom)) & enemies) != 0))
{
return;
}
var m = Utils.make(kfrom, rfrom, MoveTypeC.CASTLING);
if (Checks)
{
var ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
var givesCheck = pos.move_gives_check(m, ci);
CheckInfoBroker.Free();
if (!givesCheck)
{
return;
}
}
ms[mpos++].move = m;
}
示例8: search
//.........这里部分代码省略.........
return beta - 1;
}
}
}
// Step 9. ProbCut (is omitted in PV nodes)
// If we have a very good capture (i.e. SEE > seeValues[captured_piece_type])
// and a reduced search returns a value much above beta, we can (almost) safely
// prune the previous move.
if (!PvNode && !inCheck && excludedMove == MoveC.MOVE_NONE && depth >= 4 * DepthC.ONE_PLY + DepthC.ONE_PLY
&& (ss[ssPos].skipNullMove == 0) && Math.Abs(beta) < ValueC.VALUE_MATE_IN_MAX_PLY)
{
var rbeta = beta + 200;
var rdepth = depth - DepthC.ONE_PLY - 3 * DepthC.ONE_PLY;
Debug.Assert(rdepth >= DepthC.ONE_PLY);
Debug.Assert(ss[ssPos - 1].currentMove != MoveC.MOVE_NONE);
Debug.Assert(ss[ssPos - 1].currentMove != MoveC.MOVE_NULL);
var mp2 = MovePickerBroker.GetObject();
mp2.MovePickerC(pos, ttMove, H, pos.captured_piece_type());
var ci2 = CheckInfoBroker.GetObject();
ci2.CreateCheckInfo(pos);
while ((move = mp2.next_move()) != MoveC.MOVE_NONE)
{
if (pos.pl_move_is_legal(move, ci2.pinned))
{
ss[ssPos].currentMove = move;
if (st == null)
{
st = StateInfoBroker.GetObject();
}
pos.do_move(move, st, ci2, pos.move_gives_check(move, ci2));
value = -search(NodeTypeC.NonPV, pos, ss, ssPos + 1, -rbeta, -rbeta + 1, rdepth);
pos.undo_move(move);
if (value >= rbeta)
{
if (st != null)
{
st.previous = null;
StateInfoBroker.Free();
}
CheckInfoBroker.Free();
MovePickerBroker.Free(mp2);
MovesSearchedBroker.Free();
return value;
}
}
}
CheckInfoBroker.Free();
MovePickerBroker.Free(mp2);
}
// Step 10. Internal iterative deepening
if (ttMove == MoveC.MOVE_NONE && depth >= (PvNode ? 5 * DepthC.ONE_PLY : 8 * DepthC.ONE_PLY)
&& (PvNode || (!inCheck && ss[ssPos].staticEval + 256 >= beta)))
{
var d = (PvNode ? depth - 2 * DepthC.ONE_PLY : depth / 2);
ss[ssPos].skipNullMove = 1;
search(PvNode ? NodeTypeC.PV : NodeTypeC.NonPV, pos, ss, ssPos, alpha, beta, d);
ss[ssPos].skipNullMove = 0;
tteHasValue = TT.probe(posKey, ref ttePos, out tte);
示例9: qsearch
//.........这里部分代码省略.........
DepthC.DEPTH_NONE,
MoveC.MOVE_NONE,
ss[ssPos].staticEval,
ss[ssPos].evalMargin);
}
return bestValue;
}
if (PvNode && bestValue > alpha)
{
alpha = bestValue;
}
futilityBase = ss[ssPos].staticEval + ss[ssPos].evalMargin + 128;
enoughMaterial = (pos.sideToMove == 0 ? pos.st.npMaterialWHITE : pos.st.npMaterialBLACK)
> Constants.RookValueMidgame;
}
// 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 = MovePickerBroker.GetObject();
mp.MovePickerC(pos, ttMove, depth, H, (ss[ssPos - 1].currentMove) & 0x3F);
var ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs
while ((move = mp.next_move()) != MoveC.MOVE_NONE)
{
Debug.Assert(Utils.is_ok_M(move));
givesCheck = pos.move_gives_check(move, ci);
// Futility pruning
if (!PvNode
&& !InCheck
&& !givesCheck
&& !fromNull
&& move != ttMove
&& enoughMaterial
&& Utils.type_of_move(move) != MoveTypeC.PROMOTION && !pos.is_passed_pawn_push(move))
{
futilityValue = futilityBase + Position.PieceValue[PhaseC.EG][pos.board[move & 0x3F]]
+ (Utils.type_of_move(move) == MoveTypeC.ENPASSANT
? Constants.PawnValueEndgame
: ValueC.VALUE_ZERO);
if (futilityValue < beta)
{
bestValue = Math.Max(bestValue, futilityValue);
continue;
}
// Prune moves with negative or equal SEE
if (futilityBase < beta
&& depth < DepthC.DEPTH_ZERO
&& pos.see(move, false) <= 0)
{
bestValue = Math.Max(bestValue, futilityBase);
continue;
}
}
// Detect non-capture evasions that are candidate to be pruned