niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.4k stars 521 forks source link

Is there a way to keep id of pieces between moves ? #560

Closed mathbeal closed 4 years ago

mathbeal commented 4 years ago
board = chess.Board()

def diff_board(move):
    before_dict = dict(board.piece_map())
    board.push(move)
    after_dict = dict(board.piece_map())
    before_set= set(map(id, before_dict.values()))
    after_set = set(map(id, after_dict.values()))
    # check differences in piece_map
    print(after_set & before_set)
    print(after_set - before_set)
    print(before_set - after_set)

Nf3 = chess.Move.from_uci("g1f3")
diff_board(Nf3)

set()

{2649374433408, 2649374434304, 2649374433800, 2649374406136, 2649374406416, 2649374434192, 2649374434584, 2649374433688, 2649374405912, 2649374406304, 2649374434080, 2649374433576, 2649374434472, 2649374406192, 2649374433968, 2649374434360, 2649374433464, 2649374406080, 2649374433856, 2649374433352, 2649374434248, 2649374405968, 2649374433744, 2649374406360, 2649374434136, 2649374433632, 2649374434528, 2649374406248, 2649374434024, 2649374433520, 2649374434416, 2649374433912}

{2649374407424, 2649374406920, 2649374407816, 2649374407312, 2649374408208, 2649374407704, 2649374406808, 2649374408096, 2649374407200, 2649374407592, 2649374406696, 2649374407984, 2649374407088, 2649374407480, 2649374406584, 2649374407872, 2649374406976, 2649374407928, 2649374408264, 2649374407368, 2649374407760, 2649374406864, 2649374407256, 2649374408152, 2649374407648, 2649374406752, 2649374408040, 2649374407144, 2649374405744, 2649374407536, 2649374406640, 2649374407032}

Is there a way to track moves of a pieces along a game ?

niklasf commented 4 years ago

Hi, unfortunately the underlying board representation (bitboards) does not allow tracking the identity of pieces.