Class: ActionRules
- Inherits:
-
Object
- Object
- ActionRules
- Includes:
- Singleton
- Defined in:
- lib/MonkeyEngine/action_rules.rb
Overview
Handles monkey action rules.
Instance Method Summary collapse
-
#action_eval!(action) ⇒ Object
Evaluates an action and sets it to completed if the criteria for completion is met.
-
#get_next_action(monkey) ⇒ MonkeyAction
Retrieves tne next action for the monkey.
- #get_next_action_eval(monkey) ⇒ Object
Instance Method Details
#action_eval!(action) ⇒ Object
Evaluates an action and sets it to completed if the criteria for completion is met.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/MonkeyEngine/action_rules.rb', line 41 def action_eval!(action) raise MonkeyEngine::Exceptions::NilArgumentException.new "The [action] to be evaluated cannot be nil" \ if action.nil? raise MonkeyEngine::Exceptions::InvalidArgumentTypeException.new "The [action] is not the correct type" \ unless action.is_a? Action action_eval_eat(action) if action.is_a?(MonkeyActionEat) action_eval_pause(action) if action.is_a?(MonkeyActionPause) action_eval_sleep(action) if action.is_a?(MonkeyActionSleep) action_eval_type(action) if action.is_a?(MonkeyActionType) action_eval_wake(action) if action.is_a?(MonkeyActionWake) # If we don't specifically handle the action, just let it pass through - Action#action_completed will # be set elsewhere. action.action_completed? end |
#get_next_action(monkey) ⇒ MonkeyAction
Retrieves tne next action for the monkey
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/MonkeyEngine/action_rules.rb', line 15 def get_next_action(monkey) raise MonkeyEngine::Exceptions::InvalidOperationException.new \ "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action" \ unless monkey.action.nil? || monkey.action.action_completed? # current_action = monkey.action # If the monkey is sleeping, or first action, wake him up. return MonkeyActionWake.new(monkey) if monkey.action.nil? || monkey.action.is_a?(MonkeyActionSleep) return get_next_action_eval(monkey) unless nil # Nothing else interesting, monkey takes a breather... # MonkeyActionPause.new(monkey, Random.new.rand(MonkeyActionPause::VALID_VALUES)) MonkeyActionPause.new(monkey, 5) end |
#get_next_action_eval(monkey) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/MonkeyEngine/action_rules.rb', line 32 def get_next_action_eval(monkey) # TODO: Add logic to determine next logical action. keyboard_input = MonkeyEngine::MonkeyKeyboardEnUs.instance.get_keyboard_input return MonkeyActionType.new monkey, keyboard_input end |