Skip to content

Commit

Permalink
🧹 Remove processor #if DEBUG statements from FENParser (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio authored Nov 12, 2024
1 parent 266357d commit ecb1c90
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions src/Lynx/FENParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lynx.Model;
using NLog;
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;

using ParseResult = (ulong[] PieceBitBoards, ulong[] OccupancyBitBoards, int[] board, Lynx.Model.Side Side, byte Castle, Lynx.Model.BoardSquare EnPassant,
Expand Down Expand Up @@ -30,7 +31,7 @@ public static ParseResult ParseFEN(ReadOnlySpan<char> fen)

try
{
success = ParseBoard(fen, pieceBitBoards, occupancyBitBoards, board);
ParseBoard(fen, pieceBitBoards, occupancyBitBoards, board);

var unparsedStringAsSpan = fen[fen.IndexOf(' ')..];
Span<Range> parts = stackalloc Range[5];
Expand Down Expand Up @@ -72,47 +73,27 @@ public static ParseResult ParseFEN(ReadOnlySpan<char> fen)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ParseBoard(ReadOnlySpan<char> fen, BitBoard[] pieceBitBoards, BitBoard[] occupancyBitBoards, int[] board)
private static void ParseBoard(ReadOnlySpan<char> fen, BitBoard[] pieceBitBoards, BitBoard[] occupancyBitBoards, int[] board)
{
bool success = true;
var rankIndex = 0;
var end = fen.IndexOf('/');
while (
end != -1
#if DEBUG
&& success
#endif
)
while (end != -1)
{
var match = fen[..end];
ParseBoardSection(pieceBitBoards, board, rankIndex, match
#if DEBUG
, ref success
#endif
);
ParseBoardSection(pieceBitBoards, board, rankIndex, match);
PopulateOccupancies(pieceBitBoards, occupancyBitBoards);
fen = fen[(end + 1)..];
end = fen.IndexOf('/');
++rankIndex;
}
ParseBoardSection(pieceBitBoards, board, rankIndex, fen[..fen.IndexOf(' ')]
#if DEBUG
, ref success
#endif
);
ParseBoardSection(pieceBitBoards, board, rankIndex, fen[..fen.IndexOf(' ')]);
PopulateOccupancies(pieceBitBoards, occupancyBitBoards);
return success;
static void ParseBoardSection(BitBoard[] pieceBitBoards, int[] board, int rankIndex, ReadOnlySpan<char> boardfenSection
#if DEBUG
, ref bool success
#endif
)
static void ParseBoardSection(BitBoard[] pieceBitBoards, int[] board, int rankIndex, ReadOnlySpan<char> boardfenSection)
{
int fileIndex = 0;
Expand Down Expand Up @@ -147,13 +128,7 @@ static void ParseBoardSection(BitBoard[] pieceBitBoards, int[] board, int rankIn
else
{
fileIndex += ch - '0';
#if DEBUG
if (fileIndex < 1 || fileIndex > 8)
{
System.Diagnostics.Debug.Fail($"Error parsing char {ch} in fen {boardfenSection.ToString()}");
success = false;
}
#endif
Debug.Assert(fileIndex >= 1 && fileIndex <= 8, $"Error parsing char {ch} in fen {boardfenSection.ToString()}");
}
}
}
Expand Down

0 comments on commit ecb1c90

Please sign in to comment.