diff --git a/src/plugin/action/card.rs b/src/plugin/action/card.rs index 2cd24bb..0000573 100644 --- a/src/plugin/action/card.rs +++ b/src/plugin/action/card.rs @@ -79,7 +79,15 @@ impl Card { // saturating add is here unnecessary because the board is finite and never larger than usize::MAX self.move_to_field(current, state, other.position + 1, remaining_cards)?; } - Card::EatSalad => current.eat_salad(state)?, + Card::EatSalad => { + if current.salads == 0 { + return Err(HUIError::new_err( + "You can only play this card if you have lettuce left", + )); + } + + current.eat_salad(state)? + } Card::SwapCarrots => { if current.position >= PluginConstants::LAST_LETTUCE_POSITION || other.position >= PluginConstants::LAST_LETTUCE_POSITION diff --git a/src/plugin/test/card_test.rs b/src/plugin/test/card_test.rs index e13e6bb..fbd6d06 100644 --- a/src/plugin/test/card_test.rs +++ b/src/plugin/test/card_test.rs @@ -147,4 +147,16 @@ mod tests { let result = invalid_card.perform(&mut state, vec![Card::EatSalad, Card::SwapCarrots]); assert!(result.is_err()); } + + #[test] + fn test_no_salad_but_salad_card() { + let mut state = create_test_game_state(); + let card = Card::EatSalad; + let mut current_player = state.clone_current_player(); + current_player.salads = 0; + current_player.cards = vec![card]; + state.update_player(current_player); + let result = card.perform(&mut state, vec![]); + assert!(result.is_err()); + } }