Ideas of engines written in C#

Discussion of chess software programming and technical issues.

Moderator: Ras

Peperoni
Posts: 72
Joined: Sun Nov 01, 2020 5:27 pm
Full name: Richard Porti

Ideas of engines written in C#

Post by Peperoni »

Do you guys know if some serious chess engines have been written in C#?
mig2004
Posts: 256
Joined: Wed Oct 02, 2013 12:36 am

Re: Ideas of engines written in C#

Post by mig2004 »

Perhaps you might want to read this: https://tearth.dev/posts/performance-of ... rp-part-1/
User avatar
emadsen
Posts: 440
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: Ideas of engines written in C#

Post by emadsen »

I don't know your definition of "serious" but here's mine. MadChess is roughly 2700 Elo.

Blog
Source Code
Erik Madsen | My C# chess engine: https://www.madchess.net
Peperoni
Posts: 72
Joined: Sun Nov 01, 2020 5:27 pm
Full name: Richard Porti

Re: Ideas of engines written in C#

Post by Peperoni »

emadsen wrote: Fri Mar 24, 2023 4:10 pm I don't know your definition of "serious" but here's mine. MadChess is roughly 2700 Elo.

Blog
Source Code
Very nice :) If I wanted to adapt it for .NET 4 , do you think that would be a lot of work?
User avatar
emadsen
Posts: 440
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: Ideas of engines written in C#

Post by emadsen »

Peperoni wrote: Fri Mar 24, 2023 5:30 pm If I wanted to adapt it for .NET 4 , do you think that would be a lot of work?
I don't think so. It has no significant NuGet package dependencies other than for unit tests. I don't believe it references many .NET 7 specific APIs. Perhaps you'll have difficulties with the System.Numerics namespace. I don't know. I haven't written .NET 4 code in years.

Why would you want to backport the code to a 13 year old runtime?
Erik Madsen | My C# chess engine: https://www.madchess.net
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Ideas of engines written in C#

Post by dangi12012 »

One of the best ones : https://github.com/lithander/Leorik

You dont need to think about the API. Microsoft consolidated .net .net core and .net framework into .net standard which is basically backwards compatible. So most of .net 8 (the one from 2023) is the same code as .net framework 4.0 (barring all of nuget)
If you need to run it on windows 98 (for whatever reason) you need .net framework 2
For windows XP you can go .net framework 4

Recommendation: just go with .net 8 and be done with it. It runs of your phone too etc.

Rant about JIT:
Too bad the promise of more performance compared to C++ never materialized. Since all JIT could compile at runtime like march=native which shipped binaries cannot do.
Or compiling a startup settings file at runtime. (c++ can only ever be a const variable x) but C# can compile it as the constant "3" etc..
Its not even a fault of the language - but the MSIL optimizer is not where it could be in theory.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
JoAnnP38
Posts: 253
Joined: Mon Aug 26, 2019 4:34 pm
Location: Clearwater, Florida USA
Full name: JoAnn Peeler

Re: Ideas of engines written in C#

Post by JoAnnP38 »

dangi12012 wrote: Fri Mar 24, 2023 6:49 pm One of the best ones : https://github.com/lithander/Leorik

Recommendation: just go with .net 8 and be done with it. It runs of your phone too etc.
+1 and +1
Peperoni
Posts: 72
Joined: Sun Nov 01, 2020 5:27 pm
Full name: Richard Porti

Re: Ideas of engines written in C#

Post by Peperoni »

emadsen wrote: Fri Mar 24, 2023 6:37 pm
Peperoni wrote: Fri Mar 24, 2023 5:30 pm If I wanted to adapt it for .NET 4 , do you think that would be a lot of work?
I don't think so. It has no significant NuGet package dependencies other than for unit tests. I don't believe it references many .NET 7 specific APIs. Perhaps you'll have difficulties with the System.Numerics namespace. I don't know. I haven't written .NET 4 code in years.

Why would you want to backport the code to a 13 year old runtime?
Thank you :) Because I want to use it with the Unity engine, which is super limited about that : https://docs.unity3d.com/2023.2/Documen ... pport.html
User avatar
emadsen
Posts: 440
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: Ideas of engines written in C#

Post by emadsen »

Oh, you mean .NET Framework 4.8 not .NET Framework 4. Big difference.

I don't understand what you mean by Unity being "super limited". The Unity documentation you linked to says it supports .NET Standard 2.1. So target that. I don't see any reason to limit the runtime to .NET Framework 4.8.
Erik Madsen | My C# chess engine: https://www.madchess.net
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Ideas of engines written in C#

Post by dangi12012 »

.NET Standard 2.1 is the interface
So you can literally pick any modern framework
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer