How to generate a mask for knight?

时间:2018-02-03 09:32:41

标签: chess

I'm using bitboards to implement a chess program. My question is basically when I move a knight, it's mask has to be modified to get the legal moves. Is there an elegant way for it, I was thinking about shifting bits but that seems to be a bad way.

1 个答案:

答案 0 :(得分:1)

由于棋盘上只有64个方格,你可以简单地预先计算所有骑士的动作。在搜索本身中,您可以通过一次表查找找到骑士的攻击。<​​/ p>

表本身只需要512个字节(64 * 8个字节)。

最初填写表格并不是时间关键,因此算法的选择并不重要,只要它提供正确的正方形。