< 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    {
 861202010        public static int Nodes { get; private set; } = 0;
 11        public static int Search(BoardState boardState, int alpha, int beta, CancellationToken cancellationToken)
 12        {
 430596313            Nodes++;
 14
 430596315            if (boardState.IsDraw())
 016                return 0;
 17
 430596318            int eval = PieceSquareTableEvaluation.Evaluate(boardState);
 19
 430596320            if (eval >= beta)
 292559821                return beta;
 138036522            if (eval > alpha)
 241323                alpha = eval;
 24
 138036525            boardState.GenerateMoves();
 9790046426            foreach (Move move in boardState.Moves)
 27            {
 4756986728                MoveOrdering.PopulateMoveScore(move, boardState);
 29            }
 138036530            List<Move> moves = boardState.Moves;
 31
 885315632            for(int i = 0; i < moves.Count; ++i)
 33            {
 442657834                MoveOrdering.SortNextBestMove(moves, i);
 442657835                Move move = moves[i];
 442657836                if (cancellationToken.IsCancellationRequested)
 37                    break;
 442657738                if (!move.IsCapture())
 39                    break; // If sorted, once a quiet move is reached we won't need to visit the remaining nodes
 40
 352763841                boardState.MakeMove(move);
 352763842                if (boardState.IsInCheck(boardState.SideToMove.Other()))
 43                {
 46292044                    boardState.UnmakeMove(move);
 46292045                    continue;
 46                }
 306471847                int score = -Search(boardState, -beta, -alpha, cancellationToken);
 306471848                boardState.UnmakeMove(move);
 49
 306471850                if (score >= beta)
 48142551                    return beta;
 258329352                if (score > alpha)
 77653                    alpha = score;
 54            }
 89894055            return alpha;
 56        }
 57
 58        public static void ResetNodes()
 59        {
 5260            Nodes = 0;
 5261        }
 62    }
 63}