diff --git a/src/plugin/rules_engine.rs b/src/plugin/rules_engine.rs index 42e80a8..03d7078 100644 --- a/src/plugin/rules_engine.rs +++ b/src/plugin/rules_engine.rs @@ -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(()), @@ -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(()), } diff --git a/src/plugin/test/rules_test.rs b/src/plugin/test/rules_test.rs index a2acbf3..bd96f39 100644 --- a/src/plugin/test/rules_test.rs +++ b/src/plugin/test/rules_test.rs @@ -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()); } }