user26064: If I have a bitboard (e.g. for knight squares he can move to) like this:
00000000
00000000
00000000
00000000
00000000
01000000
00100000
N0000000

How can I "convert" it into a move or "apply" that move?

user-1: There are actually two questions in your post

How to convert Attacks in Bitboards to a list of moves?

How to represent those moves?





How to represent those moves?


This question has been discussed here and here thoroughly. But to provide some context to the readers of this post, a very simple way to do this can be to use a class / struct to represent a move

From ( where the moving piece was )
To   ( where the moving piece will be )
Special Move Flag  ( whether the move was a special move, i.e enpassant, casting, promotion)
Promoted Piece ( if the move was a promotion move, what piece did it promote to )

You can also have extra attributes such as captured piece, type of castle etc. But that information can also be deduced using the From and To squares.
So considering the above, we can represent the move as follows
struct Move {
    char from; 
    char to;   
    char spMoveFlag;
    char promotedPiece;
};

However, a lot of chess engines, including mine use another method that can compress the move into just 16 bits. Read more about that here.
Once we know what a move is, we can answer the next question



How to convert Attacks in Bitboards to a list of moves?


Let's consider that we have a knight on the square d4. We also have a function that returns the attacks of a knight given the square.
. . . . . . . . 
. . . . . . . . 
. . 1 . 1 . . . 
. 1 . . . 1 . . 
. . . n . . . .   =  knightattacks(SQ_D4)
. 1 . . . 1 . . 
. . 1 . 1 . . . 
. . . . . . . . 

So let's store this inside a variable knightAttacks
uint64_t knightAttacks = getKnightAttacksBB(SQ_D4);

If you notice carefully we already have 1 of the 4 attributes we need to represent the move, which is the From square - D4. Now all we need to do is somehow get the To square to complete this since a knight cannot perform any kind of special moves.
A very common method is to pop the least significant bit until your knightAttacks is left with nothing i.e 0.
0000011100001000 
            ^
            Least significant bit (lsb)

You can follow the link I provided to know how you can perform this, or there is a chance that your compiler might already provide you with it.
You simply need to create a function that clears the lsb of a bitboard and returns its index. Let's call it poplsb().
Altogether, your code can look like this
int from = SQ_D4;
uint16_t knightAttacks = getknightAttacks(from);

while (knightAttacks)  {
     int to = poplsb(knightAttacks);
     MyMoveList.Add( NewMove(from, to, 0, 0) ); // The last two 0's denote that there is no special move
}


This works because each time you pop the lsb, a bit gets cleared until the number is == 0. That's when the loop stops and you have a perfectly good list of moves. The same idea applies to any kind of moves you have created using Bitboards.

26064: <p>If I have a bitboard (e.g. for knight squares he can move to) like this:</p>
<pre><code>00000000
00000000
00000000
00000000
00000000
01000000
00100000
N0000000
</code></pre>
<p>How can I &quot;convert&quot; it into a move or &quot;apply&quot; that move?</p>
 -1: <p>There are actually two questions in your post</p>
<ul>
<li><p><strong>How to convert Attacks in Bitboards to a list of moves?</strong></p>
</li>
<li><p><strong>How to represent those moves?</strong></p>
</li>
</ul>
<hr />
<blockquote>
<ul>
<li><strong>How to represent those moves?</strong></li>
</ul>
</blockquote>
<p>This question has been discussed <a href="https://chess.stackexchange.com/questions/9706/representing-moves-found-via-bitboards-applying-them-and-removing-them">here</a> and <a href="https://chess.stackexchange.com/questions/18017/whats-the-right-approach-of-storing-moves-generated-using-bitboards">here</a> thoroughly. But to provide some context to the readers of this post, a very simple way to do this can be to use a class / struct to represent a move</p>
<ul>
<li><strong>From</strong> ( where the moving piece was )</li>
<li><strong>To</strong>   ( where the moving piece will be )</li>
<li><strong>Special Move Flag</strong>  ( whether the move was a special move, i.e enpassant, casting, promotion)</li>
<li><strong>Promoted Piece</strong> ( if the move was a promotion move, what piece did it promote to )</li>
</ul>
<p>You can also have extra attributes such as captured piece, type of castle etc. But that information can also be deduced using the <code>From</code> and <code>To</code> squares.</p>
<p>So considering the above, we can represent the move as follows</p>
<pre><code>struct Move {
    char from; 
    char to;   
    char spMoveFlag;
    char promotedPiece;
};
</code></pre>
<p>However, a lot of chess engines, including mine use another method that can compress the move into just <code>16</code> bits. Read more about that <a href="https://chess.stackexchange.com/questions/18017/whats-the-right-approach-of-storing-moves-generated-using-bitboards">here</a>.</p>
<p>Once we know what a move is, we can answer the next question</p>
<hr />
<blockquote>
<ul>
<li><strong>How to convert Attacks in Bitboards to a list of moves?</strong></li>
</ul>
</blockquote>
<p>Let's consider that we have a <strong>knight</strong> on the square <strong>d4</strong>. We also have a function that returns the attacks of a knight given the square.</p>
<pre><code>. . . . . . . . 
. . . . . . . . 
. . 1 . 1 . . . 
. 1 . . . 1 . . 
. . . n . . . .   =  knightattacks(SQ_D4)
. 1 . . . 1 . . 
. . 1 . 1 . . . 
. . . . . . . . 
</code></pre>
<p>So let's store this inside a variable <code>knightAttacks</code></p>
<pre><code>uint64_t knightAttacks = getKnightAttacksBB(SQ_D4);
</code></pre>
<p>If you notice carefully we already have 1 of the 4 attributes we need to represent the move, which is the <code>From</code> square - <code>D4</code>. Now all we need to do is somehow get the <code>To</code> square to complete this since a knight cannot perform any kind of special moves.</p>
<p>A very common method is to <a href="https://stackoverflow.com/questions/757059/position-of-least-significant-bit-that-is-set">pop the least significant bit</a> until your <code>knightAttacks</code> is left with nothing i.e <code>0</code>.</p>
<pre><code>0000011100001000 
            ^
            Least significant bit (lsb)
</code></pre>
<p>You can follow the link I provided to know how you can perform this, or there is a chance that <a href="https://en.wikipedia.org/wiki/Intrinsic_function" rel="nofollow noreferrer">your compiler might already provide you with it.</a></p>
<p>You simply need to create a function that clears the lsb of a bitboard and returns its index. Let's call it <code>poplsb()</code>.</p>
<p>Altogether, your code can look like this</p>
<pre><code>int from = SQ_D4;
uint16_t knightAttacks = getknightAttacks(from);

while (knightAttacks)  {
     int to = poplsb(knightAttacks);
     MyMoveList.Add( NewMove(from, to, 0, 0) ); // The last two 0's denote that there is no special move
}

</code></pre>
<p>This works because each time you pop the lsb, a bit gets cleared until the number is == 0. That's when the loop stops and you have a perfectly good list of moves. The same idea applies to any kind of moves you have created using Bitboards.</p>
