int Quiesce(int alpha, int beta, int depth) { if (depth == maxQuiesceDepth) { return(StaticEval()); } var moves = GetMoves(0, 0); IEnumerable <int> selected; if (board.GetCheckCount(board.ToMove) > 0) { if (moves.Count() == 0) { return(-INFINITE);//mate } //depth -= 1; selected = moves; } else { selected = moves.Where(k => (k & MovePackHelper.Capture) != 0 || MovePackHelper.GetPromotion(k) != PromotionTo.None); } if (selected.Count() == 0) { return(StaticEval()); } foreach (var move in selected) { board.Move(move); var score = -Quiesce(-beta, -alpha, depth + 1); board.UndoMove(); if (score > alpha) { alpha = score; } if (alpha >= beta) // current player move is better than the other one better, no reason to search further { //beta cutoff !!! break; } } return(alpha); }
private int GetWeight(int m, int best, int k1, int k2) { int val = (m & MovePackHelper.GoodCapture) != 0 ? 1000 : 0; if ((m & MovePackHelper.Capture) != 0 && (m & MovePackHelper.GoodCapture) == 0) { val -= 1000; } PromotionTo to; if ((to = MovePackHelper.GetPromotion(m)) != PromotionTo.None) { switch (to) { case PromotionTo.Queen: val += 1000; break; case PromotionTo.Knight: val += 500; break; case PromotionTo.Bishop: val -= 1000; break; case PromotionTo.Rook: val -= 1000; break; } } if (m == k1 || m == k2) { val += 5000; } if (m == best) { val += 10000; } return(val); }