Testowo z dźwigiem. Do zmiany.
This commit is contained in:
parent
f65d014f43
commit
904a9199eb
8
ruby_part/actions.txt
Normal file
8
ruby_part/actions.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pick
|
||||||
|
put
|
||||||
|
lift
|
||||||
|
place
|
||||||
|
leave
|
||||||
|
load
|
||||||
|
unload
|
||||||
|
transport
|
29
ruby_part/crane_class.rb
Normal file
29
ruby_part/crane_class.rb
Normal file
@ -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
|
21
ruby_part/dictionary.rb
Normal file
21
ruby_part/dictionary.rb
Normal file
@ -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)}
|
10
ruby_part/directions.txt
Normal file
10
ruby_part/directions.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
right
|
||||||
|
left
|
||||||
|
forward
|
||||||
|
backwards
|
||||||
|
onwards
|
||||||
|
back
|
||||||
|
west
|
||||||
|
east
|
||||||
|
north
|
||||||
|
south
|
4
ruby_part/input.txt
Normal file
4
ruby_part/input.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
forward
|
||||||
|
chess
|
||||||
|
move
|
||||||
|
load
|
8
ruby_part/intelligence_test.rb
Normal file
8
ruby_part/intelligence_test.rb
Normal file
@ -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
|
7
ruby_part/movement.txt
Normal file
7
ruby_part/movement.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
go
|
||||||
|
move
|
||||||
|
come
|
||||||
|
travel
|
||||||
|
proceed
|
||||||
|
back
|
||||||
|
head
|
9
ruby_part/past_forms.json
Normal file
9
ruby_part/past_forms.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"go":"went",
|
||||||
|
"move":"moved",
|
||||||
|
"come":"came",
|
||||||
|
"travel":"traveled",
|
||||||
|
"proceed":"proceeded",
|
||||||
|
"back":"backed",
|
||||||
|
"head":"headed"
|
||||||
|
}
|
1
ruby_part/test.json
Normal file
1
ruby_part/test.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"directions":"forward","movement":"move","actions":"load"}
|
Loading…
Reference in New Issue
Block a user