c# for chess engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Sergei S. Markoff
Posts: 227
Joined: Mon Sep 12, 2011 11:27 pm
Location: Moscow, Russia

c# for chess engine

Post by Sergei S. Markoff »

I've just spent a few days to write a simple engine on C#. I was surprised that it's not so slow as I presumed. Bitboard engine (base on de Bruijn numbers) with alpha/beta, w/o move ordering and with eval based on psq/material does 1 200 000 pos/sec. at my notebook (while SmarThink does about 450 knodes/sec). It looks promising, I hope completely rewritten engine will be not more that 10–15% slower than original.
The Force Be With You!
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: c# for chess engine

Post by wgarvin »

C# assemblies are statically compiled with an AOT compiler. (I don't think desktop .NET even has a bytecode interpreter in it, everything gets compiled). If you avoid using the more dynamic language features, performance should be pretty good. Maybe a little bit less than you can achieve with C or C++, but still pretty good.
Sergei S. Markoff
Posts: 227
Joined: Mon Sep 12, 2011 11:27 pm
Location: Moscow, Russia

Re: c# for chess engine

Post by Sergei S. Markoff »

wgarvin wrote:C# assemblies are statically compiled with an AOT compiler. (I don't think desktop .NET even has a bytecode interpreter in it, everything gets compiled). If you avoid using the more dynamic language features, performance should be pretty good. Maybe a little bit less than you can achieve with C or C++, but still pretty good.
Yes, I think so. Especially if you're using unchecked {} and other possible optimisation options.
The Force Be With You!
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: c# for chess engine

Post by Steve Maughan »

Hi Sergei,

Glad you're back!

I don't know if you saw the thread but your name came up recently

http://www.talkchess.com/forum/viewtopic.php?t=40365

So is Smarthink dead? Or will you also call the new engine Smarthink? Why switch from C to C#?

Cheers,

Steve
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c# for chess engine

Post by lucasart »

Sergei S. Markoff wrote:I've just spent a few days to write a simple engine on C#. I was surprised that it's not so slow as I presumed. Bitboard engine (base on de Bruijn numbers) with alpha/beta, w/o move ordering and with eval based on psq/material does 1 200 000 pos/sec. at my notebook (while SmarThink does about 450 knodes/sec). It looks promising, I hope completely rewritten engine will be not more that 10–15% slower than original.
that is very fast indeed! probably faster than my C engine...
i wonder how fast a good C engine can go (in nodes/sec) on simple perft calculation (no eval, just generate, play, undo moves)
Sergei S. Markoff
Posts: 227
Joined: Mon Sep 12, 2011 11:27 pm
Location: Moscow, Russia

Re: c# for chess engine

Post by Sergei S. Markoff »

SmarThink is written on plain C. The coding was started in 2000, when I wasn't very experienced. Finally that code is hard to manage now.
I'm planning to write new engine on c#, using SmarThink parts of course.
Now I have some beta, w/o most of neccessary parts.
I don't know how much time I can spent for this project — I need to spent much time to my current busyness, so I'm not sure that I will quickly produce something well-working)
The Force Be With You!
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: c# for chess engine

Post by Steve Maughan »

Great - I wish you well.

If the C version of SmarThink has been retired, how about releasing it as Freeware? Just an idea (I'd happily host it).

Steve
Sergei S. Markoff
Posts: 227
Joined: Mon Sep 12, 2011 11:27 pm
Location: Moscow, Russia

Re: c# for chess engine

Post by Sergei S. Markoff »

Steve Maughan wrote:If the C version of SmarThink has been retired, how about releasing it as Freeware? Just an idea (I'd happily host it).
Steve
Let see, may be I will do it. I need to discuss it with Lokasoft of course.
The Force Be With You!
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: c# for chess engine

Post by Steve Maughan »

Sure - let me know if you'd like to take me up on the offer of hosting.

Cheers,

Steve
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: c# for chess engine

Post by stegemma »

Sergei S. Markoff wrote:I've just spent a few days to write a simple engine on C#. I was surprised that it's not so slow as I presumed. Bitboard engine (base on de Bruijn numbers) with alpha/beta, w/o move ordering and with eval based on psq/material does 1 200 000 pos/sec. at my notebook (while SmarThink does about 450 knodes/sec). It looks promising, I hope completely rewritten engine will be not more that 10–15% slower than original.
Me too, i've changed from assembly to C++ and the overhead of the language seems to be less important than the advantage to program in an high level language. For me is important to use a good profiling tool (that isn't available for assembly code that i've used before). For sample, with the profiler of XDev i've found that my new engine in C++ was spending 47% of the time just clearing moves list (with memset function). That calling was not necessary so with just few minutes of profiling i've just doubled the engine speed.

Maybe at the end it is important to use the language that you better know...