Class: ActionRules

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/MonkeyEngine/action_rules.rb

Overview

Handles monkey action rules.

Instance Method Summary collapse

Instance Method Details

#action_eval!(action) ⇒ Object

Evaluates an action and sets it to completed if the criteria for completion is met.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/MonkeyEngine/action_rules.rb', line 44

def action_eval!(action)
  raise MonkeyEngine::Exceptions::NilArgumentException, 'The [action] to be evaluated cannot be nil' \
      if action.nil?

  raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, '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

Parameters:

  • the (monkey)

    monkey whose next action is to be retrieved

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/MonkeyEngine/action_rules.rb', line 17

def get_next_action(monkey)
  unless monkey.action.nil? || monkey.action.action_completed?
    raise MonkeyEngine::Exceptions::InvalidOperationException,
      "The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action"
  end

  # 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



35
36
37
38
39
40
41
# File 'lib/MonkeyEngine/action_rules.rb', line 35

def get_next_action_eval(monkey)
  # TODO: Add logic to determine next logical action.

  keyboard_input = MonkeyEngine::MonkeyKeyboardEnUs.instance.get_keyboard_input

  MonkeyActionType.new monkey, keyboard_input
end