user10914: I have read a lot of stuff about magic bitboard but some stuff is not clear. A lot of authors say to create the move masks for the piece avoiding the border positions. So, for a bishop at D3 the move mask would be this:
00000000
00000000
00000010
01000100
00101000
00000000
00101000
00000000

instead of this
00000000
00000001
00000010
01000100
00101000
00000000
00101000
01000100

They say this is good for convenience. I don't see how, but anyway, lets bear with this idea.
The problem is that, if we will avoid the border are, how will the move map for a hook at A1 be? All zeros? The hook at A1 will be like this:
10000000
10000000
10000000
10000000
10000000
10000000
10000000
11111111

but if we cannot have the numbers at the border it will be all zeros.
Is there another reason for that "avoid the border" rule? Is that OK if I forget that rule and make it to the border?

user1508: It's not about avoiding the border. It's about avoiding the last bit of the ray.
Given this:
10000000
10000000
10000000
10000000
10000000
10000000
10000000
01111111

(Note that A1 should be zero as the rook is unimportant)
You will note that along the first rank, if there is no piece on G1, then a rook can attack H1, regardless of what is on that square. This also applies along the A-file, where if there is no piece on A7, then A8 can always be attacked.
Because of this, we mask out the last bit of the ray, as we do not need to know what's at the end of the ray, producing this mask:
00000000
10000000
10000000
10000000
10000000
10000000
10000000
01111110

This produces a significant table reduction, as you need only 12 bits of occupancy to index the table, not 14.

10914: <p>I have read a lot of stuff about magic bitboard but some stuff is not clear. A lot of authors say to create the move masks for the piece avoiding the border positions. So, for a bishop at <code>D3</code> the move mask would be this:</p>

<pre><code>00000000
00000000
00000010
01000100
00101000
00000000
00101000
00000000
</code></pre>

<p>instead of this</p>

<pre><code>00000000
00000001
00000010
01000100
00101000
00000000
00101000
01000100
</code></pre>

<p>They say this is good for convenience. I don't see how, but anyway, lets bear with this idea.</p>

<p>The problem is that, if we will avoid the border are, how will the move map for a hook at <code>A1</code> be? All zeros? The hook at <code>A1</code> will be like this:</p>

<pre><code>10000000
10000000
10000000
10000000
10000000
10000000
10000000
11111111
</code></pre>

<p>but if we cannot have the numbers at the border it will be all zeros.</p>

<p>Is there another reason for that "avoid the border" rule? Is that OK if I forget that rule and make it to the border?</p>
 1508: <p>It's not about avoiding the border. It's about avoiding the last bit of the ray.</p>

<p>Given this:</p>

<pre><code>10000000
10000000
10000000
10000000
10000000
10000000
10000000
01111111
</code></pre>

<p>(Note that A1 should be zero as the rook is unimportant)</p>

<p>You will note that along the first rank, if there is no piece on G1, then a rook can attack H1, regardless of what is on that square. This also applies along the A-file, where if there is no piece on A7, then A8 can always be attacked.</p>

<p>Because of this, we mask out the last bit of the ray, as we do not need to know what's at the end of the ray, producing this mask:</p>

<pre><code>00000000
10000000
10000000
10000000
10000000
10000000
10000000
01111110
</code></pre>

<p>This produces a significant table reduction, as you need only 12 bits of occupancy to index the table, not 14.</p>
