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); }
public static string ProduceShortAlgebraicString(IChessBoard board, int p) { board.TestInCheck(board.ToMove); int [] moves = new int[200]; board.GetMoves(0, moves); List <int> possibles = new List <int>(); int end = MovePackHelper.GetEndSquare(p); foreach (var m in moves) { if (GetEndSquare(m) == end && board.BoardArray[GetStartSquare(m)].Type == board.BoardArray[GetStartSquare(p)].Type) { possibles.Add(p); } } StringBuilder sb = new StringBuilder(); var spiece = board.BoardArray[GetStartSquare(p)]; if (spiece.Type != PieceType.Pawn) { sb.Append(spiece.ToString().ToUpper()); } if (possibles.Count > 1) { var squares = possibles.Select(k => GetSquareString(GetStartSquare(k))); if (squares.Select(k => k[0]).Distinct().Count() > 1) { sb.Append(GetSquareString(GetStartSquare(p))[0]); } else if (squares.Select(k => k[1]).Distinct().Count() > 1) { sb.Append(GetSquareString(GetStartSquare(p))[1]); } else { sb.Append(GetSquareString(GetStartSquare(p))); } } if (HasCapture(p)) { sb.Append("x"); } sb.Append(GetSquareString(GetEndSquare(p))); board.Move(p); board.TestInCheck(board.ToMove); int cnt = board.GetCheckCount(board.ToMove); if (cnt > 0) { int[] tmp = new int[200]; if (0 == board.GetMoves(0, tmp)) { sb.Append("#"); } else { sb.Append(new string('+', cnt)); } } board.UndoMove(); return(sb.ToString()); }