user30006: How do you go about writing an evaluation function for a bitboard bases chess engine? I want to start of simple and only evaluate based on piece value, and where the pieces stand. For example a knight on c3 should give more points than a knight on a3.
I can start with making an array of size 64 for each piece with weights. For example I can store the value 0.1 in the square c3 and -0.1 in the square a3 for the knights. Then I could loop over the 64 squares and check if any of the 12 piece types are in this square and add (or subtract) it from the total evaluation. However it seems like this is very slow.
If I were only counting the piece values then I could use a pop count on each bitboard to get the value, but I don't see how I can implement the square weights this way.
Is there a smarter way to think about this?

user30145: Given there is a maximum of 16 pieces on the chessboard you could loop on the pieces instead of the 64 squares. In this way, the less pieces on the board the faster.
Each piece contains the index of the square, you then only have to pick the value of the corresponding weight to have your score. As each piece could have their own array of weight you can even pre compute the values on the weight adding the piece value and the position.
If the performances really matter, use a profiler to know where is the bottleneck. You might end up using integers instead of floats, pointers instead of indexes, masks for operations and other smart operators to run operations in the same time.

30006: <p>How do you go about writing an evaluation function for a bitboard bases chess engine? I want to start of simple and only evaluate based on piece value, and where the pieces stand. For example a knight on c3 should give more points than a knight on a3.</p>
<p>I can start with making an array of size 64 for each piece with weights. For example I can store the value 0.1 in the square c3 and -0.1 in the square a3 for the knights. Then I could loop over the 64 squares and check if any of the 12 piece types are in this square and add (or subtract) it from the total evaluation. However it seems like this is very slow.</p>
<p>If I were only counting the piece values then I could use a pop count on each bitboard to get the value, but I don't see how I can implement the square weights this way.</p>
<p>Is there a smarter way to think about this?</p>
 30145: <p>Given there is a maximum of 16 pieces on the chessboard you could loop on the pieces instead of the 64 squares. In this way, the less pieces on the board the faster.
Each piece contains the index of the square, you then only have to pick the value of the corresponding weight to have your score. As each piece could have their own array of weight you can even pre compute the values on the weight adding the piece value and the position.
If the performances really matter, use a profiler to know where is the bottleneck. You might end up using integers instead of floats, pointers instead of indexes, masks for operations and other smart operators to run operations in the same time.</p>
