Jump to content
  • Advertisement
Sign in to follow this  
ashish123

Chess Programing: Request for Code Review.

This topic is 2117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

 

I have written a chess program using bit boards in C# and almost done with move generation(Castling still incomplete).

 

I have also written a PERFT function which gives me  the following statistics for the starting position on the chess board:

  1. 20 Nodes ---> 10 ms  --->  2 kN/s
  2. 400 Nodes --->11 ms  --->  36 kN/s
  3. 8902 Nodes ---> 18 ms  ---> 494.56 kN/s
  4. 197281 Nodes  --->477 ms. ---> 413.59 kN/s
  5. 4865609 Nodes ---> 4372 ms   --->  1112.9 kN/s
  6. 119060324 Nodes ---> 307920  ---> 386.56 kN/s

 

 

This is my very first bit-boards chess engine so don't know much about the speed, however when compared to my previous 0x88 chess stats this is definitely a winner.

 

When I compared these stats with Sharper (amazing chess program), I realized that it is much more faster than this, It computed Perft(6) in 132 ms without hash tables.

 

So I would request some one with experience in chess programming or in c# to review my code and let me know where I am going wrong or what can be done to optimize it.

 

I shall post my code if any one is ready to review the same.

Please note, that there are no visible bugs.

 

Also if any one is aware, kindly post some kind of profiling tool which will help me to understand the coding efficiency better.

 

I am using Visual Studio 2010 as my IDE and C# as the language.

 

Thanks.

 

 

Share this post


Link to post
Share on other sites
Advertisement
I have experience in chess programming, but not in C#. The purpose of perft is to verify correctness of the move generation and functions to make and undo moves. As a proxy for the performance of the code in a real chess game, it's not very useful. It does make sense that the time it takes your program to complete perft 6 shouldn't be orders of magnitude more than other programs.
 
You say that Sharp (I am not familiar with this program) can finished perft 6 in 132 milliseconds without hash tables. If you are using a 3GHz CPU, that means it takes it less than 4 cycles to visit a position. I don't think I believe that claim.
 

Share this post


Link to post
Share on other sites

Thanks alvaro for the reply,

 

I didnot calculate that but yes it seems impossible, however it is what my system shows.

Can you please comment on the speed my program is giving

My machine configuration is 

Intel i3 core,

4.00GB RAM

2.40 GHz.

 

Also it would be helpful if you agree review my code, it uses nothing C# specific. (My program contains everything static even arrays and other stuff).

Getting my code reviewed from an experienced and expert like you would also help me be a better programmer.

 

Kindly help.

 

Thank you.

Share this post


Link to post
Share on other sites

You can show me your code, but I can't promise I will find the time to look at it in detail. Hopefully C# is easy to read.

Share this post


Link to post
Share on other sites
 
I hope my code is readable.
 
Basically I think that MoveExtractor and moveGeneration Methods are what should be analyzed.
 
MoveExtractor is method which will extract the moves from logical grouping using appropriate bitShifts and bitMasks. 
MoveGeneration is as usual.
 
Above are three main classes and heart of my code.
 
 

Share this post


Link to post
Share on other sites

Hi again,

I have completed my move generation logic including the castling and promotions and have verified with the Perft Suite and found now defect in it.

Since you haven't replied back I assume that you are busy and didn't find time to review my code, however if there is any other reason like the code quality was not up to the mark or code was difficult to understand, please let me know so that I can make it the way it is easier for you to review and hence wont take much of your time.

 

This is a log that has been generated to give an idea how much time has been consumed in order to generate moves and so on.

http://pastebin.com/fJeFxuuh

 

Thanks.

Share this post


Link to post
Share on other sites

I took a very brief look at it the day you posted it, and the only thing that I thought was odd is that you had code that checked the type of the captured piece by successively querying each bitboard to see if it is there. It would be better to have an array with the content of the board and keep it in parallel to the bitboard structure (see the "Hybrid Solutions" section here).

 

I find that semi-interpreted languages like C# make it harder to guess where the bottlenecks of performance are, and this is specially true for me, since I don't have any experience with the language.

Share this post


Link to post
Share on other sites

One more thing: You can find many chess-programming experts in a more specialized forum, like this one. I point you there reluctantly, though, because a lot of the participants in that forum lack social skills and you often end up with strange wars that look more like intellectual pissing contests than legitimate attempts at helping people.

Share this post


Link to post
Share on other sites
Hi thanks for replying. I have read great deal of high quality posts from that forum however as you pointed out, I have also read many more posts that turn off mood. Recently, I ran a profiler on code, where it highlights some hot-spots which take time. One of the major concern is while validating the moves. As per my code, I turn it into a super king and check if can capture opponents piece, this would mean that opponenet would be able to capture my king, hence a check. But since It involves all the regeneration again, it takes up lot of time. So I am working on this. I read on In-Between Look up on chessprograming wiki. But cannot imagine how the array or the way to think on it. Can you guide me on this. Is there any better way? One more important reason about me posting here is that you reply in simple language at a level which I can understand. However I am waiting for my membership to get approved there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!