0

基本的に私はチェスエンジンを作ろうとしていて、ボードとビットボード表現でコーディングを始めています。しかし、ビットボードを np.uint64 操作のオペランドにして、ビットボードに np.uint64 操作を適用するのに問題があります。これはビットボード クラスです。

import numpy as np
def create_empty_bitboard()->np.uint64:
    return np.uint64(0)
class bitboard:
    def __init__ (self):
        self=create_empty_bitboard()
    def get_bytes_bitboard(self:np.uint64)->str:
        x=bin(self)[2:].zfill(64)
        return x
    def get_squares_from_bb(self)->list:
        squares=[]
        for i,bit in enumerate(reversed(self.get_bytes_bitboard())):
            if int(bit)!=0 :
                squares.append(i)
        return squares

    def create_empty_bitboard(self):
        return np.uint64(0)

    def setBitHot(self, bit:np.uint64 ):
        return np.uint64( (self | (np.uint64(1) << bit)))

    def clearBit(self, bit:int ):
        return self & ~(np.uint64(1) << np.uint64(bit))

jupyterノートブックを使用してバックグラウンドですべてをテストしており、呼び出し時にこれを受け取りました

a=bitboard()
a.get_bytes_bitboard()

'bitboard' オブジェクトは整数として解釈できません

各ピースを別々に実行すると動作します:

a=np.uint64(5)
ch=bin(a)
ch=ch[2:].zfill(64)
int(ch, 2)
a=a<<np.uint64(2)
ch=bin(a)
ch=ch[2:].zfill(64)
b=np.uint64(int(ch, 2))
a==b

True を返します。これを行うより良い方法はありますか?チェス プログラミング wiki を最大限に活用しようとしています。

4

0 に答える 0