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
4 changes: 2 additions & 2 deletions src/plugin/rules_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl RulesEngine {
if field != Field::Goal && new_position == other_player.position {
return Err(HUIError::new_err("Field is occupied by opponent"));
}

match field {
Field::Hedgehog => Err(HUIError::new_err("Cannot advance on Hedgehog field")),
Field::Salad if player.salads > 0 => Ok(()),
Expand All @@ -115,7 +115,7 @@ impl RulesEngine {
Field::Hare => Err(HUIError::new_err("No card to play")),
Field::Market if player.carrots >= 10 && !cards.is_empty() => Ok(()),
Field::Market => Err(HUIError::new_err("Not enough carrots or no card to play")),
Field::Goal if player.carrots <= 10 && player.salads == 0 => Ok(()),
Field::Goal if player.carrots - RulesEngine::calculates_carrots(distance as usize) <= 10 && player.salads == 0 => Ok(()),
Field::Goal => Err(HUIError::new_err("Too many carrots or salads")),
_ => Ok(()),
}
Expand Down
15 changes: 15 additions & 0 deletions src/plugin/test/rules_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ mod tests {
assert!(RulesEngine::can_move_to(&board, 5, &player_one, &player_two, vec![]).is_err());

player_one.cards = vec![];
player_one.carrots = 60;
assert!(RulesEngine::can_move_to(&board, 6, &player_one, &player_two, vec![]).is_err());

// goal
// too many salads and carrots
assert!(RulesEngine::can_move_to(&board, 8, &player_one, &player_two, vec![]).is_err());
// salads ok, too many carrots
player_one.salads = 0;
assert!(RulesEngine::can_move_to(&board, 8, &player_one, &player_two, vec![]).is_err());
// too many salads, carrots ok
player_one.carrots = 45;
player_one.salads = 3;
assert!(RulesEngine::can_move_to(&board, 8, &player_one, &player_two, vec![]).is_err());
// all ok
player_one.salads = 0;
assert!(RulesEngine::can_move_to(&board, 8, &player_one, &player_two, vec![]).is_ok());
}
}