Problem with Move Gen in 0x88

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Suji

Problem with Move Gen in 0x88

Post by Suji »

I'm not writing the complicated part yet, but I've hit a snag. I'm working through my move generation code, and right now I'm looping through all the squares and testing to see if the square is on the board. It prints the first six ranks, and then it gets to 96 in my for loop and quits printing anything.

Here is the relevant code. I really can't see what I'm doing wrong. I want to make sure the loop prints all squares on the board before I do anything with moves, since it's hard to generate the moves for a square it won't hit.

Code: Select all

for&#40;int i = 0; i < 120;)
&#123;
     if&#40;&#40;board&#91;i&#93; & 0x88&#41; != 0&#41;
     &#123;
              cout << i << " Square not on board..." << endl;
              i += 8;
              continue;
     &#125;
     else 
     &#123;
             cout << i << endl;
             i++;
      &#125;
&#125;
As I see it, it should loop through all 120 iterations. I've check 96 in a decimal to binary converter, and it comes out to be 01100000. It should print it.
oysteijo

Re: Problem with Move Gen in 0x88

Post by oysteijo »

Code: Select all

if&#40;&#40;board&#91;i&#93; & 0x88&#41; != 0&#41; 
You are doing bitwise AND of the board content and not the index.

-Øystein
Suji

Re: Problem with Move Gen in 0x88

Post by Suji »

Arrgh! I knew it was something simple.

Thanks.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Problem with Move Gen in 0x88

Post by bob »

Suji wrote:I'm not writing the complicated part yet, but I've hit a snag. I'm working through my move generation code, and right now I'm looping through all the squares and testing to see if the square is on the board. It prints the first six ranks, and then it gets to 96 in my for loop and quits printing anything.

Here is the relevant code. I really can't see what I'm doing wrong. I want to make sure the loop prints all squares on the board before I do anything with moves, since it's hard to generate the moves for a square it won't hit.

Code: Select all

for&#40;int i = 0; i < 120;)
&#123;
     if&#40;&#40;board&#91;i&#93; & 0x88&#41; != 0&#41;
     &#123;
              cout << i << " Square not on board..." << endl;
              i += 8;
              continue;
     &#125;
     else 
     &#123;
             cout << i << endl;
             i++;
      &#125;
&#125;
As I see it, it should loop through all 120 iterations. I've check 96 in a decimal to binary converter, and it comes out to be 01100000. It should print it.

To terminate the loop, you should be doing "i & 0x88" as "i" is the square number. You don't test the contents of the board squares, you test the square numbers themselves.