Added a warning to player in turn when has been captured one of its pieces

This commit is contained in:
spla 2020-11-21 19:58:30 +01:00
pare 4053a73ad4
commit 8c60d051ef
S'han modificat 2 arxius amb 47 adicions i 0 eliminacions

Veure arxiu

@ -42,3 +42,4 @@ Within Python Virtual Environment:
![board](board.png)
20.11.2020 - New feature! added link to on going games in games list
21.11.2020 - New feature! Added a warning to player in turn when has been captured one of its pieces

Veure arxiu

@ -89,6 +89,34 @@ def get_user_domain(account_id):
conn.close()
def get_piece_name(captured_piece):
if captured_piece == 1:
piece_name = "un Peó"
if captured_piece == 2:
piece_name = "un cavall"
if captured_piece == 3:
piece_name = "l'àlfil"
if captured_piece == 4:
piece_name = "una torre"
if captured_piece == 5:
piece_name = "la Reina"
if captured_piece == 6:
piece_name = "el Rei"
return piece_name
def get_notification_data():
try:
@ -1011,6 +1039,20 @@ if __name__ == '__main__':
playing_user = next_move(username)
if bool(board.is_capture(chess.Move.from_uci(moving))):
capture = True
square_capture_index = chess.SQUARE_NAMES.index(moving[2:])
captured_piece = board.piece_type_at(square_capture_index)
piece_name = get_piece_name(captured_piece)
else:
capture = False
board.push(chess.Move.from_uci(moving))
if board.is_check() == True:
@ -1051,6 +1093,10 @@ if __name__ == '__main__':
toot_text = "@"+playing_user + ' el teu torn.'+ '\n'
if capture:
toot_text += "\n* has perdut " + piece_name + "!\n"
toot_text += '\n#escacs' + '\n'
if username == white_user: