< 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    {
 860657610        public static int Nodes { get; private set; } = 0;
 11        public static int Search(BoardState boardState, int alpha, int beta, CancellationToken cancellationToken)
 12        {
 430324113            Nodes++;
 14
 430324115            if (boardState.IsDraw())
 016                return 0;
 17
 430324118            int eval = PieceSquareTableEvaluation.Evaluate(boardState);
 19
 430324120            if (eval >= beta)
 292407021                return beta;
 137917122            if (eval > alpha)
 241323                alpha = eval;
 24
 137917125            boardState.GenerateMoves();
 9785489226            foreach (Move move in boardState.Moves)
 27            {
 4754827528                MoveOrdering.PopulateMoveScore(move, boardState);
 29            }
 137917130            List<Move> moves = boardState.Moves;
 31
 884763032            for(int i = 0; i < moves.Count; ++i)
 33            {
 442381534                MoveOrdering.SortNextBestMove(moves, i);
 442381535                Move move = moves[i];
 442381536                if (cancellationToken.IsCancellationRequested)
 37                    break;
 442381438                if (!move.IsCapture())
 39                    break; // If sorted, once a quiet move is reached we won't need to visit the remaining nodes
 40
 352606741                boardState.MakeMove(move);
 352606742                if (boardState.IsInCheck(boardState.SideToMove.Other()))
 43                {
 46287944                    boardState.UnmakeMove(move);
 46287945                    continue;
 46                }
 306318847                int score = -Search(boardState, -beta, -alpha, cancellationToken);
 306318848                boardState.UnmakeMove(move);
 49
 306318850                if (score >= beta)
 48142351                    return beta;
 258176552                if (score > alpha)
 77653                    alpha = score;
 54            }
 89774855            return alpha;
 56        }
 57
 58        public static void ResetNodes()
 59        {
 5260            Nodes = 0;
 5261        }
 62    }
 63}