Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: unique distance relationship

Author: Gerd Isenberg

Date: 10:21:34 08/16/02

Go up one level in this thread


On August 16, 2002 at 05:17:48, Gerd Isenberg wrote:

>On August 16, 2002 at 04:31:32, Sune Fischer wrote:
>
>>On August 15, 2002 at 17:13:23, Gerd Isenberg wrote:
>>
>>Looks interesting :)
>>
>>>bool sameSquareColor(int sq1, int sq2) {
>>>   return (combidist[sq1][sq2] & 1) == 0;}
>>
>>I think this one is faster without table lookup though:
>>
>>bool sameSquareColor(int sq1, int sq2) {
>>   return (((sq1^sq2)&1)^1); // or (!((sq1^sq2)&1));
>>}
>>
>>The above is derived from this observation:
>>If sq1 and sq2 have the same color, they are equivalent modulo 2 since equals
>>are black and unequals white (at least in my notation).
>>
>>so you can do
>>bool isSquareWhite(int sq) {
>>   return (sq&1);
>>}
>>
>>(I didn't test it, so check it:)
>>
>>-S.
>
>Hi Sune,
>
>i think your function don't considers the odd/even change between the ranks.
>Square 0(A1) is black, 1(B1) is white... 7(H1)-is white
>Square 8(A2) is white!...
>
>// return: 0 = white square, 1 = black square
>int colorOfsquare (int sq) {
>   return (sq^(sq>>3))&1;}
>


oups, this is wrong of course it must be negated, A1 is black.

// return: 0 = white square, 1 = black square
int colorOfsquare (int sq) {
   return (sq^1^(sq>>3))&1;}


>bool sameSquareColor(int sq1, int sq2) {
>   return colorOfsquare(sq1) == colorOfsquare(sq2);}
>
>or
>
>bool sameSquareColor(int sq1, int sq2) {
>   return ((sq1^sq2^((sq1^sq2)>>3))&1) == 0;}
>
>Gerd



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.