class Asagi2::Generate_AI
Public Class Methods
operate_tree()
click to toggle source
# File lib/asagi2.rb, line 134 def self.operate_tree print "Operate which tree? >> "; input = gets.chomp system("#{input}.rb"); sleep(3) end
self_repair()
click to toggle source
# File lib/asagi2.rb, line 117 def self.self_repair print "Which file is missing? >> " input = gets.chomp if File.exists?("#{input}.rb") puts "I'm still here in your folder." else back_up = File.read(".backup/#{input}.rb").strip open("#{input}.rb", "w") { |f| f.puts back_up } puts "You should be more careful how you treat your files."; sleep(3) end end
sequence()
click to toggle source
# File lib/asagi2.rb, line 7 def self.sequence print "Give a method name >> "; method_name = gets.chomp; ratio = "_ratio" print "Create a meter attribute >> "; attribute = gets.chomp; print "Name a robot action >> "; action = gets.chomp; print "Write automamtic robot dialogue >> "; robot_dialogue_automatic = gets.chomp; open("data/input/#{method_name}#{ratio}.txt", "w") { |f| starting_value = 0.5 f.puts starting_value } open("tree_#{action}.rb", "w") { |f| f.puts "# Auto training, motivation, and action." f.puts "def experience_#{method_name}" f.puts " current_value = File.read('data/input/#{method_name}_ratio.txt')" f.puts " current_value = current_value.to_i" f.puts " current_value = current_value + 10" f.puts " " f.puts " # Writes current value to file." f.puts " open('data/input/#{method_name}_ratio.txt', 'w') { |f|" f.puts " puts 'Training AI to self learn.'" f.puts " " f.puts " f.puts current_value" f.puts " }" f.puts " " f.puts " sleep(3)" f.puts " " f.puts " #{method_name[0]} = #{method_name}#{ratio}" f.puts "end" f.puts " " f.puts "def #{method_name}#{ratio}" f.puts " require 'decisiontree'" f.puts " " f.puts " def robot_#{method_name}" f.puts " a = ai_#{action}" f.puts " end" f.puts " " f.puts " def confirm_deny" f.puts " print 'Robot is increasingly restless, #{action} or stay? >> '" f.puts " input = gets.chomp" f.puts " " f.puts " if input == '#{action}'" f.puts " a = ai_#{action}" f.puts " elsif input == 'stay'" f.puts " require 'espeak'" f.puts " " f.puts " speech = ESpeak::Speech.new('I chose to stay.')" f.puts " speech.speak" f.puts " else" f.puts " require 'espeak'" f.puts " " f.puts " speech = ESpeak::Speech.new('Command not understood.')" f.puts " speech.speak" f.puts " end" f.puts " end" f.puts " " f.puts " input = File.read('data/input/#{method_name}#{ratio}.txt').strip.to_i" f.puts " " f.puts " attributes = ['#{attribute}']" f.puts " " f.puts " training = [" f.puts " [13.75, 'Very Low'], [20.625, 'Somewhat Low'], [27.5, 'Normal Low']," f.puts " [37.3125, 'Medium'], [54.0, 'High'], [67.5, 'Urgent']," f.puts " [81.0, 'Danger'], [94.5, 'Critical'], [108.0, 'Automatic']," f.puts " ]" f.puts " " f.puts " dec_tree = DecisionTree::ID3Tree.new(attributes, training, 1, :continuous); dec_tree.train" f.puts " test = [input]" f.puts " " f.puts " decision = dec_tree.predict(test)" f.puts " true_decision = test.last" f.puts " " f.puts " print '#{method_name.upcase}: '; print decision" f.puts " puts '\n'" f.puts " " f.puts " if decision == 'Very Low' or 13.75; c = confirm_deny" f.puts " elsif decision == 'Somewhat Low' or 20.625; c = confirm_deny" f.puts " elsif decision == 'Normal Low' or 67.5; c = confirm_deny" f.puts " elsif decision == 'Medium' or 37.3125; c = confirm_deny" f.puts " elsif decision == 'High' or 54.0; c = confirm_deny" f.puts " elsif decision == 'Urgent' or 67.5; c = confirm_deny" f.puts " elsif decision == 'Danger' or 81.0; c = confirm_deny" f.puts " elsif decision == 'Critical' or 94.5; c = confirm_deny" f.puts " elsif decision == 'Automatic' or 108.0; r = robot_#{method_name}" f.puts " end" f.puts " " f.puts "end" f.puts " " f.puts "def ai_#{action}" f.puts " require 'espeak'" f.puts " " f.puts " speech = ESpeak::Speech.new('#{robot_dialogue_automatic}')" f.puts " speech.speak" f.puts "\n # Fill in action script below here." f.puts "end" f.puts "\n# Don't edit below here." f.puts "e = experience_#{method_name}" } record_backup = File.read("tree_#{action}.rb") print "Do you want to back up your file? >> " backup_tree = "tree_#{action}" open(".backup/#{backup_tree}.rb", "w") { |f| f.puts record_backup } end