예제 #1
0
 def __init__(self, fen=STARTING_FEN):
     super().__init__(fen=fen)
     # Visible state emulates what JHUAPL website shows on its board while playing
     self.visible_state = [BaseBoard(), BaseBoard()]
     self.observation = [
         np.zeros((8, 8, 13), dtype='float32'),
         np.zeros((8, 8, 13), dtype='float32')
     ]
     self.sense_history = [[], []]
예제 #2
0
    def __str__(self):
        def obfusc(char):
            return 'W' if char in ascii_uppercase else \
                   'b' if char in ascii_lowercase else \
                   char

        return ''.join( obfusc(char) for char in BaseBoard.__str__(self) )
예제 #3
0
    def hash_board(self, board: chess.BaseBoard) -> int:
        zobrist_hash = 0

        for pivot, squares in enumerate(board.occupied_co):
            for square in chess.scan_reversed(squares):
                piece_index = (typing.cast(chess.PieceType, board.piece_type_at(square)) - 1) * 2 + pivot
                zobrist_hash ^= self.array[64 * piece_index + square]

        return zobrist_hash
예제 #4
0
 def set_piece_at(self, square, piece):
     '''
     In `BaseBoard`, this method expects a square and a Piece object.
     But for BlindBoards, we only need the second argument to be a color
     (we don't need the piece type).
     '''
     if piece in chess.COLORS:
         piece = Piece(PAWN, piece)
     elif not isinstance(piece, Piece):
         raise ValueError("`%s` is neither a `bool` nor a Piece object"
                          % str(piece))
     return BaseBoard.set_piece_at(self, square, piece)
예제 #5
0
    def generate(board: chess.BaseBoard) -> Image:
        chessboard = Image.open("resources/chessboard.png")

        for y, Y in enumerate(Generator.coordinates):
            for x, X in enumerate(Generator.coordinates):
                piece = board.piece_at(Generator.layout[y][x])

                if piece is not None:
                    path = Generator.path(piece)
                else: continue

                piece = Image.open(path).convert("RGBA")
                
                chessboard.paste(piece, (X, Y), piece)

        return chessboard
예제 #6
0
def calculate_attacking(board: chess.BaseBoard):
    w_builder = []
    b_builder = []
    for square in chess.SQUARES:
        atks = board.attacks_mask(square)
        mask = chess.BB_SQUARES[square]
        color = bool(board.occupied_co[chess.WHITE] & mask)
        if color:
            w_builder.append(atks)
        else:
            b_builder.append(atks)

    w_atk = [0] * 64
    b_atk = [0] * 64
    for square in chess.SQUARES:
        for msk in w_builder:
            w_atk[square] += 1 if msk & chess.BB_SQUARES[square] else 0
        for msk in b_builder:
            b_atk[square] += 1 if msk & chess.BB_SQUARES[square] else 0

    return {'w': w_atk, 'b': b_atk}
예제 #7
0
 def __init__(self, fen=None):
     # create an empty board by default
     # (whereas the default for BaseBoard is a board in starting position)
     BaseBoard.__init__(self, fen)