我想把UCI-move转换成bitboard。
例如a2a3 -> 32768、8388608
我需要将7,6,...,0赋给a,b,...,h,这样对于每个字母,我都有一个分配的数字(N)来计算2^n
然后,我可以根据开始字段或结束字段按uci1或uci3 *8中的值向左移位。
这是我的方法,它看起来不是很好,也不是多余的。
def ucitoBit(uci):
if uci[0] == 'a':
mask1 = 2 ** 7
if uci[0] == 'b':
mask1 = 2 ** 6
if uci[0] == 'c':
mask1 = 2 ** 5
if uci[0] == 'd':
mask1 = 2 ** 4
if uci[0] == 'e':
mask1 = 2 ** 3
if uci[0] == 'f':
mask1 = 2 ** 2
if uci[0] == 'g':
mask1 = 2 ** 1
if uci[0] == 'h':
mask1 = 2 ** 0
mask1 = mask1 << 8 * (int(uci[1]) - 1)
if uci[2] == 'a':
mask2 = 2 ** 7
if uci[2] == 'b':
mask2 = 2 ** 6
if uci[2] == 'c':
mask2 = 2 ** 5
if uci[2] == 'd':
mask2 = 2 ** 4
if uci[2] == 'e':
mask2 = 2 ** 3
if uci[2] == 'f':
mask2 = 2 ** 2
if uci[2] == 'g':
mask2 = 2 ** 1
if uci[2] == 'h':
mask2 = 2 ** 0
mask2 = mask2 << 8 * (int(uci[3]) - 1)
bitstring = [np.uint64(mask1), np.uint64(mask2)]
return bitstring发布于 2020-10-11 03:59:30
如何定义包含rows和cols索引的两个数组,并像这样使用它们:
rows = ["1", "2", "3", "4", "5", "6", "7", "8"]
cols = ["a", "b", "c", "d", "e", "f", "g", "h"]
def parse_move(move):
from_col, from_row, to_col, to_row = list(move)
from_sq = 2**((7 - cols.index(from_col)) + 8*rows.index(from_row))
to_sq = 2**((7 - cols.index(to_col)) + 8*rows.index(to_row))
return [from_sq, to_sq]https://stackoverflow.com/questions/63306177
复制相似问题