Class: ScoreComparison
- Inherits:
-
Object
- Object
- ScoreComparison
- Defined in:
- lib/score_comparison.rb
Constant Summary collapse
- MAX_SCORE =
Constant variable for max score and threshold
6
- THRESHOLD =
3
Instance Method Summary collapse
- #calculate_state(mood) ⇒ Object
- #get_mood(score) ⇒ Object
- #get_score ⇒ Object
-
#initialize(player_recipe, customer_recipe) ⇒ ScoreComparison
constructor
A new instance of ScoreComparison.
Constructor Details
#initialize(player_recipe, customer_recipe) ⇒ ScoreComparison
Returns a new instance of ScoreComparison.
10 11 12 13 14 |
# File 'lib/score_comparison.rb', line 10 def initialize(player_recipe, customer_recipe) @player_recipe = player_recipe @customer_recipe = customer_recipe @score = 0 end |
Instance Method Details
#calculate_state(mood) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/score_comparison.rb', line 46 def calculate_state(mood) max_reputation = GameState.max_reputation reputation = GameState.current_reputation payment = GameState::PAYMENT if mood == "happy" GameState.update_money(payment) if reputation < max_reputation GameState.update_reputation(1) end elsif mood == "neutral" GameState.update_money(payment / 2) else GameState.update_reputation(-1) end money = GameState.current_money reputation = GameState.current_reputation return money, reputation end |
#get_mood(score) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/score_comparison.rb', line 29 def get_mood(score) # 6 happy # 3-5 neutral # <2 || >6 angry if (score <= MAX_SCORE) if (score == MAX_SCORE) "happy" elsif (score >= THRESHOLD) "neutral" else "angry" end else "angry" end end |
#get_score ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/score_comparison.rb', line 16 def get_score # Reverse customer recipe (stacked from bottom up) r_customer_recipe = @customer_recipe.dup r_customer_recipe.reverse! # Compare recipe, score +1 for every correct ingredient-quantity (in order) @player_recipe.each_with_index do |line, i| line == r_customer_recipe[i] ? @score += 1 : @score end @score end |