< Summary

Information
Class: Rudim.Search.Quiescence
Assembly: Rudim
File(s): /home/runner/work/rudim/rudim/Rudim/Search/Quiescence.cs
Line coverage
96%
Covered lines: 30
Uncovered lines: 1
Coverable lines: 31
Total lines: 63
Line coverage: 96.7%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Nodes()100%11100%
Search(...)95%202096.42%
ResetNodes()100%11100%

File(s)

/home/runner/work/rudim/rudim/Rudim/Search/Quiescence.cs

#LineLine coverage
 1using Rudim.Board;
 2using Rudim.Common;
 3using System.Collections.Generic;
 4using System.Threading;
 5
 6namespace Rudim.Search
 7{
 8    static class Quiescence
 9    {
 859743810        public static int Nodes { get; private set; } = 0;
 11        public static int Search(BoardState boardState, int alpha, int beta, CancellationToken cancellationToken)
 12        {
 429867213            Nodes++;
 14
 429867215            if (boardState.IsDraw())
 016                return 0;
 17
 429867218            int eval = PieceSquareTableEvaluation.Evaluate(boardState);
 19
 429867220            if (eval >= beta)
 292138321                return beta;
 137728922            if (eval > alpha)
 241323                alpha = eval;
 24
 137728925            boardState.GenerateMoves();
 9777836026            foreach (Move move in boardState.Moves)
 27            {
 4751189128                MoveOrdering.PopulateMoveScore(move, boardState);
 29            }
 137728930            List<Move> moves = boardState.Moves;
 31
 883825232            for(int i = 0; i < moves.Count; ++i)
 33            {
 441912634                MoveOrdering.SortNextBestMove(moves, i);
 441912635                Move move = moves[i];
 441912636                if (cancellationToken.IsCancellationRequested)
 37                    break;
 441912538                if (!move.IsCapture())
 39                    break; // If sorted, once a quiet move is reached we won't need to visit the remaining nodes
 40
 352324641                boardState.MakeMove(move);
 352324642                if (boardState.IsInCheck(boardState.SideToMove.Other()))
 43                {
 46276144                    boardState.UnmakeMove(move);
 46276145                    continue;
 46                }
 306048547                int score = -Search(boardState, -beta, -alpha, cancellationToken);
 306048548                boardState.UnmakeMove(move);
 49
 306048550                if (score >= beta)
 48140951                    return beta;
 257907652                if (score > alpha)
 77653                    alpha = score;
 54            }
 89588055            return alpha;
 56        }
 57
 58        public static void ResetNodes()
 59        {
 5260            Nodes = 0;
 5261        }
 62    }
 63}