From 8c60d051efc393a9d7bdc92bc89bedaac73c2497 Mon Sep 17 00:00:00 2001 From: spla Date: Sat, 21 Nov 2020 19:58:30 +0100 Subject: [PATCH] Added a warning to player in turn when has been captured one of its pieces --- README.md | 1 + mastochess.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/README.md b/README.md index f1ba3f2..c5b0374 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mastochess.py b/mastochess.py index 29ebc51..a969b20 100644 --- a/mastochess.py +++ b/mastochess.py @@ -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: