Testowo z dźwigiem. Do zmiany.

This commit is contained in:
Michał Jurgo 2016-12-08 08:49:58 +01:00
parent f65d014f43
commit 904a9199eb
9 changed files with 97 additions and 0 deletions

8
ruby_part/actions.txt Normal file
View File

@ -0,0 +1,8 @@
pick
put
lift
place
leave
load
unload
transport

29
ruby_part/crane_class.rb Normal file
View 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
View 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
View File

@ -0,0 +1,10 @@
right
left
forward
backwards
onwards
back
west
east
north
south

4
ruby_part/input.txt Normal file
View File

@ -0,0 +1,4 @@
forward
chess
move
load

View 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
View File

@ -0,0 +1,7 @@
go
move
come
travel
proceed
back
head

View 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
View File

@ -0,0 +1 @@
{"directions":"forward","movement":"move","actions":"load"}