11 January 2016

Hi,
I've been working on a chess project called 'Lux Chess'. This was one of the hardest but yet amazing projects I worked on. I would encourage you to try to make your own chess engine just because there is so much great things you can learn. Anyway, after a few months working on this engine I got some pretty good results and I am satisfied with the engine strength. There is a lot of things that can be improved which I'll be hopefully doing in future.


At the bottom of this post you can find the full source code download link. I hope you will have some fun playing against my engine and I hope you will even improve it or even make a game from it, if you do please don't hesitate to show me.

Now I'll quickly introduce you to my engine.

First thing you need to think about when writing a chess engine is how to represent the board and the pieces. There are many ways, and the first and the worst way that you probably already thought about is using arrays. This is really bad since in the chess engine it is all about the speed and arrays are slow. There are some ways to improve the speed but it's very slow when it comes to the move generation.

That's why I used something which is called bitboards. Since the largest number has a 64 bits and the chess board has a 64 squares you can see that this number can be used to represent the chess squares.
For each piece I had a ulong variable. Each bit can be set to 0 or 1. If it is 0 then that square is empty and if it is 1 then the square is occupied.
Here is the example of the 64 bit number:

0000 0000 0000 0000 0000 0000 0000 0000 = 0 

Now there are a lot of useful instructions and bitwise operators that can be used on this bitboards. There is also a script in the project called Ops which stands for Operations. You can see some of  the functions that helps extracting the bits from the bitboard or even finding their position or index.

Now this is the rough explanation but if you are interested in more details I might release another post which would explain more and even some other parts of the chess engine.

Also for the first time I'm going to put a donate button on my blog. Now you have a chance to help me do more amazing free projects! 

Thank's for reading.

All the best,
Dragutin!

Source code
Donate Button

{ 2 коментара... read them below or Comment }

  1. Thank you friend...

    ReplyDelete
  2. Hello,
    well done!!!!
    i'm using Huo Chess (C# micro chess) for Unity...
    also great...
    respect & thx for sharing
    wish you all the best!

    ReplyDelete

- Copyright © Unity plus - Skyblue - Powered by Blogger - Designed by Johanes Djogan -