File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,22 @@ impl Card {
34
34
other : & mut Hare ,
35
35
) -> Result < ( ) , PyErr > {
36
36
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
+ }
39
53
Card :: EatSalad => current. eat_salad ( state) ?,
40
54
Card :: SwapCarrots => swap ( & mut current. carrots , & mut other. carrots ) ,
41
55
}
You can’t perform that action at this time.
0 commit comments