Skip to content

Commit

Permalink
Move to .NET 8 (#291)
Browse files Browse the repository at this point in the history
* Move to .NET 8
* Ensure `appsettings.json` are the same ones as default Configuration ones, given that settings file isn't really working for prod builds. This should avoid surprises once it starts working (active pr in dotnet runtim repo)
* Apply analysis suggestions:
  * Use Logger instead of ILogger in static classes when  getting it via `LogManager.GetCurrentClassLogger();`
  * Improve `RevertLastMove()` by using `[^1` instead of .Last()
  * Move to `init` properties for tb record, since json deserialization into record classes with init properties is only supported in .NET 8
  • Loading branch information
eduherminio authored Aug 1, 2023
1 parent d8e0b21 commit 51f0e75
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 149 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
fail-fast: false

env:
DOTNET_VERSION: 8.0.x
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_TieredPGO: 1
DOTNET_ReadyToRun: 0
Expand All @@ -30,7 +31,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Nuget cache
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- cron: '1 0 * * 1' # Mondays at 00:01

env:
DOTNET_VERSION: 7.0.x
DOTNET_VERSION: 8.0.x
PROJECT_NAME: Lynx
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_TieredPGO: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on:
required: false

env:
DOTNET_VERSION: 7.0.x
DOTNET_VERSION: 8.0.x
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_TieredPGO: 1
DOTNET_ReadyToRun: 0
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>Enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Lynx is a chess engine developed by [@eduherminio](https://github.com/eduherminio).

It's written in C# (.NET 7).
It's written in C# (.NET 8).

You can find Lynx:

Expand All @@ -23,12 +23,13 @@ Lichess bot can be played directly, but a chess GUI that supports UCI protocol i

| Lynx version | CCRL Blitz elo |
|-----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [0.13.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.13.0) | [1736](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.13.0%2064-bit#Lynx_0_13_0_64-bit) |
| [0.11.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.11.0) | [1603](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.11.0%2064-bit#Lynx_0_11_0_64-bit) |
| [0.10.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.10.0) | [1558](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.10.0%2064-bit#Lynx_0_10_0_64-bit) |
| [0.9.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.9.0) | [1575](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.9.0%2064-bit#Lynx_0_9_0_64-bit) |
| [0.6.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.6.0) | [1407](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.6.0%2064-bit#Lynx_0_6_0_64-bit) |
| [0.4.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.4.0) | [1361](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.4.0%2064-bit#Lynx_0_4_0_64-bit) |
| [0.14.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.14.0) | [1804](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.14.0%2064-bit#Lynx_0_14_0_64-bit) |
| [0.13.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.13.0) | [1762](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.13.0%2064-bit#Lynx_0_13_0_64-bit) |
| [0.11.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.11.0) | [1618](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.11.0%2064-bit#Lynx_0_11_0_64-bit) |
| [0.10.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.10.0) | [1573](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.10.0%2064-bit#Lynx_0_10_0_64-bit) |
| [0.9.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.9.0) | [1591](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.9.0%2064-bit#Lynx_0_9_0_64-bit) |
| [0.6.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.6.0) | [1419](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.6.0%2064-bit#Lynx_0_6_0_64-bit) |
| [0.4.0](https://github.com/lynx-chess/Lynx/releases/tag/v0.4.0) | [1367](http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Lynx%200.4.0%2064-bit#Lynx_0_4_0_64-bit) |

## Building Lynx

Expand All @@ -38,7 +39,7 @@ However, you can also choose to build Lynx yourself.

### Requirements

- [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0). You can find instructions about how to install it in your preferred OS/Distro either [here](https://docs.microsoft.com/en-us/dotnet/core/install/) or [here](https://github.com/dotnet/core/tree/main/release-notes/7.0).
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0). You can find instructions about how to install it in your preferred OS/Distro either [here](https://docs.microsoft.com/en-us/dotnet/core/install/) or [here](https://github.com/dotnet/core/tree/main/release-notes/8.0).

If you're a Linux user and are new to .NET ecosystem, the conversation in [this issue](https://github.com/lynx-chess/Lynx/issues/33) may help.

Expand Down
10 changes: 5 additions & 5 deletions src/Lynx.Benchmark/FENGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public string RecordStruct_FENCalculatedWithinTheMoveConstructor(string fen)

internal struct StructCustomPosition
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private string? _fen;

Expand Down Expand Up @@ -699,7 +699,7 @@ private readonly string CalculateFEN()

internal readonly struct ReadonlyStructCustomPosition
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

public string FEN { get; private init; }

Expand Down Expand Up @@ -1053,7 +1053,7 @@ private readonly string CalculateFEN()

internal class ClassCustomPosition
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private string? _fen;

Expand Down Expand Up @@ -1412,7 +1412,7 @@ private string CalculateFEN()

internal record class RecordClassCustomPosition
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private string? _fen;

Expand Down Expand Up @@ -1771,7 +1771,7 @@ private string CalculateFEN()

internal record struct RecordStructCustomPosition
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private string? _fen;

Expand Down
2 changes: 1 addition & 1 deletion src/Lynx.Benchmark/MoveGeneratorParallel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Move[] WhenAllArray(string fen)

public static class CustomMoveGenerator
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private const int TRUE = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/Lynx.Cli/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Lynx.Cli;
public sealed class Listener
{
private readonly Channel<string> _guiInputReader;
private readonly ILogger _logger;
private readonly Logger _logger;

public Listener(Channel<string> guiInputReader)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Lynx.Cli/Lynx.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>

<PropertyGroup Condition="'$(Optimized.ToLower())'=='true'">
Expand All @@ -17,9 +18,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.2" />
</ItemGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Lynx.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
.AddEnvironmentVariables()
.Build();

#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code - Application code isn't trimmed, see https://github.com/dotnet/runtime/discussions/59230
config.GetRequiredSection(nameof(EngineSettings)).Bind(Configuration.EngineSettings);
config.GetRequiredSection(nameof(GeneralSettings)).Bind(Configuration.GeneralSettings);
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code

if (!Configuration.GeneralSettings.DisableLogging)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lynx.Cli/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Lynx.Cli;
public sealed class Writer
{
private readonly ChannelReader<string> _engineOutputReader;
private readonly ILogger _logger;
private readonly Logger _logger;

public Writer(ChannelReader<string> engineOutputReader)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Lynx.Cli/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"SecondTimeLimitWhenNoMovesToGoProvided": 30000,
"SecondCoefficientWhenNoMovesToGoProvided": 2,
"MinSecurityTime": 1000,
"CoefficientSecurityTime": 0.9,
"CoefficientSecurityTime": 0.95,
"MinDepth": 4,
"MaxDepth": 128,
"MaxDepth": 64,
//"MinMoveTime": 1000,
//"DepthWhenLessThanMinMoveTime": 5,
"MinElapsedTimeToConsiderStopSearching": 0,
Expand All @@ -41,10 +41,10 @@
75,
100,
150,
0
200
],
"SemiOpenFileRookBonus": 10,
"OpenFileRookBonus": 12,
"OpenFileRookBonus": 15,
"SemiOpenFileKingPenalty": 10,
"OpenFileKingPenalty": 15,
"KingShieldBonus": 5,
Expand Down
8 changes: 1 addition & 7 deletions src/Lynx/AssertException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.Serialization;

namespace Lynx;
namespace Lynx;

public class AssertException : Exception
{
Expand All @@ -15,8 +13,4 @@ public AssertException(string? message) : base(message)
public AssertException(string? message, Exception? innerException) : base(message, innerException)
{
}

protected AssertException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
2 changes: 1 addition & 1 deletion src/Lynx/FENParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static partial class FENParser

private static readonly Regex _ranksRegex = RanksRegex();

private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

public static (bool Success, BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, Side Side, int Castle, BoardSquare EnPassant,
int HalfMoveClock, int FullMoveCounter) ParseFEN(string fen)
Expand Down
5 changes: 3 additions & 2 deletions src/Lynx/LinxDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public sealed class LinxDriver
private readonly ChannelReader<string> _uciReader;
private readonly Channel<string> _engineWriter;
private readonly Engine _engine;
private readonly ILogger _logger;
private readonly Logger _logger;
private static readonly string[] _none = new[] { "none" };

public LinxDriver(ChannelReader<string> uciReader, Channel<string> engineWriter, Engine engine)
{
Expand Down Expand Up @@ -203,7 +204,7 @@ private void HandleSetOption(string command, string[] commandItems)
{
if (commandItems.Length > 4)
{
_logger.Info("Game against {0}", string.Join(' ', commandItems.Skip(4).Except(new[] { "none" })));
_logger.Info("Game against {0}", string.Join(' ', commandItems.Skip(4).Except(_none)));
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/Lynx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0-preview.6.23329.11" />
<PackageReference Include="NLog" Version="5.2.2" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/Lynx/Model/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Lynx.Model;

public sealed class Game
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

public Move[] MovePool { get; } = new Move[Constants.MaxNumberOfPossibleMovesInAPosition];

Expand Down Expand Up @@ -80,7 +80,7 @@ internal void RevertLastMove()
{
if (PositionHistory.Count != 0)
{
CurrentPosition = PositionHistory.Last();
CurrentPosition = PositionHistory[^1];
PositionHistory.Remove(CurrentPosition);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/Model/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class MoveExtensions
{
public const int CaptureBaseScore = 100_000;

private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

/// <summary>
/// 'Encode' constractor
Expand Down
Loading

0 comments on commit 51f0e75

Please sign in to comment.