2021年1月1日星期五

I'm trying to reassign elements of a list inside a dictionary, what am I doing wrong?

Trying to make a chess AI. The board is a dictionary with keys a-h, and each key is assigned to an empty list. Essentially this is an 'empty chessboard.'

board['a'][0] = rook(['a', 1], True)

where rook is a class that, in this instance, created a rook with location a1, and true means it's a white piece.

however, my output is such. White pawns and black pawns worked fine, but every single 0 element became that, and if I tried to put a white bishop in a2, all white rooks are replaced with white bishop.

What's wrong?

{'a': [white rook, white pawn, '', '', '', '', black pawn, ''], 'b': [white rook, white pawn, '', '', '', '', black pawn, ''], 'c': [white rook, white pawn, '', '', '', '', black pawn, ''], 'd': [white rook, white pawn, '', '', '', '', black pawn, ''], 'e': [white rook, white pawn, '', '', '', '', black pawn, ''], 'f': [white rook, white pawn, '', '', '', '', black pawn, ''], 'g': [white rook, white pawn, '', '', '', '', black pawn, ''], 'h': [white rook, white pawn, '', '', '', '', black pawn, '']}

https://stackoverflow.com/questions/65535933/im-trying-to-reassign-elements-of-a-list-inside-a-dictionary-what-am-i-doing-w January 02, 2021 at 12:08PM

没有评论:

发表评论