Get stockfish running on linux server

This commit is contained in:
2025-07-03 20:08:41 +00:00
parent d799b88403
commit f21a8320ce
3 changed files with 33 additions and 3 deletions
+5
View File
@@ -10,6 +10,11 @@
<PackageReference Include="System.Text.Json" Version="9.0.3" />
</ItemGroup>
<ItemGroup>
<None Include="Resources/**"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
<Folder Include="wwwroot\css\debug\" />
Binary file not shown.
@@ -4,6 +4,7 @@ using JoshHeaps.Net.Services.Interfaces;
using Microsoft.AspNetCore.SignalR;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Channels;
@@ -19,8 +20,23 @@ public sealed class Stockfish : IAsyncDisposable
public Stockfish(int skill = 20, int hash = 256)
{
_skill = skill;
string exePath = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string relativeFilePath = @"\Resources\stockfish-windows-x86-64-avx2.exe";
string exePath = Assembly.GetExecutingAssembly().Location.Split(@"\bin\")[0] + relativeFilePath;
exePath = Assembly.GetExecutingAssembly().Location.Split(@"\bin\")[0] + relativeFilePath;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string relativeFilePath = @"/Resources/stockfish-ubuntu-x86-64-sse41-popcnt";
exePath = Assembly.GetExecutingAssembly().Location.Split(@"/bin/")[0] + relativeFilePath;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
string relativeFilePath = @"/Resources/stockfish-mac-x86-64-avx2";
exePath = Assembly.GetExecutingAssembly().Location.Split(@"/bin/")[0] + relativeFilePath;
}
Console.Write(exePath);
@@ -36,7 +52,16 @@ public sealed class Stockfish : IAsyncDisposable
}
};
try
{
_p.Start();
}
catch (Exception ex)
{
Console.WriteLine($"Error starting process: {ex.Message}");
throw;
}
_stdin = _p.StandardInput;
_ = Task.Run(async () =>