Skip to content

Commit

Permalink
remove raise
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengfei Chen committed Oct 11, 2023
1 parent 2dcb890 commit b63ba2c
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions unitary/examples/quantum_chinese_chess/chess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit b63ba2c

Please sign in to comment.