is there a 10x8 equivalent of 0x88

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

rjgibert
Posts: 317
Joined: Mon Jun 26, 2006 9:44 am

Re: is there a 10x8 equivalent of 0x88

Post by rjgibert »

After determining with the 0x88 trick whether a square is out of bounds or not, you must next determine if the destination square contains a piece of the same color.

It turns out that the 1st test can be folded into the 2nd test with the proper encoding. By assigning the last 2 bits of the token for a piece to convey color as follows:

Code: Select all

0 empty square
1 white piece
2 black piece
3 out of bounds
BTW, 3 can also be thought of as containing both a white piece and a black piece if you prefer to think of it that way.

Now when you want to determine whether a black Queen can move to sq, you would do the test to see if it contains a piece of the same color as follows:

Code: Select all

board[sq]&2
If this returns 0, it is ok to move a black Queen there. Note that the test has simultaneously folded the inbounds test into it.

With 0x88, you would have to do 2 tests to produce the same result:

Code: Select all

sq&0x88
board[sq]&1
Where square color is encoded more simply as a single bit.

Since, the 1st test with 0x88 usually returns an inbounds result, you don't usually save yourself from having to access the board, so skipping this 1st test works out well.