The official Fatica Labs Blog! RSS 2.0
# Saturday, November 26, 2011

I decide to publish my chess engine plays on bitbucket. Well it is almost a redo from scratch of a complete but buggy chess engine I wrote in the past that I decided to rewrite just because it was difficult to stack into the old code what I learned. The version present when I write this post contains just the move generator and the complete test for it ( I used an other nice engine: roce to compare my perft test results against. What is a perft test ? Well it is a test to prove our engine produces, from a starting board, all the possible different boards in a certain number of ply, accordingly to the chess game rules. This test also give an idea on how fast is the strategy we use to generate moves, even if this can affect just in part the overall performance of the alpha/beta pruning, we should not write a slow blobby monster. Lets see below a session of the test working:


The strange string showing the position are board situations expressed in FEN Notation, that is almost the standard notation we use to talk about board situations. How many test does FelpoII move generator passes ? Well here is the file containing the FEN boards, with the depth plies move counts shown, there is a lot of positions, even tricky and generally challenging positions ( in term of rules ).

What is the performance ? Since almost all chess engine are written in C++ or in C, can a C# engine works at the same level of magnitude of performance ? Here below the performance we have for the starting position:

Depth: 6 119060324 moves 5,34 seconds. 22283422,048 Move/s. Hash Hit=1400809

The same test with roce ( that is a C++ chess engine ):

Perft (6): 119060324, Time: 4.208 s

So almost the same, that is good if we remember that we wrote in C# Smile We just used a little hack: as you probably know ( or will know if you will start playing with chess engines development ) chess engines uses hash tables to store information about a board ( by using hashes against Zobrist Keys ) this tabled is sored in an unamanaged big memory array, this achieved a really sensible increase in performances.

Well some more details about the engine:

  • It uses a 0x88 board representation
  • It uses object oriented code ( so it is easier to understand compared to traditional C++ engines )
  • The internal random numbers for the zobrist key are generated by a Mersenne Twister Generator, that really solved some nasty bug due to wrong hash conflicts when I used the standard random algo of c#.
  • It uses a trasposition table in unmanaged memory to increase performance.
  • It has a performance comparable ( at least in move generation ) with traditional C/C++ engines


What we can do next ?

Complete the engine with a good working Negamax alpha – beta pruning algorithm.

What can we do with the code as is ?

We can use the move generator as is to validate game moves in a two human player UI, or generating fancy images from FEN positions, write a WPF ( another ) chess board ( winboard compatible? so a lot of engines are already written for it) and so on.


Saturday, November 26, 2011 10:11:13 AM (GMT Standard Time, UTC+00:00)  #    Comments [3] - Trackback
CodeProject | CSharp | Games

Saturday, November 26, 2011 10:57:34 AM (GMT Standard Time, UTC+00:00)
It's very interesting, I also had created a small library (in C #) for chess:
Saturday, November 26, 2011 9:59:08 PM (GMT Standard Time, UTC+00:00)
Are you implemented alpha beta too ? What did you use for test ? I'm interested in your experience
Friday, December 02, 2011 7:39:27 AM (GMT Standard Time, UTC+00:00)
All comments require the approval of the site owner before being displayed.
Please login with either your OpenID above, or your details below.
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, strike, strong) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
My Stack Overflow

Send mail to the author(s) E-mail

profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Felice Pollano
Sign In
Total Posts: 157
This Year: 0
This Month: 0
This Week: 0
Comments: 127
This blog visits
All Content © 2019, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano