hmm, maybe you should init the result array
Code: Select all
Code:
int result[] = {0,0,0,0,0,0,0,0};
OMG,
When I win the lottery, where do I make checks payable too?
It works! Thanks a million,
Joshua
Moderators: hgm, Rebel, chrisw
hmm, maybe you should init the result array
Code: Select all
Code:
int result[] = {0,0,0,0,0,0,0,0};
there isn't a name for it ...jhaglund wrote:Code:Code: Select all
result[8] /* 0-7 => a-h */ for (i =0; i<64; i++) result[i-(i&56)]+=sq[i]
i-(i&56)
is the same as
i & 7
I'm not familar with this technique. What is this technique called?
Posted: Sun Jun 20, 2010 4:28 pm Post subject: Re: Vector problem - square addition
--------------------------------------------------------------------------------
jhaglund wrote:
Quote:
Code: Code:
result[8] /* 0-7 => a-h */
for (i =0; i<64; i++)
result[i-(i&56)]+=sq
Quote:
i-(i&56)
is the same as
i & 7
I'm not familar with this technique. What is this technique called?
there isn't a name for it ...
what you want is the file from a given square ... what is used in the formula is just a bit awkward.
instead of:
result[i-(i&56)]+=sq;
you can write:
result[i&7]+=sq;
these two do the same thing.
a square is a value from 0 to 63
that is 6 bits in binary
the upper three bits denote the rank
the lower three bits denote the file
so if you want to get the file you can either
a) (like in the original code)
mask the rank and subtract it from the original leaving just the file
or
b) (like in my version)
immediately just mask the file
note that
56 is in binary notation 111000.b
and 7 is 000111.b
regards,
Edmund