@@ -9,6 +9,8 @@ use crate::plugin::{
9
9
hare:: Hare ,
10
10
} ;
11
11
12
+ use super :: Action ;
13
+
12
14
#[ pyclass]
13
15
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Hash , Copy ) ]
14
16
pub enum Card {
@@ -51,9 +53,40 @@ impl Card {
51
53
current. move_to_field ( state, other. position + 1 ) ?;
52
54
}
53
55
Card :: EatSalad => current. eat_salad ( state) ?,
54
- Card :: SwapCarrots => swap ( & mut current. carrots , & mut other. carrots ) ,
55
- }
56
+ Card :: SwapCarrots => {
57
+ let last_lettuce_position = state
58
+ . board
59
+ . get_previous_field ( Field :: Salad , state. board . track . len ( ) - 1 )
60
+ . ok_or_else ( || {
61
+ CannotPlayCardError :: new_err (
62
+ "Unable to find the last lettuce field position" ,
63
+ )
64
+ } ) ?;
65
+
66
+ if current. position < last_lettuce_position {
67
+ return Err ( CannotPlayCardError :: new_err (
68
+ "You can only play this card if you are standing in front of the last lettuce field" ,
69
+ ) ) ;
70
+ }
56
71
72
+ if let ( Some ( current_last_move) , Some ( other_last_move) ) =
73
+ ( & current. last_move , & other. last_move )
74
+ {
75
+ if let ( Action :: Advance ( current_advance) , Action :: Advance ( other_advance) ) =
76
+ ( & current_last_move. action , & other_last_move. action )
77
+ {
78
+ if current_advance. cards . contains ( & Card :: SwapCarrots )
79
+ && other_advance. cards . contains ( & Card :: SwapCarrots )
80
+ {
81
+ return Err ( CannotPlayCardError :: new_err (
82
+ "You can only play this card if the last similar swap card was not used in one of the last two turns" ,
83
+ ) ) ;
84
+ }
85
+ }
86
+ }
87
+ swap ( & mut current. carrots , & mut other. carrots ) ;
88
+ }
89
+ }
57
90
Ok ( ( ) )
58
91
}
59
92
0 commit comments