Welcome to the PureBasic forums, but I have to wonder -
Does this question have anything to do with chess or PureBasic?
If not, perhaps pose it in the offtopic section?
cheers
Storing Chessboard positions
I know that most of this has been touched on before but wouldn't you be able to store all the necessary information about any board in exactly 24bytes and 7bits?
The 7bits are needed for:
1bit - Which players turn is it B or W?
4bit - En passant available (there can be only one en passant/turn and it has to be for the player whose turn it is. Seeing as there are 9 possiblities (8 squares and no en passant available we'll need 4bits for this)
1bit - Is white still able to castle?
1bit - Is black still able to castle?
After that you store 64bits, one for each square. Each bit decides whether or not there is a piece on that square.
1*64 = Is there a piece on square A1:H8?
After that you store 32*4 bits of information for each possible piece:
1bit = colour
3bit = type of piece (there are six pieces for each colour)
All in all this would amount to a total of 7 + 64 + 128bits which equals 199bits which is also 24bytes (192) and 7bits.
The 7bits are needed for:
1bit - Which players turn is it B or W?
4bit - En passant available (there can be only one en passant/turn and it has to be for the player whose turn it is. Seeing as there are 9 possiblities (8 squares and no en passant available we'll need 4bits for this)
1bit - Is white still able to castle?
1bit - Is black still able to castle?
After that you store 64bits, one for each square. Each bit decides whether or not there is a piece on that square.
1*64 = Is there a piece on square A1:H8?
After that you store 32*4 bits of information for each possible piece:
1bit = colour
3bit = type of piece (there are six pieces for each colour)
All in all this would amount to a total of 7 + 64 + 128bits which equals 199bits which is also 24bytes (192) and 7bits.
Have a look at those old thoughts ...
http://www.chessbox.de/Compu/schachzahl1_e.html
http://www.chessbox.de/Compu/schachzahl1_e.html