From b63ba2c3686c1d209aec940f19af0eb9101c53b4 Mon Sep 17 00:00:00 2001 From: Pengfei Chen Date: Wed, 11 Oct 2023 14:18:15 -0700 Subject: [PATCH] remove raise --- .../examples/quantum_chinese_chess/chess.py | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/unitary/examples/quantum_chinese_chess/chess.py b/unitary/examples/quantum_chinese_chess/chess.py index 78f35797..991cd8a8 100644 --- a/unitary/examples/quantum_chinese_chess/chess.py +++ b/unitary/examples/quantum_chinese_chess/chess.py @@ -295,10 +295,7 @@ def classify_move( def apply_move(self, str_to_parse: str) -> None: """Check if the input string is valid. If it is, determine the move type and variant and return the move.""" - try: - sources, targets = self.parse_input_string(str_to_parse) - except ValueError as e: - raise e + sources, targets = self.parse_input_string(str_to_parse) # Additional checks based on the current board. for source in sources: @@ -324,10 +321,7 @@ def apply_move(self, str_to_parse: str) -> None: classical_pieces_0, quantum_pieces_0 = self.board.path_pieces( sources[0], targets[0] ) - try: - self.check_classical_rule(sources[0], targets[0], classical_pieces_0) - except ValueError as e: - raise e + self.check_classical_rule(sources[0], targets[0], classical_pieces_0) # Check if the second path (if exists) satisfies the classical rule. classical_pieces_1 = None @@ -337,30 +331,21 @@ def apply_move(self, str_to_parse: str) -> None: classical_pieces_1, quantum_pieces_1 = self.board.path_pieces( sources[1], targets[0] ) - try: - self.check_classical_rule(sources[1], targets[0], classical_pieces_1) - except ValueError as e: - raise e + self.check_classical_rule(sources[1], targets[0], classical_pieces_1) elif len(targets) == 2: classical_pieces_1, quantum_pieces_1 = self.board.path_pieces( sources[0], targets[1] ) - try: - self.check_classical_rule(sources[0], targets[1], classical_pieces_1) - except ValueError as e: - raise e + self.check_classical_rule(sources[0], targets[1], classical_pieces_1) # Classify the move type and move variant. - try: - move_type, move_variant = self.classify_move( - sources, - targets, - classical_pieces_0, - quantum_pieces_0, - classical_pieces_1, - quantum_pieces_1, - ) - except ValueError as e: - raise e + move_type, move_variant = self.classify_move( + sources, + targets, + classical_pieces_0, + quantum_pieces_0, + classical_pieces_1, + quantum_pieces_1, + ) if move_type == MoveType.CLASSICAL: if source_0.type_ == Type.KING: