< Summary

Information
Class: Rudim.Board.History
Assembly: Rudim
File(s): /home/runner/work/rudim/rudim/Rudim/Board/History.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
SaveBoardHistory(...)100%11100%
RestoreBoardHistory()100%11100%
ClearBoardHistory()100%11100%
get_CapturedPiece()100%11100%
get_EnPassantSquare()100%11100%
get_CastlingRights()100%11100%
get_BoardHash()100%11100%
get_LastDrawKiller()100%11100%
get_BestMove()100%11100%
HasHashAppearedTwice(...)100%66100%
IsHistoryEmpty()100%11100%

File(s)

/home/runner/work/rudim/rudim/Rudim/Board/History.cs

#LineLine coverage
 1using Rudim.Common;
 2using System;
 3
 4namespace Rudim.Board
 5{
 6    public static class History
 7    {
 8        private const int HistorySize = 4096;
 19        private static readonly BoardHistory[] BoardHistories = new BoardHistory[HistorySize];
 10        private static int _historyIndex;
 11
 12
 13        public static void SaveBoardHistory(Piece capturedPiece, Square enPassant, Castle originalCastlingRights,
 14            ulong boardHash, int lastDrawKiller, Move bestMove)
 15        {
 562141216            BoardHistories[_historyIndex++] = new BoardHistory
 562141217            {
 562141218                CapturedPiece = capturedPiece,
 562141219                EnPassantSquare = enPassant,
 562141220                CastlingRights = originalCastlingRights,
 562141221                BoardHash = boardHash,
 562141222                LastDrawKiller = lastDrawKiller,
 562141223                BestMove = bestMove
 562141224            };
 562141225        }
 26
 27        public static BoardHistory RestoreBoardHistory()
 28        {
 562109329            return BoardHistories[--_historyIndex];
 30        }
 31
 32        public static void ClearBoardHistory()
 33        {
 1134            Array.Clear(BoardHistories);
 1135            _historyIndex = 0;
 1136        }
 37
 38        public class BoardHistory
 39        {
 1518200040            public Piece CapturedPiece { get; set; }
 1124250541            public Square EnPassantSquare { get; set; }
 1124250542            public Castle CastlingRights { get; internal set; }
 1124474243            public ulong BoardHash { get; set; }
 1124250544            public int LastDrawKiller { get; set; }
 1112206845            public Move BestMove { get; set; }
 46        }
 47
 48        public static bool HasHashAppearedTwice(ulong boardHash, int startingIndex)
 49        {
 21050            int count = 0;
 489051            for (int i = _historyIndex - 1; i >= startingIndex; --i)
 52            {
 223753                if (BoardHistories[i].BoardHash == boardHash)
 1154                    count++;
 55
 223756                if (count == 2)
 257                    return true;
 58            }
 59
 20860            return false;
 61        }
 62        public static bool IsHistoryEmpty()
 63        {
 264            return _historyIndex == 0;
 65        }
 66    }
 67}