Skip to content

Commit e49b3d4

Browse files
committed
fix: Improve error handling and logic for hare movement
1 parent c00ef05 commit e49b3d4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/plugin/action/card.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,22 @@ impl Card {
3434
other: &mut Hare,
3535
) -> Result<(), PyErr> {
3636
match self {
37-
Card::FallBack => current.move_to_field(state, other.position - 1)?,
38-
Card::HurryAhead => current.move_to_field(state, other.position + 1)?,
37+
Card::FallBack => {
38+
if current.position < other.position {
39+
return Err(CannotPlayCardError::new_err(
40+
"You can only play this card if you are ahead of the other player",
41+
));
42+
}
43+
current.move_to_field(state, other.position - 1)?;
44+
}
45+
Card::HurryAhead => {
46+
if current.position > other.position {
47+
return Err(CannotPlayCardError::new_err(
48+
"You can only play this card if you are behind the other player",
49+
));
50+
}
51+
current.move_to_field(state, other.position + 1)?;
52+
}
3953
Card::EatSalad => current.eat_salad(state)?,
4054
Card::SwapCarrots => swap(&mut current.carrots, &mut other.carrots),
4155
}

0 commit comments

Comments
 (0)