Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T04:08:42.207Z
Answers.Text: ok thanks for the explanation but what I do not understand is this. Suppose there is a piece at H1 and I am trying to discover if the hook is attacking that. If that H1 bit is zero how do I will ever discover that?
Answers.UserDisplayName: Duck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T14:42:48.880Z
Answers.Text: Because the attack table that the magics index will have the bit set as needed. Remember that the mask and the attack table are different things.
Answers.UserDisplayName: ZirconiumX
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T14:47:00.180Z
Answers.Text: Perhaps you should try to use something other than magics for your program. Perhaps you could try [Obstruction Difference](http://chessprogramming.wikispaces.com/Obstruction+Difference) instead?
Answers.UserDisplayName: ZirconiumX
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T15:50:42.240Z
Answers.Text: I don't know. I have read a lot of stuff but nobody explains what is really needed to make this work. Many people try but their explanations derail after the the third paragraph. From that point on, it is impossible to understand what they are talking about. Magic index for example: they say is an index that converts one stuff into another... example that one can understand? nope.
Answers.UserDisplayName: Duck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T18:34:26.383Z
Answers.Text: It's called a magic number for a reason. Have you read the CPW article on it? That tends to help. Also have a look at kindergarten bitboards, which were what magic bitboards were derived from.
Answers.UserDisplayName: ZirconiumX
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T18:35:47.420Z
Answers.Text: Also, sign up for an account at the [computer chess club](talkchess.com), which is a lot more focused than chess.SE.
Answers.UserDisplayName: ZirconiumX
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-01T19:23:38.357Z
Answers.LastActivityDate: 2016-08-01T19:23:38.357Z
Answers.UserDisplayName: ZirconiumX
Body: <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>
  
Tags: <software><bitboard>
Title: Understanding magic bitboard
ThreadText: # Understanding magic bitboard
  
  (Asked by: username_0 on 2016-08-01)
  
  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?
  
  **Tags:** software, bitboard
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-01. Score: 3
  
  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.
  
  > **Comments:**
  > **username_0**: ok thanks for the explanation but what I do not understand is this. Suppose there is a piece at H1 and I am trying to discover if the hook is attacking that. If that H1 bit is zero how do I will ever discover that?  
  > **username_1**: Because the attack table that the magics index will have the bit set as needed. Remember that the mask and the attack table are different things.  
  > **username_1**: Perhaps you should try to use something other than magics for your program. Perhaps you could try [Obstruction Difference](http://chessprogramming.wikispaces.com/Obstruction+Difference) instead?  
  > **username_0**: I don't know. I have read a lot of stuff but nobody explains what is really needed to make this work. Many people try but their explanations derail after the the third paragraph. From that point on, it is impossible to understand what they are talking about. Magic index for example: they say is an index that converts one stuff into another... example that one can understand? nope.  
  > **username_1**: It's called a magic number for a reason. Have you read the CPW article on it? That tends to help. Also have a look at kindergarten bitboards, which were what magic bitboards were derived from.  
  > **username_1**: Also, sign up for an account at the [computer chess club](talkchess.com), which is a lot more focused than chess.SE.  
  
  ---
  
  