forked from BNwike47/cs257
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchess_util.py
35 lines (24 loc) · 1.13 KB
/
chess_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def capturing_piece_type(board, move):
"""Returns a character symbol representing the piece type of
of the capturer on this move, or None if there is no capturer.
Uppercase signifies white piece, lowercase signifies black."""
capturing_piece_type = None
if board.is_capture(move):
source_square = move.from_square
capturing_piece_type = board.piece_at(source_square).symbol()
return capturing_piece_type
def captured_piece_type(board, move):
"""Returns a character symbol representing the piece type of
of the captured piece this move, or None if no piece was captured.
Uppercase signifies white piece, lowercase signifies black."""
captured_piece_type = None
if board.is_capture(move):
target_square = move.to_square
if board.is_en_passant(move):
# Ensure that target square points to the position of the captured piece
if target_square < 32:
target_square += 8
else:
target_square -= 8
captured_piece_type = board.piece_at(target_square).symbol()
return captured_piece_type