diff --git a/ruby_part/actions.txt b/ruby_part/actions.txt new file mode 100644 index 0000000..9f8a97c --- /dev/null +++ b/ruby_part/actions.txt @@ -0,0 +1,8 @@ +pick +put +lift +place +leave +load +unload +transport \ No newline at end of file diff --git a/ruby_part/crane_class.rb b/ruby_part/crane_class.rb new file mode 100644 index 0000000..acf876e --- /dev/null +++ b/ruby_part/crane_class.rb @@ -0,0 +1,29 @@ +require 'json' +class Crane + attr_accessor :name, :words + + def initialize(name) + @name = name + end + + def introduce + puts "Hello, sir. I'm #{name} the Crane." + end + + def get_words + file = File.read('test.json') + @words = JSON.parse(file) + #puts words + end + + def if_understand + return @words.length > 1 + end + + def response + file = File.read('past_forms.json') + past_formes = JSON.parse(file) + puts (if @words.values.any? { |e| @words.key(e).eql? "movement" } then "I #{past_formes[@words["movement"]] + ' ' + @words["directions"]}" else "Ooops" end) + end + +end diff --git a/ruby_part/dictionary.rb b/ruby_part/dictionary.rb new file mode 100644 index 0000000..a5e6d4b --- /dev/null +++ b/ruby_part/dictionary.rb @@ -0,0 +1,21 @@ +require 'json' + +#txt = open("actions.txt") +#print txt.read +txt = open("input.txt") +#puts txt.read +filenames = ["actions.txt", "directions.txt", "movement.txt"] +dictionary = {} +#filenames.each do |name| + #f = File.read(name).include? +#end +txt.each_line do |line| + filenames.each do |name| + if File.read(name).include?line + dictionary[name.chomp('.txt')] = line.chomp("\n") + end + end +end + +puts dictionary +File.open("test.json", "w") {|f| f.write(dictionary.to_json)} diff --git a/ruby_part/directions.txt b/ruby_part/directions.txt new file mode 100644 index 0000000..46fdad8 --- /dev/null +++ b/ruby_part/directions.txt @@ -0,0 +1,10 @@ +right +left +forward +backwards +onwards +back +west +east +north +south \ No newline at end of file diff --git a/ruby_part/input.txt b/ruby_part/input.txt new file mode 100644 index 0000000..5826256 --- /dev/null +++ b/ruby_part/input.txt @@ -0,0 +1,4 @@ +forward +chess +move +load diff --git a/ruby_part/intelligence_test.rb b/ruby_part/intelligence_test.rb new file mode 100644 index 0000000..023016c --- /dev/null +++ b/ruby_part/intelligence_test.rb @@ -0,0 +1,8 @@ +require_relative 'crane_class' + +c = Crane.new("Roman") +c.introduce +c.get_words +puts c.words +puts h = c.if_understand +c.response diff --git a/ruby_part/movement.txt b/ruby_part/movement.txt new file mode 100644 index 0000000..b7fad49 --- /dev/null +++ b/ruby_part/movement.txt @@ -0,0 +1,7 @@ +go +move +come +travel +proceed +back +head \ No newline at end of file diff --git a/ruby_part/past_forms.json b/ruby_part/past_forms.json new file mode 100644 index 0000000..951bf9b --- /dev/null +++ b/ruby_part/past_forms.json @@ -0,0 +1,9 @@ +{ + "go":"went", + "move":"moved", + "come":"came", + "travel":"traveled", + "proceed":"proceeded", + "back":"backed", + "head":"headed" +} diff --git a/ruby_part/test.json b/ruby_part/test.json new file mode 100644 index 0000000..c5b8401 --- /dev/null +++ b/ruby_part/test.json @@ -0,0 +1 @@ +{"directions":"forward","movement":"move","actions":"load"} \ No newline at end of file