Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/plugin/action/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/plugin/test/card_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading