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" /> <PackageReference Include="System.Text.Json" Version="9.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources/**"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Resources\" /> <Folder Include="Resources\" />
<Folder Include="wwwroot\css\debug\" /> <Folder Include="wwwroot\css\debug\" />
Binary file not shown.
@@ -4,6 +4,7 @@ using JoshHeaps.Net.Services.Interfaces;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Channels; using System.Threading.Channels;
@@ -19,8 +20,23 @@ public sealed class Stockfish : IAsyncDisposable
public Stockfish(int skill = 20, int hash = 256) public Stockfish(int skill = 20, int hash = 256)
{ {
_skill = skill; _skill = skill;
string relativeFilePath = @"\Resources\stockfish-windows-x86-64-avx2.exe"; string exePath = string.Empty;
string exePath = Assembly.GetExecutingAssembly().Location.Split(@"\bin\")[0] + relativeFilePath;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string relativeFilePath = @"\Resources\stockfish-windows-x86-64-avx2.exe";
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); Console.Write(exePath);
@@ -36,7 +52,16 @@ public sealed class Stockfish : IAsyncDisposable
} }
}; };
_p.Start(); try
{
_p.Start();
}
catch (Exception ex)
{
Console.WriteLine($"Error starting process: {ex.Message}");
throw;
}
_stdin = _p.StandardInput; _stdin = _p.StandardInput;
_ = Task.Run(async () => _ = Task.Run(async () =>