本文整理汇总了C#中Portfish.Position.in_check方法的典型用法代码示例。如果您正苦于以下问题:C# Position.in_check方法的具体用法?C# Position.in_check怎么用?C# Position.in_check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfish.Position
的用法示例。
在下文中一共展示了Position.in_check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: generate_capture
internal static void generate_capture(Position pos, MoveStack[] ms, ref int mpos)
{
Debug.Assert(!pos.in_check());
var us = pos.sideToMove;
var target = pos.byColorBB[us ^ 1];
generate_all(GenType.CAPTURES, pos, ms, ref mpos, us, target, null);
}
示例4: generate_non_evasion
internal static void generate_non_evasion(Position pos, MoveStack[] ms, ref int mpos)
{
Debug.Assert(!pos.in_check());
var us = pos.sideToMove;
var target = ~(pos.byColorBB[us]);
generate_all(GenType.NON_EVASIONS, pos, ms, ref mpos, us, target, null);
}
示例5: generate_quiet_check
internal static void generate_quiet_check(Position pos, MoveStack[] ms, ref int mpos)
{
/// generate<MV_NON_CAPTURE_CHECK> generates all pseudo-legal non-captures and knight
/// underpromotions that give check. Returns a pointer to the end of the move list.
Debug.Assert(!pos.in_check());
Color us = pos.sideToMove;
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
Bitboard dc = ci.dcCandidates;
while (dc != 0)
{
Square from = Utils.pop_1st_bit(ref dc);
PieceType pt = Utils.type_of(pos.piece_on(from));
if (pt == PieceTypeC.PAWN)
continue; // Will be generated together with direct checks
Bitboard b = pos.attacks_from_PTS(pt, from) & ~pos.occupied_squares;
if (pt == PieceTypeC.KING)
b &= ~Utils.PseudoAttacks[PieceTypeC.QUEEN][ci.ksq];
while (b != 0) { ms[mpos++].move = Utils.make_move(from, Utils.pop_1st_bit(ref b)); }
}
generate_pawn_moves(us, MoveType.MV_QUIET_CHECK, pos, ms, ref mpos, ci.dcCandidates, ci.ksq);
generate_direct_checks(PieceTypeC.KNIGHT, pos, ms, ref mpos, us, ci);
generate_direct_checks(PieceTypeC.BISHOP, pos, ms, ref mpos, us, ci);
generate_direct_checks(PieceTypeC.ROOK, pos, ms, ref mpos, us, ci);
generate_direct_checks(PieceTypeC.QUEEN, pos, ms, ref mpos, us, ci);
if (pos.can_castle_C(us) != 0)
{
generate_castle(CastlingSideC.KING_SIDE, true, pos, ms, ref mpos, us);
generate_castle(CastlingSideC.QUEEN_SIDE, true, pos, ms, ref mpos, us);
}
CheckInfoBroker.Free();
}
示例6: insert_pv_in_tt
// insert_pv_in_tt() is called at the end of a search iteration, and inserts
// the PV back into the TT. This makes sure the old PV moves are searched
// first, even if the old TT entries have been overwritten.
internal void insert_pv_in_tt(Position pos)
{
StateInfoArray sia = StateInfoArrayBroker.GetObject();
int stPos = 0;
TTEntry tte;
bool tteHasValue;
Key k;
Value v, m = ValueC.VALUE_NONE;
int ply = 0;
UInt32 ttePos = 0;
Debug.Assert(pv[ply] != MoveC.MOVE_NONE && pos.is_pseudo_legal(pv[ply]));
do
{
k = pos.key();
tteHasValue = TT.probe(k, ref ttePos, out tte);
// Don't overwrite existing correct entries
if ((!tteHasValue) || tte.move() != pv[ply])
{
v = (pos.in_check() ? ValueC.VALUE_NONE : Evaluate.do_evaluate(false, pos, ref m));
TT.store(k, ValueC.VALUE_NONE, Bound.BOUND_NONE, DepthC.DEPTH_NONE, pv[ply], v, m);
}
pos.do_move(pv[ply], sia.state[stPos++]);
} while (pv[++ply] != MoveC.MOVE_NONE);
do pos.undo_move(pv[--ply]); while (ply != 0);
StateInfoArrayBroker.Free();
}
示例7: MovePickerC
internal void MovePickerC(Position p, Move ttm, Depth d, History h,
Square sq)
{
pos = p;
H = h;
curMovePos = 0;
lastMovePos = 0;
Debug.Assert(d <= DepthC.DEPTH_ZERO);
depth = 0;
recaptureSquare = 0;
captureThreshold = 0;
lastQuietPos = 0; lastBadCapturePos = 0;
mpos = 0;
if (p.in_check())
phase = SequencerC.EVASION;
else if (d > DepthC.DEPTH_QS_NO_CHECKS)
phase = SequencerC.QSEARCH_0;
else if (d > DepthC.DEPTH_QS_RECAPTURES)
{
phase = SequencerC.QSEARCH_1;
// Skip TT move if is not a capture or a promotion, this avoids qsearch
// tree explosion due to a possible perpetual check or similar rare cases
// when TT table is full.
if ((ttm != 0) && !pos.is_capture_or_promotion(ttm))
ttm = MoveC.MOVE_NONE;
}
else
{
phase = SequencerC.RECAPTURE;
recaptureSquare = sq;
ttm = MoveC.MOVE_NONE;
}
ttMove = ((ttm != 0) && pos.is_pseudo_legal(ttm) ? ttm : MoveC.MOVE_NONE);
lastMovePos += ((ttMove != MoveC.MOVE_NONE) ? 1 : 0);
}
示例8: do_evaluate
/// evaluate() is the main evaluation function. It always computes two
/// values, an endgame score and a middle game score, and interpolates
/// between them based on the remaining material.
internal static int do_evaluate(bool Trace, Position pos, ref int margin)
{
Debug.Assert(!pos.in_check());
var ei = EvalInfoBroker.GetObject();
Value marginsWHITE, marginsBLACK;
int score = 0, mobilityWhite = 0, mobilityBlack = 0;
// margins[] store the uncertainty estimation of position's evaluation
// that typically is used by the search for pruning decisions.
marginsWHITE = marginsBLACK = ValueC.VALUE_ZERO;
// Initialize score by reading the incrementally updated scores included
// in the position object (material + piece square tables) and adding
// Tempo bonus. Score is computed from the point of view of white.
score = pos.st.psqScore + (pos.sideToMove == ColorC.WHITE ? Tempo : -Tempo);
// Probe the material hash table
pos.this_thread().materialTable.probe(pos, out ei.mi);
score += ((ei.mi.value << 16) + ei.mi.value);
// If we have a specialized evaluation function for the current material
// configuration, call it and return.
if (ei.mi.evaluationFunction != null)
{
margin = ValueC.VALUE_ZERO;
var retval = ei.mi.evaluationFunction(ei.mi.evaluationFunctionColor, pos);
ei.pi = null;
ei.mi = null;
EvalInfoBroker.Free();
return retval;
}
// Probe the pawn hash table
pos.this_thread().pawnTable.probe(pos, out ei.pi);
score += ei.pi.value;
// Initialize attack and king safety bitboards
init_eval_info(ColorC.WHITE, pos, ei);
init_eval_info(ColorC.BLACK, pos, ei);
// Evaluate pieces and mobility
score += evaluate_pieces_of_color(ColorC.WHITE, Trace, pos, ei, ref mobilityWhite)
- evaluate_pieces_of_color(ColorC.BLACK, Trace, pos, ei, ref mobilityBlack);
score += (((((((mobilityWhite - mobilityBlack) + 32768) & ~0xffff) / 0x10000
* (((Weights[EvalWeightC.Mobility] + 32768) & ~0xffff) / 0x10000)) / 0x100) << 16)
+ (((short)((mobilityWhite - mobilityBlack) & 0xffff)
* ((short)(Weights[EvalWeightC.Mobility] & 0xffff))) / 0x100));
// Evaluate kings after all other pieces because we need complete attack
// information when computing the king safety evaluation.
score += evaluate_king(ColorC.WHITE, Trace, pos, ei, ref marginsWHITE, ref marginsBLACK)
- evaluate_king(ColorC.BLACK, Trace, pos, ei, ref marginsWHITE, ref marginsBLACK);
// Evaluate tactical threats, we need full attack information including king
score += evaluate_threats(ColorC.WHITE, pos, ei) - evaluate_threats(ColorC.BLACK, pos, ei);
// Evaluate passed pawns, we need full attack information including king
score += evaluate_passed_pawns(ColorC.WHITE, pos, ei) - evaluate_passed_pawns(ColorC.BLACK, pos, ei);
// If one side has only a king, check whether exists any unstoppable passed pawn
if ((pos.st.npMaterialWHITE == 0) || (pos.st.npMaterialBLACK == 0))
{
score += evaluate_unstoppable_pawns(pos, ei);
}
// Evaluate space for both sides, only in middle-game.
if (ei.mi.spaceWeight != 0)
{
var s = evaluate_space(ColorC.WHITE, pos, ei) - evaluate_space(ColorC.BLACK, pos, ei);
score += ((((((((s * ei.mi.spaceWeight) << 16) + 32768) & ~0xffff) / 0x10000
* (((Weights[EvalWeightC.Space] + 32768) & ~0xffff) / 0x10000)) / 0x100) << 16)
+ (((short)(((s * ei.mi.spaceWeight) << 16) & 0xffff)
* ((short)(Weights[EvalWeightC.Space] & 0xffff))) / 0x100));
}
// Scale winning side if position is more drawish that what it appears
var sf = ((short)(score & 0xffff)) > ValueC.VALUE_DRAW
? ei.mi.scale_factor_WHITE(pos)
: ei.mi.scale_factor_BLACK(pos);
// If we don't already have an unusual scale factor, check for opposite
// colored bishop endgames, and use a lower scale for those.
if (ei.mi.gamePhase < PhaseC.PHASE_MIDGAME
&& (pos.pieceCount[ColorC.WHITE][PieceTypeC.BISHOP] == 1
&& pos.pieceCount[ColorC.BLACK][PieceTypeC.BISHOP] == 1
&& (((((pos.pieceList[ColorC.WHITE][PieceTypeC.BISHOP][0]
^ pos.pieceList[ColorC.BLACK][PieceTypeC.BISHOP][0]) >> 3)
^ (pos.pieceList[ColorC.WHITE][PieceTypeC.BISHOP][0]
^ pos.pieceList[ColorC.BLACK][PieceTypeC.BISHOP][0])) & 1) != 0))
&& sf == ScaleFactorC.SCALE_FACTOR_NORMAL)
{
// Only the two bishops ?
if (pos.st.npMaterialWHITE == Constants.BishopValueMidgame
&& pos.st.npMaterialBLACK == Constants.BishopValueMidgame)
//.........这里部分代码省略.........
示例9: search
// search<>() is the main search function for both PV and non-PV nodes and for
// normal and SplitPoint nodes. When called just after a split point the search
// is simpler because we have already probed the hash table, done a null move
// search, and searched the first move before splitting, we don't have to repeat
// all this work again. We also don't need to store anything to the hash table
// here: This is taken care of after we return from the split point.
internal static int search(int NT, Position pos, Stack[] ss, int ssPos, int alpha, int beta, int depth)
{
var PvNode = (NT == NodeTypeC.PV || NT == NodeTypeC.Root || NT == NodeTypeC.SplitPointPV
|| NT == NodeTypeC.SplitPointRoot);
var SpNode = (NT == NodeTypeC.SplitPointPV || NT == NodeTypeC.SplitPointNonPV
|| NT == NodeTypeC.SplitPointRoot);
var RootNode = (NT == NodeTypeC.Root || NT == NodeTypeC.SplitPointRoot);
Debug.Assert(alpha >= -ValueC.VALUE_INFINITE && alpha < beta && beta <= ValueC.VALUE_INFINITE);
Debug.Assert((PvNode || alpha == beta - 1));
Debug.Assert(depth > DepthC.DEPTH_ZERO);
var ms = MovesSearchedBroker.GetObject();
var movesSearched = ms.movesSearched;
StateInfo st = null;
var tte = TT.StaticEntry;
var tteHasValue = false;
uint ttePos = 0;
ulong posKey = 0;
int ttMove, move, excludedMove, bestMove, threatMove;
int ext, newDepth;
int bestValue, value, ttValue;
int eval = 0, nullValue, futilityValue;
bool inCheck, givesCheck, pvMove, singularExtensionNode;
bool captureOrPromotion, dangerous, doFullDepthSearch;
int moveCount = 0, playedMoveCount = 0;
SplitPoint sp = null;
// Step 1. Initialize node
var thisThread = pos.this_thread();
//var threatExtension = false;
inCheck = pos.in_check();
if (SpNode)
{
sp = ss[ssPos].sp;
bestMove = sp.bestMove;
threatMove = sp.threatMove;
bestValue = sp.bestValue;
ttMove = excludedMove = MoveC.MOVE_NONE;
ttValue = ValueC.VALUE_NONE;
Debug.Assert(sp.bestValue > -ValueC.VALUE_INFINITE && sp.moveCount > 0);
goto split_point_start;
}
bestValue = -ValueC.VALUE_INFINITE;
ss[ssPos].currentMove = threatMove = ss[ssPos + 1].excludedMove = bestMove = MoveC.MOVE_NONE;
ss[ssPos].ply = ss[ssPos - 1].ply + 1;
ss[ssPos + 1].skipNullMove = 0;
ss[ssPos + 1].reduction = DepthC.DEPTH_ZERO;
ss[ssPos + 2].killers0 = ss[ssPos + 2].killers1 = MoveC.MOVE_NONE;
// Used to send selDepth info to GUI
if (PvNode && thisThread.maxPly < ss[ssPos].ply)
{
thisThread.maxPly = ss[ssPos].ply;
}
if (!RootNode)
{
// Step 2. Check for aborted search and immediate draw
if ((SignalsStop || pos.is_draw(false) || ss[ssPos].ply > Constants.MAX_PLY))
{
MovesSearchedBroker.Free();
return DrawValue[pos.sideToMove];
}
// Step 3. Mate distance pruning. Even if we mate at the next move our score
// would be at best mate_in(ss->ply+1), but if alpha is already bigger because
// a shorter mate was found upward in the tree then there is no need to search
// further, we will never beat current alpha. Same logic but with reversed signs
// applies also in the opposite condition of being mated instead of giving mate,
// in this case return a fail-high score.
alpha = Math.Max(Utils.mated_in(ss[ssPos].ply), alpha);
beta = Math.Min(Utils.mate_in(ss[ssPos].ply + 1), beta);
if (alpha >= beta)
{
MovesSearchedBroker.Free();
return alpha;
}
}
// Step 4. Transposition table lookup
// We don't want the score of a partial search to overwrite a previous full search
// TT value, so we use a different position key in case of an excluded move.
excludedMove = ss[ssPos].excludedMove;
posKey = (excludedMove != 0) ? pos.exclusion_key() : pos.key();
tteHasValue = TT.probe(posKey, ref ttePos, out tte);
ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tteHasValue ? tte.move() : MoveC.MOVE_NONE;
ttValue = tteHasValue ? value_from_tt(tte.value(), ss[ssPos].ply) : ValueC.VALUE_NONE;
//.........这里部分代码省略.........
示例10: 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).
private static int qsearch(int NT, bool InCheck, Position pos, Stack[] ss, int ssPos, int alpha, int beta, int depth)
{
var PvNode = (NT == NodeTypeC.PV);
Debug.Assert(NT == NodeTypeC.PV || NT == NodeTypeC.NonPV);
Debug.Assert(InCheck == pos.in_check());
Debug.Assert(alpha >= -ValueC.VALUE_INFINITE && alpha < beta && beta <= ValueC.VALUE_INFINITE);
Debug.Assert(PvNode || (alpha == beta - 1));
Debug.Assert(depth <= DepthC.DEPTH_ZERO);
StateInfo st = null;
int ttMove, move, bestMove;
int ttValue, bestValue, value, futilityValue, futilityBase, oldAlpha = 0;
bool givesCheck, enoughMaterial, evasionPrunable, fromNull;
var tteHasValue = false;
TTEntry tte;
uint ttePos = 0;
int ttDepth;
Key posKey;
// To flag BOUND_EXACT a node with eval above alpha and no available moves
if (PvNode)
{
oldAlpha = alpha;
}
ss[ssPos].currentMove = bestMove = MoveC.MOVE_NONE;
ss[ssPos].ply = ss[ssPos - 1].ply + 1;
fromNull = ss[ssPos - 1].currentMove == MoveC.MOVE_NULL;
// Check for an instant draw or maximum ply reached
if (pos.is_draw(true) || ss[ssPos].ply > Constants.MAX_PLY)
{
return DrawValue[pos.sideToMove];
}
// Transposition table lookup. At PV nodes, we don't use the TT for
// pruning, but only for move ordering.
posKey = pos.key();
tteHasValue = TT.probe(posKey, ref ttePos, out tte);
ttMove = (tteHasValue ? tte.move() : MoveC.MOVE_NONE);
ttValue = tteHasValue ? value_from_tt(tte.value(), ss[ssPos].ply) : ValueC.VALUE_NONE;
// 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.
ttDepth = (InCheck || depth >= DepthC.DEPTH_QS_CHECKS ? DepthC.DEPTH_QS_CHECKS : DepthC.DEPTH_QS_NO_CHECKS);
if (tteHasValue
&& tte.depth() >= depth
&& ttValue != ValueC.VALUE_NONE // Only in case of TT access race
&& (PvNode ? tte.type() == Bound.BOUND_EXACT
: ttValue >= beta ? ((tte.type() & Bound.BOUND_LOWER) != 0)
: ((tte.type() & Bound.BOUND_UPPER) != 0)))
{
ss[ssPos].currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
}
// Evaluate the position statically
if (InCheck)
{
ss[ssPos].staticEval = ss[ssPos].evalMargin = ValueC.VALUE_NONE;
bestValue = futilityBase = -ValueC.VALUE_INFINITE;
enoughMaterial = false;
}
else
{
if (fromNull)
{
// Approximated score. Real one is slightly higher due to tempo
ss[ssPos].staticEval = bestValue = -ss[ssPos - 1].staticEval;
ss[ssPos].evalMargin = ValueC.VALUE_ZERO;
}
else if (tteHasValue)
{
// Never assume anything on values stored in TT
if ((ss[ssPos].staticEval = bestValue = tte.eval_value()) == ValueC.VALUE_NONE
|| (ss[ssPos].evalMargin = tte.eval_margin()) == ValueC.VALUE_NONE)
{
ss[ssPos].staticEval = bestValue = Evaluate.do_evaluate(false, pos, ref ss[ssPos].evalMargin);
}
}
else
{
ss[ssPos].staticEval = bestValue = Evaluate.do_evaluate(false, pos, ref ss[ssPos].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),
//.........这里部分代码省略.........
示例11: insert_pv_in_tt
// insert_pv_in_tt() is called at the end of a search iteration, and inserts
// the PV back into the TT. This makes sure the old PV moves are searched
// first, even if the old TT entries have been overwritten.
internal void insert_pv_in_tt(Position pos)
{
var sia = StateInfoArrayBroker.GetObject();
var stPos = 0;
TTEntry tte;
bool tteHasValue;
int v, m = 0;
var ply = 0;
uint ttePos = 0;
do
{
tteHasValue = TT.probe(pos.key(), ref ttePos, out tte);
if ((!tteHasValue) || tte.move() != this.pv[ply]) // Don't overwrite existing correct entries
{
if (pos.in_check())
{
v = m = ValueC.VALUE_NONE;
}
else
{
v = Evaluate.do_evaluate(false, pos, ref m);
}
TT.store(pos.key(), ValueC.VALUE_NONE, Bound.BOUND_NONE, DepthC.DEPTH_NONE, this.pv[ply], v, m);
}
Debug.Assert(pos.move_is_legal(pv[ply]));
pos.do_move(this.pv[ply++], sia.state[stPos++]);
}
while (this.pv[ply] != MoveC.MOVE_NONE);
while (ply != 0)
{
pos.undo_move(this.pv[--ply]);
}
StateInfoArrayBroker.Free();
}
示例12: generate_capture
internal static void generate_capture(Position pos, MoveStack[] ms, ref int mpos)
{
Debug.Assert(!pos.in_check());
Color us = pos.sideToMove;
Bitboard target = pos.byColorBB[us ^ 1];
generate_pawn_moves(us, MoveType.MV_CAPTURE, pos, ms, ref mpos, target, SquareC.SQ_NONE);
generate_moves(pos, ms, ref mpos, us, target);
generate_king_moves(pos, ms, ref mpos, us, target);
}
示例13: generate_non_evasion
internal static void generate_non_evasion(Position pos, MoveStack[] ms, ref int mpos)
{
Debug.Assert(!pos.in_check());
Color us = pos.sideToMove;
Bitboard target = ~(pos.byColorBB[us]);
generate_pawn_moves(us, MoveType.MV_NON_EVASION, pos, ms, ref mpos, target, SquareC.SQ_NONE);
generate_moves(pos, ms, ref mpos, us, target);
generate_king_moves(pos, ms, ref mpos, us, target);
if ((pos.st.castleRights & (CastleRightC.WHITE_ANY << (us << 1))) != 0)
{
generate_castle(CastlingSideC.KING_SIDE, false, pos, ms, ref mpos, us);
generate_castle(CastlingSideC.QUEEN_SIDE, false, pos, ms, ref mpos, us);
}
}
示例14: Endgame_KXK
/// Mate with KX vs K. This function is used to evaluate positions with
/// King and plenty of material vs a lone king. It simply gives the
/// attacking side a bonus for driving the defending king towards the edge
/// of the board, and for keeping the distance between the two kings small.
/// KXK
internal static Value Endgame_KXK(Color strongerSide, Position pos)
{
Color weakerSide = strongerSide ^ 1;
Debug.Assert(pos.non_pawn_material(weakerSide) == ValueC.VALUE_ZERO);
Debug.Assert(pos.piece_count(weakerSide, PieceTypeC.PAWN) == ValueC.VALUE_ZERO);
// Stalemate detection with lone king
MList mlist = MListBroker.GetObject(); mlist.pos = 0;
Movegen.generate_legal(pos, mlist.moves, ref mlist.pos);
bool any = mlist.pos > 0;
MListBroker.Free();
if (pos.sideToMove == weakerSide
&& !pos.in_check()
&& !any)
{
return ValueC.VALUE_DRAW;
}
Square winnerKSq = pos.king_square(strongerSide);
Square loserKSq = pos.king_square(weakerSide);
Value result = pos.non_pawn_material(strongerSide)
+ pos.piece_count(strongerSide, PieceTypeC.PAWN) * Constants.PawnValueEndgame
+ MateTable[loserKSq]
+ DistanceBonus[Utils.square_distance(winnerKSq, loserKSq)];
if (pos.piece_count(strongerSide, PieceTypeC.QUEEN)!=0
|| pos.piece_count(strongerSide, PieceTypeC.ROOK)!=0
|| pos.bishop_pair(strongerSide))
{
result += ValueC.VALUE_KNOWN_WIN;
}
return strongerSide == pos.sideToMove ? result : -result;
}
示例15: generate_legal
internal static void generate_legal(Position pos, MoveStack[] ms, ref int mpos)
{
/// generate<LEGAL> generates all the legal moves in the given position
var pinned = pos.pinned_pieces();
Square ksq = pos.king_square(pos.sideToMove);
if (pos.in_check())
{
generate_evasion(pos, ms, ref mpos);
}
else
{
generate_non_evasion(pos, ms, ref mpos);
}
var last = mpos;
var cur = 0;
while (cur != last)
{
var curMove = ms[cur].move;
//if (!pos.pl_move_is_legal(ms[cur].move, pinned))
if ((pinned != 0 || Utils.from_sq(curMove) == ksq || Utils.type_of_move(curMove) == MoveTypeC.ENPASSANT) && !pos.pl_move_is_legal(curMove, pinned))
{
ms[cur].move = ms[--last].move;
}
else
{
cur++;
}
}
mpos = last;
}