MonkeyEngine 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +19 -16
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +71 -0
- data/Rakefile +3 -2
- data/dictionaries/en-US.txt +466554 -0
- data/lib/Action/action.rb +5 -4
- data/lib/Monkey/monkey.rb +17 -12
- data/lib/Monkey.rb +3 -1
- data/lib/MonkeyAction/monkey_action.rb +3 -1
- data/lib/MonkeyAction/monkey_action_dead.rb +8 -6
- data/lib/MonkeyAction/monkey_action_eat.rb +6 -4
- data/lib/MonkeyAction/monkey_action_pause.rb +6 -5
- data/lib/MonkeyAction/monkey_action_sleep.rb +6 -4
- data/lib/MonkeyAction/monkey_action_type.rb +15 -10
- data/lib/MonkeyAction/monkey_action_wake.rb +8 -6
- data/lib/MonkeyAction/monkey_timed_action.rb +6 -4
- data/lib/MonkeyActions.rb +2 -0
- data/lib/MonkeyEngine/action_rules.rb +20 -18
- data/lib/MonkeyEngine/exceptions.rb +7 -7
- data/lib/MonkeyEngine/monkey_engine.rb +13 -10
- data/lib/MonkeyEngine/version.rb +3 -1
- data/lib/MonkeyEngine.rb +3 -1
- data/lib/MonkeyFactory/monkey_factory.rb +3 -4
- data/lib/MonkeyFactory.rb +3 -1
- data/lib/MonkeyKeyboard/keyboard_char.rb +3 -2
- data/lib/MonkeyKeyboard/keyboard_input.rb +4 -3
- data/lib/MonkeyKeyboard/keyboard_key.rb +3 -1
- data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +5 -7
- data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +100 -80
- data/lib/MonkeyKeyboardEnUs.rb +3 -1
- data/lib/MonkeyManager/monkey_manager.rb +13 -11
- data/lib/MonkeyManager.rb +3 -1
- data/lib/MonkeyService/monkey_service.rb +8 -9
- data/lib/MonkeyService.rb +3 -1
- data/lib/tasks/engine.rb +57 -52
- data/monkeyengine.gemspec +22 -20
- data/spec/action_rules_spec.rb +9 -9
- data/spec/engine_spec.rb +5 -10
- data/spec/keyboard_char_spec.rb +3 -4
- data/spec/keyboard_key_spec.rb +3 -4
- data/spec/monkey_action_eat_spec.rb +14 -15
- data/spec/monkey_action_pause_spec.rb +15 -16
- data/spec/monkey_action_sleep_spec.rb +15 -16
- data/spec/monkey_action_type_spec.rb +22 -21
- data/spec/monkey_action_wake_spec.rb +6 -7
- data/spec/monkey_factory_spec.rb +5 -5
- data/spec/monkey_keyboard_en_us_spec.rb +8 -14
- data/spec/monkey_manager_spec.rb +2 -1
- data/spec/monkey_service_spec.rb +15 -18
- data/spec/monkey_spec.rb +2 -1
- data/spec/{spec_helpers.rb → spec_helper.rb} +6 -4
- data/spec/support/shared_examples.rb +12 -12
- metadata +67 -54
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/MonkeyEngine.iml +0 -133
- data/.idea/codeStyleSettings.xml +0 -13
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/runConfigurations/All_specs_in_test__MonkeyEngine.xml +0 -38
- data/.idea/runConfigurations/IRB_console.xml +0 -25
- data/.idea/runConfigurations/Start_Yard_Server.xml +0 -26
- data/.idea/runConfigurations/monkey_run.xml +0 -26
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -886
data/lib/Action/action.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
# Defines a base action.
|
@@ -18,12 +20,11 @@ class Action
|
|
18
20
|
@action_completed
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
@action_completed = value
|
23
|
-
end
|
23
|
+
attr_writer :action_completed
|
24
24
|
|
25
25
|
protected
|
26
|
+
|
26
27
|
def validate
|
27
28
|
# throw if invalid state
|
28
29
|
end
|
29
|
-
end
|
30
|
+
end
|
data/lib/Monkey/monkey.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'MonkeyActions'
|
4
4
|
require 'MonkeyService'
|
@@ -27,6 +27,7 @@ class Monkey
|
|
27
27
|
attr_reader :monkey_symbol, :action
|
28
28
|
|
29
29
|
protected
|
30
|
+
|
30
31
|
def initialize(monkey_symbol)
|
31
32
|
@monkey_symbol = monkey_symbol
|
32
33
|
@monkey_service = MonkeyEngine::MonkeyService.instance
|
@@ -43,6 +44,7 @@ class Monkey
|
|
43
44
|
#
|
44
45
|
def alive?
|
45
46
|
return false if @thread.nil?
|
47
|
+
|
46
48
|
@thread.alive?
|
47
49
|
end
|
48
50
|
|
@@ -52,6 +54,7 @@ class Monkey
|
|
52
54
|
#
|
53
55
|
def current_action
|
54
56
|
return MonkeyActionDead.new(self) unless alive?
|
57
|
+
|
55
58
|
@action
|
56
59
|
end
|
57
60
|
|
@@ -71,8 +74,11 @@ class Monkey
|
|
71
74
|
# @return [Monkey, self]
|
72
75
|
#
|
73
76
|
def start
|
74
|
-
|
75
|
-
|
77
|
+
if alive?
|
78
|
+
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
79
|
+
"The monkey [#{@monkey_symbol}] thread is already started"
|
80
|
+
end
|
81
|
+
|
76
82
|
initialize_thread
|
77
83
|
self
|
78
84
|
end
|
@@ -81,28 +87,27 @@ class Monkey
|
|
81
87
|
#
|
82
88
|
# @return [Thread]
|
83
89
|
#
|
84
|
-
|
85
|
-
@thread
|
86
|
-
end
|
90
|
+
attr_reader :thread
|
87
91
|
|
88
92
|
protected
|
93
|
+
|
89
94
|
def initialize_thread
|
90
|
-
@sleep_time = 1.0/250.0
|
95
|
+
@sleep_time = 1.0 / 250.0
|
91
96
|
@kill_thread = false
|
92
97
|
|
93
|
-
@thread = Thread.new
|
98
|
+
@thread = Thread.new do
|
94
99
|
monkey_do
|
95
|
-
|
100
|
+
end
|
96
101
|
|
97
|
-
|
102
|
+
# @thread.freeze
|
98
103
|
@thread.abort_on_exception = true
|
99
104
|
end
|
100
105
|
|
101
106
|
def monkey_do
|
102
|
-
until @kill_thread
|
107
|
+
until @kill_thread
|
103
108
|
@action = @monkey_service.new_action(self) if @action.nil? || @action.action_completed?
|
104
109
|
@monkey_service.monkey_do @action unless @monkey_service.action_eval! @action
|
105
110
|
sleep(@sleep_time)
|
106
111
|
end
|
107
112
|
end
|
108
|
-
end
|
113
|
+
end
|
data/lib/Monkey.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'monkey_action'
|
2
4
|
require 'MonkeyEngine/exceptions'
|
3
5
|
|
4
6
|
# Monkey action: dead (as in not alive)
|
5
7
|
# The monkey has been killed - the thread is not running.
|
6
8
|
class MonkeyActionDead < MonkeyAction
|
7
|
-
|
8
9
|
WEIGHT = 100.0
|
9
|
-
VALID_VALUES = [
|
10
|
+
VALID_VALUES = [true].freeze
|
10
11
|
|
11
12
|
def initialize(monkey)
|
12
|
-
super monkey, true
|
13
|
+
super monkey, true, WEIGHT
|
13
14
|
|
14
15
|
validate
|
15
16
|
|
@@ -17,10 +18,11 @@ class MonkeyActionDead < MonkeyAction
|
|
17
18
|
end
|
18
19
|
|
19
20
|
protected
|
21
|
+
|
20
22
|
def validate
|
21
23
|
super
|
22
24
|
|
23
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
24
|
-
|
25
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
26
|
+
unless VALID_VALUES.include?(@value)
|
25
27
|
end
|
26
|
-
end
|
28
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
require_relative 'monkey_action'
|
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
|
|
7
9
|
# Monkey action: eat (as in banana)
|
8
10
|
# The monkey is eating.
|
9
11
|
class MonkeyActionEat < MonkeyTimedAction
|
10
|
-
|
11
12
|
WEIGHT = 2.0
|
12
13
|
VALID_VALUES = (30..60) # 30 through 60 minutes
|
13
14
|
|
@@ -22,10 +23,11 @@ class MonkeyActionEat < MonkeyTimedAction
|
|
22
23
|
end
|
23
24
|
|
24
25
|
protected
|
26
|
+
|
25
27
|
def validate
|
26
28
|
super
|
27
29
|
|
28
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
29
|
-
|
30
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
|
+
unless VALID_VALUES.include?(@value)
|
30
32
|
end
|
31
|
-
end
|
33
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
require_relative 'monkey_action'
|
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
|
|
7
9
|
# Monkey action: pause (as in take a break)
|
8
10
|
# The monkey paused, usually from typing.
|
9
11
|
class MonkeyActionPause < MonkeyTimedAction
|
10
|
-
|
11
12
|
WEIGHT = 2.0
|
12
13
|
VALID_VALUES = (0..60) # Seconds (0 - 60 seconds)
|
13
14
|
|
@@ -22,11 +23,11 @@ class MonkeyActionPause < MonkeyTimedAction
|
|
22
23
|
end
|
23
24
|
|
24
25
|
protected
|
26
|
+
|
25
27
|
def validate
|
26
28
|
super
|
27
29
|
|
28
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
29
|
-
|
30
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
|
+
unless VALID_VALUES.include?(@value)
|
30
32
|
end
|
31
|
-
|
32
|
-
end
|
33
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
require_relative 'monkey_action'
|
@@ -7,7 +9,6 @@ require 'MonkeyEngine/exceptions'
|
|
7
9
|
# Monkey action: sleep (as in take a snooze)
|
8
10
|
# The monkey is a sleep.
|
9
11
|
class MonkeyActionSleep < MonkeyTimedAction
|
10
|
-
|
11
12
|
WEIGHT = 10.0
|
12
13
|
VALID_VALUES = ((60 * 6)..(60 * 8)) # 6 through 8 hours
|
13
14
|
|
@@ -22,10 +23,11 @@ class MonkeyActionSleep < MonkeyTimedAction
|
|
22
23
|
end
|
23
24
|
|
24
25
|
protected
|
26
|
+
|
25
27
|
def validate
|
26
28
|
super
|
27
29
|
|
28
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
29
|
-
|
30
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
31
|
+
unless VALID_VALUES.include?(@value)
|
30
32
|
end
|
31
|
-
end
|
33
|
+
end
|
@@ -1,20 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'monkey_action'
|
2
4
|
require 'MonkeyEngine/exceptions'
|
3
5
|
|
4
6
|
# Monkey action: type (as in keyboard)
|
5
7
|
# The monkey typed something on the keyboard.
|
6
8
|
class MonkeyActionType < MonkeyAction
|
7
|
-
|
8
9
|
attr_reader :keyboard_input
|
9
10
|
|
10
11
|
WEIGHT = 5.0
|
11
12
|
|
12
13
|
def initialize(monkey, keyboard_input)
|
13
|
-
raise MonkeyEngine::Exceptions::NilArgumentException
|
14
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "keyboard_input '#{keyboard_input}' cannot be nil" \
|
14
15
|
if keyboard_input.nil?
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
unless keyboard_input.is_a?(KeyboardInput)
|
18
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
|
19
|
+
"keyboard_input '#{keyboard_input}' is not a valid argument type"
|
20
|
+
end
|
18
21
|
|
19
22
|
@keyboard_input = keyboard_input
|
20
23
|
|
@@ -26,15 +29,17 @@ class MonkeyActionType < MonkeyAction
|
|
26
29
|
end
|
27
30
|
|
28
31
|
protected
|
29
|
-
def validate
|
30
32
|
|
31
|
-
|
33
|
+
def validate
|
34
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
|
32
35
|
if @value.nil?
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
unless @value.is_a?(Array)
|
38
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException,
|
39
|
+
"Value '#{value}' is not a valid argument type (#{value.class.name})"
|
40
|
+
end
|
36
41
|
|
37
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
42
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' cannot be empty" \
|
38
43
|
if @value.empty?
|
39
44
|
end
|
40
|
-
end
|
45
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'monkey_action'
|
2
4
|
require 'MonkeyEngine/exceptions'
|
3
5
|
|
4
6
|
# Monkey action: wake (as in from sleep)
|
5
7
|
# The monkey has awakened from sleep.
|
6
8
|
class MonkeyActionWake < MonkeyAction
|
7
|
-
|
8
9
|
WEIGHT = 2.0
|
9
|
-
VALID_VALUES = [
|
10
|
+
VALID_VALUES = [true].freeze
|
10
11
|
|
11
12
|
def initialize(monkey)
|
12
|
-
super monkey, true
|
13
|
+
super monkey, true, WEIGHT
|
13
14
|
|
14
15
|
validate
|
15
16
|
|
@@ -17,10 +18,11 @@ class MonkeyActionWake < MonkeyAction
|
|
17
18
|
end
|
18
19
|
|
19
20
|
protected
|
21
|
+
|
20
22
|
def validate
|
21
23
|
super
|
22
24
|
|
23
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentValueException
|
24
|
-
|
25
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value" \
|
26
|
+
unless VALID_VALUES.include?(@value)
|
25
27
|
end
|
26
|
-
end
|
28
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'monkey_action'
|
2
4
|
require 'MonkeyEngine/exceptions'
|
3
5
|
|
4
6
|
# Monkey action: one that is timed based on an Integer.
|
5
7
|
class MonkeyTimedAction < MonkeyAction
|
6
|
-
|
7
8
|
attr_accessor :action_time_of_completion
|
8
9
|
|
9
10
|
def initialize(monkey, value, weight)
|
@@ -17,11 +18,12 @@ class MonkeyTimedAction < MonkeyAction
|
|
17
18
|
end
|
18
19
|
|
19
20
|
protected
|
21
|
+
|
20
22
|
def validate
|
21
|
-
raise MonkeyEngine::Exceptions::NilArgumentException
|
23
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, "Value '#{value}' cannot be nil" \
|
22
24
|
if @value.nil?
|
23
25
|
|
24
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
26
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, "Value '#{value}' is not a valid argument type" \
|
25
27
|
unless @value.is_a?(Integer)
|
26
28
|
end
|
27
|
-
end
|
29
|
+
end
|
data/lib/MonkeyActions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
require 'singleton'
|
3
5
|
|
@@ -8,14 +10,15 @@ require 'MonkeyKeyboardEnUs'
|
|
8
10
|
class ActionRules
|
9
11
|
include Singleton
|
10
12
|
|
11
|
-
# Retrieves tne next action for the monkey
|
12
|
-
#
|
13
|
-
# @param [monkey] the monkey whose next action is to be retrieved
|
14
|
-
# @return [MonkeyAction] the next monkey action
|
13
|
+
# Retrieves tne next action for the monkey
|
14
|
+
#
|
15
|
+
# @param [monkey] the monkey whose next action is to be retrieved
|
16
|
+
# @return [MonkeyAction] the next monkey action
|
15
17
|
def get_next_action(monkey)
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
unless monkey.action.nil? || monkey.action.action_completed?
|
19
|
+
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
20
|
+
"The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling get_next_action"
|
21
|
+
end
|
19
22
|
|
20
23
|
# current_action = monkey.action
|
21
24
|
|
@@ -34,15 +37,15 @@ class ActionRules
|
|
34
37
|
|
35
38
|
keyboard_input = MonkeyEngine::MonkeyKeyboardEnUs.instance.get_keyboard_input
|
36
39
|
|
37
|
-
|
40
|
+
MonkeyActionType.new monkey, keyboard_input
|
38
41
|
end
|
39
42
|
|
40
43
|
# Evaluates an action and sets it to completed if the criteria for completion is met.
|
41
44
|
def action_eval!(action)
|
42
|
-
raise MonkeyEngine::Exceptions::NilArgumentException
|
45
|
+
raise MonkeyEngine::Exceptions::NilArgumentException, 'The [action] to be evaluated cannot be nil' \
|
43
46
|
if action.nil?
|
44
47
|
|
45
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
48
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
46
49
|
unless action.is_a? Action
|
47
50
|
|
48
51
|
action_eval_eat(action) if action.is_a?(MonkeyActionEat)
|
@@ -61,28 +64,28 @@ class ActionRules
|
|
61
64
|
# Action evaluation methods
|
62
65
|
|
63
66
|
def action_eval_eat(action)
|
64
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
67
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
65
68
|
unless action.is_a? MonkeyActionEat
|
66
69
|
|
67
70
|
action_eval_timed_action action
|
68
71
|
end
|
69
72
|
|
70
73
|
def action_eval_pause(action)
|
71
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
74
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
72
75
|
unless action.is_a? MonkeyActionPause
|
73
76
|
|
74
77
|
action_eval_timed_action action
|
75
78
|
end
|
76
79
|
|
77
80
|
def action_eval_sleep(action)
|
78
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
81
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
79
82
|
unless action.is_a? MonkeyActionSleep
|
80
83
|
|
81
84
|
action_eval_timed_action action
|
82
85
|
end
|
83
86
|
|
84
87
|
def action_eval_type(action)
|
85
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
88
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
86
89
|
unless action.is_a? MonkeyActionType
|
87
90
|
|
88
91
|
# TODO: How do I evaluate this?
|
@@ -91,7 +94,7 @@ class ActionRules
|
|
91
94
|
end
|
92
95
|
|
93
96
|
def action_eval_wake(action)
|
94
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
97
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
95
98
|
unless action.is_a? MonkeyActionWake
|
96
99
|
|
97
100
|
action.action_completed = true
|
@@ -100,12 +103,11 @@ class ActionRules
|
|
100
103
|
end
|
101
104
|
|
102
105
|
def action_eval_timed_action(action)
|
103
|
-
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
106
|
+
raise MonkeyEngine::Exceptions::InvalidArgumentTypeException, 'The [action] is not the correct type' \
|
104
107
|
unless action.is_a? MonkeyTimedAction
|
105
108
|
|
106
109
|
action.action_completed = true if action.action_time_of_completion <= Time.now
|
107
110
|
|
108
111
|
action
|
109
112
|
end
|
110
|
-
|
111
|
-
end
|
113
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module MonkeyEngine
|
4
4
|
module Exceptions
|
5
|
-
class InvalidArgumentValueException < ArgumentError
|
5
|
+
class InvalidArgumentValueException < ArgumentError
|
6
6
|
end
|
7
7
|
|
8
|
-
class InvalidArgumentTypeException < ArgumentError
|
8
|
+
class InvalidArgumentTypeException < ArgumentError
|
9
9
|
end
|
10
10
|
|
11
|
-
class NilArgumentException < ArgumentError
|
11
|
+
class NilArgumentException < ArgumentError
|
12
12
|
end
|
13
13
|
|
14
14
|
# The object must be unique.
|
15
|
-
class UniqueObjectException < ArgumentError
|
15
|
+
class UniqueObjectException < ArgumentError
|
16
16
|
end
|
17
17
|
|
18
|
-
class InvalidOperationException < ArgumentError
|
18
|
+
class InvalidOperationException < ArgumentError
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'observer'
|
2
4
|
require 'singleton'
|
3
5
|
require 'time'
|
@@ -6,15 +8,14 @@ require 'MonkeyActions'
|
|
6
8
|
require_relative 'action_rules'
|
7
9
|
|
8
10
|
module MonkeyEngine
|
9
|
-
|
10
11
|
# Assigns, executes and evaluates actions.
|
11
12
|
class Engine
|
12
13
|
include Singleton
|
13
14
|
include Observable
|
14
15
|
|
15
16
|
private
|
16
|
-
|
17
|
-
end
|
17
|
+
|
18
|
+
def initialize; end
|
18
19
|
|
19
20
|
public
|
20
21
|
|
@@ -24,8 +25,10 @@ module MonkeyEngine
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def do_action(action)
|
27
|
-
|
28
|
-
|
28
|
+
if action.action_completed?
|
29
|
+
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
30
|
+
"The action [#{action.class.name}] for Monkey [#{action.monkey.monkey_symbol}] is already completed"
|
31
|
+
end
|
29
32
|
|
30
33
|
do_action_type(action) if action.is_a? MonkeyActionType
|
31
34
|
|
@@ -42,12 +45,12 @@ module MonkeyEngine
|
|
42
45
|
|
43
46
|
# Returns a new action.
|
44
47
|
def new_action(monkey)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
unless monkey.action.nil? || monkey.action.action_completed?
|
49
|
+
raise MonkeyEngine::Exceptions::InvalidOperationException,
|
50
|
+
"The action [#{monkey.action.class.name}] for Monkey [#{monkey.monkey_symbol}] must be completed before calling new_action"
|
51
|
+
end
|
48
52
|
|
49
|
-
|
53
|
+
ActionRules.instance.get_next_action monkey
|
50
54
|
end
|
51
|
-
|
52
55
|
end
|
53
56
|
end
|
data/lib/MonkeyEngine/version.rb
CHANGED
data/lib/MonkeyEngine.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'Monkey'
|
2
4
|
|
3
5
|
module MonkeyFactory
|
4
|
-
|
5
6
|
class << self
|
6
|
-
|
7
|
-
public
|
8
7
|
def create(monkey_symbol)
|
9
8
|
# Call the protected constructor - monkeys can only be created
|
10
9
|
# via the MonkeyFactory.
|
11
10
|
Monkey.send(:new, monkey_symbol)
|
12
11
|
end
|
13
12
|
end
|
14
|
-
end
|
13
|
+
end
|
data/lib/MonkeyFactory.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Represents keyboard input.
|
2
4
|
class KeyboardInput
|
3
|
-
|
4
5
|
attr_accessor :is_word, :input
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@is_word = false
|
8
|
-
@input =
|
9
|
+
@input = []
|
9
10
|
end
|
10
11
|
|
11
12
|
def input_to_s
|
12
13
|
@input.join.to_s
|
13
14
|
end
|
14
|
-
end
|
15
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class KeyboardKeyEvaluator
|
2
4
|
def initialize
|
3
5
|
@shift_on = false
|
@@ -10,16 +12,12 @@ class KeyboardKeyEvaluator
|
|
10
12
|
|
11
13
|
return nil if keyboard_key.keyboard_char.char.is_a? Symbol
|
12
14
|
|
13
|
-
if @shift_on
|
14
|
-
return keyboard_key.keyboard_shift_char.char
|
15
|
-
end
|
15
|
+
return keyboard_key.keyboard_shift_char.char if @shift_on
|
16
16
|
|
17
17
|
char = keyboard_key.keyboard_char.char
|
18
18
|
|
19
|
-
if @caps_on
|
20
|
-
return char.upcase
|
21
|
-
end
|
19
|
+
return char.upcase if @caps_on
|
22
20
|
|
23
21
|
char
|
24
22
|
end
|
25
|
-
end
|
23
|
+
end
|