1

To make my engine more efficient, I am writing my engine such that it uses bit-boards in its move generation. But I have a question, suppose I have a rook move mask centered at a specific spot, how might I transpose the rook mask so that it shows the moves for a different position? eg:

from this mask:
[
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [1, 1, 1, "R", 1, 1, 1, 1],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0]
];

to this mask:
[
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [1, 1, 1, "R", 1, 1, 1, 1],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0]
];

If you need any clarifications regarding the question feel free to ask.

  • 1
    That would depend what language you are using wouldnt it? In APL I would just rotate the matrix up circular one unit. Or maybe that is down, I have not used APL for a long time now. – edwina oliver Jan 30 at 3:13
  • @edwinaoliver I am using Javascript if that helps. – Crupeng Jan 30 at 3:21
  • Thanks. That will help whoever answers. I do not use javascript. – edwina oliver Jan 30 at 3:29
  • 3
    The programming language is in the title. – Mike Jones Jan 30 at 12:58
4

In the beginning, they thought that using a right shift (or a left shift), but they found that, as with other systems, bit would fall off the board. To correct this, they computed every move from each square for each piece. This takes a performance hit only when the page loads. The other alternative they tried was to just load precomputed bitboards which increases the data slightly.

I've developed a system which has drawbacks including being slightly slower, but it's easier to understand.

First you need three arrays:

const int movement[64] ={

17171, 50075, 50075, 50075, 50075, 50075, 33179, 32905, 

18231, 51199, 59391, 59391, 59391, 59391, 41471, 41165, 

20279, 57343, 65535, 65535, 65535, 65535, 45567, 45261, 

20279, 57343, 65535, 65535, 65535, 65535, 45567, 45261, 

20279, 57343, 65535, 65535, 65535, 65535, 45567, 45261, 

20279, 57343, 65535, 65535, 65535, 65535, 45567, 45261, 

20023, 24319, 32511, 32511, 32511, 32511, 14591, 12493,

 3110, 23662, 15470, 15470, 15470, 15470, 14446, 12364

};

const int dir[16] ={
    8, 1, -8, -1, 9, -7, -9, 7, 17, 10, -6, -15, -17, -10, 6, 15
};

const int key[16] = {
    1, 2, 4, 8, 16, 32, 64, 128,
    256, 512, 1024, 2048, 4096, 8192, 16384, 32768
};

This is constructed so that if the first bit (key[0]) is set, then the relative movement of +8 (dir[0]) is possible; (Showing this in hex would display the relative values better.)

The move generation is six functions each containing about 9 lines each. The bitboard generation is shorter and faster, but harder to implement. Using magic bitboards is even faster, but it's even harder to understand.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.