2

I am starting to look at chessboard representation with the 0x88 hex array board rep, but I'm getting confused! Please help me understand it properly!

The 0x88 chess board representations I have seen as examples around on net resources say it can be thought of as representing a 16x8 2D array (size 128 and so is used as 2 boards side by side to check off board moves etc).

However, afaik, hex value 0x88 is equivalent to 136 in decimal (10001000 in binary) so why is the array size not size 136 (136 bytes)? I must be overlooking something simple with this. I apologise for this and will no doubt feel very foolish when I find what mistaken thinking my brain is stuck with over this!

I am grateful for any helpful replies,many thanks

7

0x88 is just the name of the system. The actual length of the board array is 128.

The name comes from the fact that a bitwise AND can be performed the index of a square (range is 0 to 127) and 0x88. If the result is non-zero, then the square is not on the board. This happens because 0x88 is 10001000 in binary and every square on the board will have the form 0xxx0xxx.

Another benefit of the system is that all of the legal squares can be trivially constructed in octal notation. For example, d4 is 0x33 assuming that 0x00 is the lower left of the board (both d and 4 are the 4th square from the edge, so 3 in a zero-indexed array).

See https://chessprogramming.wikispaces.com/0x88 for more information about this system.

3
  • Hi Andrew and thanks for your swift reply. I'm still not sure about this bitwise op and why the system is called 0x88. Hopefully if I read more about it I will come to understand it more. I looked at your link but I do not understand this yet " 0x88 is C-syntax and the hexadecimal value of a mask of bits need to be zero for valid square coordinates (136 decimal, 210 octal, 10001000B)." I hope that given time I will get to understand this chessboard representation properly! Best wishes :-)
    – rpd
    Dec 23 '13 at 22:03
  • @rpd As an example, consider finding all of the moves to the right for a rook on g1. That square is 0x06. To get to the next square, we add 1: 0x07. Then we test to see if it's on the board (0x88 & 0x07 => 0). Since that is zero, it's on the board (the h1 square). Repeat: 0x08 is the next square (i1) and the bitmask is as follows: 0x08 & 0x88 => 0x08. Since that is non-zero, the square is off the board and the move Rg1-i1 is illegal. These bitwise operations were much faster than memory lookup in early programs which is why this system is so popular.
    – Andrew
    Dec 23 '13 at 23:24
  • Andrew,many thanks for your further helpful explanation. I am a novice C programmer still & as I do not yet understand using 0x88 as a mask(?) or ANDing it with the next square as a test for on board square. I will be looking at this int ime and I'm sure I will understand it properly. I have been looking at chess board reps and I will be sticking with a 1D or 2D 64 square array (unless I use 12x12 array or 10x12 array to help off board square detection). Later I may consider 0x88 system but I need to learn it properly first! Again many thanks for your clear explanation of 0x88..best wishes
    – rpd
    Dec 24 '13 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.