Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in AI and Deep Learning by (50.2k points)

Ok, so I have been working on my chess program for a while and I am beginning to hit a wall. I have done all of the standard optimizations (negascout, iterative deepening, killer moves, history heuristic, quiescent search, pawn position evaluation, some search extensions) and I'm all out of ideas!

I am looking to make it multi-threaded soon, and that should give me a good boost in performance, but aside from that, are there any other nifty tricks you guys have come across? I have considered switching to MDF(f), but I have heard it is a hassle and isn't really worth it.

what I would be most interested in is some kind of learning algorithm, but I don't know if anyone has done that effectively with a chess program yet.

also, would switching to a bit board be significant? I currently am using 0x88.

1 Answer

0 votes
by (108k points)

I would like to share some tricks with you:

Your first problem in code optimization will be the measurement.

  1. Measuring performance: You can improve your performance in two ways:

    • Evaluate your nodes faster

    • Search fewer nodes to come up with the same answer

How do you come to know that you really have made a difference? In order to help you with this problem, you have to record some statistics during your move searches like the time it took for the search to complete and the number of nodes searched during its performance.

This will allow you to get a standard point of reference in your performance and test your changes. For testing, you can create several save games from the opening position, middle game, and the end game. Record the time and number of nodes searched for black and white. After making any changes you can perform tests against the above mentioned save games to see if you have made any improvements in the above two matrices: the number of nodes searched or speed in the performance.

  1. Finding performance gain: Now after knowing how to measure your performance, let us discuss how to identify potential performance gain:

If you are in a .NET environment then the .NET profiler will identify your potential performance gain

Your profiler will surely identify things for you, however, there are some small lessons you will learn working with C#:

  • Make everything private

  • Whatever you can’t make private, make it sealed

  • Make as many methods static as possible.

  • Don’t make your methods chatty, one long method is better than 4 smaller ones.

  • Chess board stored as an array [8][8] is slower than an array of [64]

  • Replace int with byte where possible.

  • Return from your methods as early as possible.

  • Stacks are better than lists

  • Arrays are better than stacks and lists.

  • If you can define the size of the list before you populate it.

  • Casting, boxing, unboxing is evil.

Interested in learning Artificial Intelligence? Enrol in our Artificial Intelligence Course now!

Browse Categories