Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into eval/incremental-2
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Jan 10, 2025
2 parents 665946e + 85b0cf3 commit 8147466
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/Lynx/FENParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ public static ParseResult ParseFEN(ReadOnlySpan<char> fen)
//{
// _logger.Debug("No full move counter detected");
//}

if (pieceBitBoards[(int)Piece.K].CountBits() != 1
|| pieceBitBoards[(int)Piece.k].CountBits() != 1)
{
throw new LynxException("Missing or extra kings");
}
}
#pragma warning disable S2139 // Exceptions should be either logged or rethrown but not both - meh
catch (Exception e)
{
_logger.Error(e, "Error parsing FEN");
_logger.Error(e, "Error parsing FEN {Fen}", fen.ToString());
success = false;
throw;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Lynx.Test/FENParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void PieceBitBoards()
Assert.True(pieceBitBoards[(int)Piece.K].GetBit(BoardSquare.e1));
}

[TestCase("8/8/8/8/8/8/8/8 w - - 0 1")]
[TestCase("K1k5/8/8/8/8/8/8/8 w - - 0 1")]
[TestCase("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 ")]
[TestCase(Constants.TrickyTestPositionFEN)]
[TestCase(Constants.KillerTestPositionFEN)]
Expand Down Expand Up @@ -187,7 +187,7 @@ public void CastlingRights(string fen, int expectedCastleResult)
{
// Arrange
// Make sure a previous Fen doesn't change anything
const string previuosFen = "8/8/8/8/8/8/8/8 w KQkq - 0 1";
const string previuosFen = "K15k/8/8/8/8/8/8/8 w KQkq - 0 1";
Assert.DoesNotThrow(() => FENParser.ParseFEN(previuosFen));

if (expectedCastleResult >= 0)
Expand Down Expand Up @@ -230,9 +230,9 @@ public void EnPassant_Error(string fen)
Assert.Throws<LynxException>(() => FENParser.ParseFEN(fen));
}

[TestCase("8/8/8/8/8/8/8/8 w KQkq - 0 1", 0)]
[TestCase("8/8/8/8/8/8/8/8 w KQkq - 1 1", 1)]
[TestCase("8/8/8/8/8/8/8/8 w KQkq - 51 1", 51)]
[TestCase("K1k/8/8/8/8/8/8/8 w KQkq - 0 1", 0)]
[TestCase("K1k/8/8/8/8/8/8/8 w KQkq - 1 1", 1)]
[TestCase("K1k/8/8/8/8/8/8/8 w KQkq - 51 1", 51)]
public void HalfMoveClock(string fen, int expectedHalfMoves)
{
var result = FENParser.ParseFEN(fen);
Expand Down
16 changes: 11 additions & 5 deletions tests/Lynx.Test/Model/PositionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ public void CloneConstructor(string fen)
}
}

[TestCase(Constants.EmptyBoardFEN, false)]
[TestCase("K/8/8/8/8/8/8/8 w - - 0 1", false)]
[TestCase("K/8/8/8/8/8/8/8 b - - 0 1", false)]
[TestCase("k/8/8/8/8/8/8/8 w - - 0 1", false)]
[TestCase("k/8/8/8/8/8/8/8 b - - 0 1", false)]
[TestCase(Constants.EmptyBoardFEN)]
[TestCase("K/8/8/8/8/8/8/8 w - - 0 1")]
[TestCase("K/8/8/8/8/8/8/8 b - - 0 1")]
[TestCase("k/8/8/8/8/8/8/8 w - - 0 1")]
[TestCase("k/8/8/8/8/8/8/8 b - - 0 1")]
public void MissingKings(string fen)
{
Assert.Throws<LynxException>(() => new Position(fen));
}

[TestCase(Constants.InitialPositionFEN, true)]
[TestCase("r1k5/1K6/8/8/8/8/8/8 w - - 0 1", false)]
[TestCase("r1bqkbnr/pppp2pp/2n2p2/4p2Q/2B1P3/8/PPPP1PPP/RNB1K1NR w KQkq - 0 1", false)]
[TestCase("r1bqkbnr/pppp2pp/2n2p2/4p2Q/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 0 1", true)]
[TestCase("r1bqk1nr/pppp2pp/2n2p2/4p3/1bB1P3/3P4/PPP2PPP/RNBQK1NR b KQkq - 0 1", false)]
Expand Down
2 changes: 1 addition & 1 deletion tests/Lynx.Test/MoveGeneration/GenerateKnightMovesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static IEnumerable<Move> GenerateKnightCaptures(Position position)
}

[TestCase(Constants.InitialPositionFEN, 4)]
[TestCase("1K1k3/8/8/8/8/P1P2P1P/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 0)]
[TestCase("1k6/8/8/8/8/P1P2P1P/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 0)]
[TestCase("rnbqkbnr/pppppppp/p1p2p1p/8/8/8/8/1K6 b KQkq - 0 1", 0)]
[TestCase("1K1k3/8/2P1P3/1P3P2/3N4/1P3P2/2P1P3/8 w - - 0 1", 0)]
[TestCase("1K1k3/8/2p1p3/1p3p2/3N4/1p3p2/2p1p3/8 w - - 0 1", 8)]
Expand Down

0 comments on commit 8147466

Please sign in to comment.