Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Trying to understand 0x88

Author: Robert Hyatt

Date: 07:32:16 10/30/03

Go up one level in this thread


On October 30, 2003 at 09:49:28, Edward Seid wrote:

>I'm trying to understand 0x88 board representation.  My reference is Bruce
>Moreland's page at http://www.seanet.com/~brucemo/topics/0x88.htm  Note that I'm
>not a C programmer, so please explain in generic coding terms.
>
>I've figured out that (index & &H88) is used to determine if the square is on
>the board.  The square is off the board if (index & &H88) = &H08, &H80 or &H88.
>
>My question is... is there a quick way to determine if (index & &H88) is equal
>to any of those 3 numbers?  Since I'm programming in Visual Basic, the best that
>I've come up with is:


Why do you want to do that?  The first point of 0x88 is that with a
single AND boolean operation, you can answer the question "did I just
move a sliding piece off the edge of the board?"

if (sq & 0x88) produces a non-zero result, the answer is "yes"...

any reasonable language interprets 0 as "false" and non-zero as
"true".  But for those that don't, you change it to this:

if ((sq & 0x88) > 0) then it is off the board.  IE older Cray fortran
compilers used to use 0=false, -1=true, which would break the first
type of test above, but the second would work.


>
>mask = index And &H88
>If (mask = &H08) Or (mask = &H80) Or (mask = &H88) Then
>   ' square is off board
>Else
>   ' square is on board
>End If
>
>I thought there was a shortcut way.  Visual Basic doesn't have bitshift
>operators, in case that's required.
>
>Thanks in advance.

Just and with 0x88.  That leaves at _most_ two bits set in the byte.  If
either bit is set (or both are set) the square is off the board.  Only when
both bitz are zero are you on the board.




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.