erikbern / deep-pink

Deep Pink is a chess AI that learns to play chess using deep learning.
http://erikbern.com/2014/11/29/deep-learning-for-chess/
813 stars 159 forks source link

bb2array in parse_game.py #14

Open pavel796 opened 7 years ago

pavel796 commented 7 years ago

Hi. I have some problem while using your tool. There was TypeError: 'instancemethod' object is not iterable. I think that is because you use iterating in function b.pieces. How can I fix this problem and why it appears? Is it only my problem?

erikbern commented 7 years ago

sorry no idea, but if you figure out feel free to send over a PR!

brianprichardson commented 7 years ago

I think this is related to Issue #11 By going back to python-chess 0.8.3 it seems to work. In recent versions pieces is no longer iterable in bb2array()

Nick-Pieros commented 7 years ago

I was having the same issue and, assuming my understanding of the original loop is correct, I may have a work around for python-chess 0.9.0 and newer.

This pretty much just walks through the board square by square (0 to 63) and does the calculations when it finds a piece.

`

python-chess 0.9.0 work around

board_pos = 0
# looping through each row 
for row in range(0, 8):
    # looping through each column
    for col in range(0, 8):
        # getting the Piece at the current position
        piece = b.piece_at(board_pos)
        # Checking that there is actually a piece at the current position
        if piece is not None:
            # getting the integer value of the piece (between 1 and 6)
            piece_val = piece.piece_type
            # getting the color of the piece
            color = int(piece.color)
            if flip:
                row = 7 - row
                color = 1 - color

            piece_val = color * 7 + piece_val

            x[row * 8 + col] = piece_val
        board_pos += 1

`

There may be a better/more efficient way to do this, I just wanted to come up with a quick work around. I'm still fairly new to Python so if there's anything that I should fix or improve in that loop let me know!

Edit: Also, as brianpirchanderson pointed out, I believe this should be the same issue as #11