@@ -3,11 +3,7 @@ use std::mem::swap;
33use pyo3:: * ;
44
55use crate :: plugin:: {
6- errors:: { CannotEnterFieldError , CannotPlayCardError , CardNotOwnedError } ,
7- field:: Field ,
8- game_state:: GameState ,
9- hare:: Hare ,
10- rules_engine:: RulesEngine ,
6+ errors:: HUIError , field:: Field , game_state:: GameState , hare:: Hare , rules_engine:: RulesEngine ,
117} ;
128
139use super :: Action ;
@@ -37,10 +33,8 @@ impl Card {
3733 target_position : usize ,
3834 cards : Vec < Card > ,
3935 ) -> Result < ( ) , PyErr > {
40- println ! ( "target_position: {}" , target_position) ;
41- println ! ( "player.position: {}" , player. position) ;
4236 let distance = target_position as isize - player. position as isize ;
43- RulesEngine :: can_advance_to (
37+ RulesEngine :: can_move_to (
4438 & state. board ,
4539 distance,
4640 player,
@@ -64,7 +58,7 @@ impl Card {
6458 match self {
6559 Card :: FallBack => {
6660 if current. position < other. position {
67- return Err ( CannotPlayCardError :: new_err (
61+ return Err ( HUIError :: new_err (
6862 "You can only play this card if you are ahead of the other player" ,
6963 ) ) ;
7064 }
@@ -77,7 +71,7 @@ impl Card {
7771 }
7872 Card :: HurryAhead => {
7973 if current. position > other. position {
80- return Err ( CannotPlayCardError :: new_err (
74+ return Err ( HUIError :: new_err (
8175 "You can only play this card if you are behind the other player" ,
8276 ) ) ;
8377 }
@@ -90,14 +84,14 @@ impl Card {
9084 . board
9185 . get_previous_field ( Field :: Salad , state. board . track . len ( ) - 1 )
9286 . ok_or_else ( || {
93- CannotPlayCardError :: new_err (
94- "Unable to find the last lettuce field position" ,
95- )
87+ HUIError :: new_err ( "Unable to find the last lettuce field position" )
9688 } ) ?;
9789
98- if current. position < last_lettuce_position {
99- return Err ( CannotPlayCardError :: new_err (
100- "You can only play this card if you are standing in front of the last lettuce field" ,
90+ if current. position > last_lettuce_position
91+ || other. position > last_lettuce_position
92+ {
93+ return Err ( HUIError :: new_err (
94+ "You can only play this card if both players haven't passed the last lettuce field" ,
10195 ) ) ;
10296 }
10397
@@ -108,9 +102,9 @@ impl Card {
108102 ( & current_last_move. action , & other_last_move. action )
109103 {
110104 if current_advance. cards . contains ( & Card :: SwapCarrots )
111- && other_advance. cards . contains ( & Card :: SwapCarrots )
105+ || other_advance. cards . contains ( & Card :: SwapCarrots )
112106 {
113- return Err ( CannotPlayCardError :: new_err (
107+ return Err ( HUIError :: new_err (
114108 "You can only play this card if the last similar swap card was not used in one of the last two turns" ,
115109 ) ) ;
116110 }
@@ -129,10 +123,10 @@ impl Card {
129123 let field = state
130124 . board
131125 . get_field ( current. position )
132- . ok_or_else ( || CannotEnterFieldError :: new_err ( "Field not found" ) ) ?;
126+ . ok_or_else ( || HUIError :: new_err ( "Field not found" ) ) ?;
133127
134128 if field != Field :: Hare {
135- return Err ( CannotPlayCardError :: new_err (
129+ return Err ( HUIError :: new_err (
136130 "You can only play cards on the hare field" ,
137131 ) ) ;
138132 }
@@ -141,7 +135,7 @@ impl Card {
141135 . cards
142136 . iter ( )
143137 . position ( |card| card == self )
144- . ok_or_else ( || CardNotOwnedError :: new_err ( "Card not owned" ) ) ?;
138+ . ok_or_else ( || HUIError :: new_err ( "Card not owned" ) ) ?;
145139
146140 self . play ( state, & mut current, & mut other, remaining_cards) ?;
147141
0 commit comments