class Asagi::Generate_AI
Public Class Methods
operate_tree()
click to toggle source
# File lib/asagi.rb, line 146 def self.operate_tree system("ruby tree.rb"); sleep(3) end
self_repair()
click to toggle source
# File lib/asagi.rb, line 132 def self.self_repair if File.exists?("tree.rb") puts "I'm still here in your folder." else back_up = File.read(".backup/tree.rb").strip open("tree.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/asagi.rb, line 7 def self.sequence old_tree = File.read("tree.rb") backup_tree = old_tree open(".backup/tree.rb", "w") { |f| f.puts backup_tree } 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.rb", "w") { |f| f.puts "# Auto training, motivation, and action." f.puts "def experience_#{method_name}" f.puts " fear = File.read('data/input/fear_ratio.txt').strip.to_i" f.puts " " f.puts " open('data/input/fear_ratio.txt', 'w') { |f|" f.puts " f.puts fear += 0.5" f.puts " }" f.puts " " f.puts " sleep(3)" 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 == 'fight'" 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 " " 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_flight" 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 "end" f.puts " " f.puts old_tree f.puts " " f.puts "def asagi_fear; ex = experience_fear; mo = fear_ratio; end" f.puts "def asagi_danger; ex = experience_danger; mo = danger_ratio; end" f.puts "def asagi_hunger; ex = experience_hunger; mo = hunger_ratio; end" f.puts "def asagi_lust; ex = experience_lust; mo = lust_ratio; end" f.puts "def asagi_comfort; ex = experience_comfort; mo = comfort_ratio; end" f.puts "def asagi_creativity; ex = experience_creativity; mo = creativity_ratio; end" f.puts "def asagi_curiosity ex = experience_curiosity; mo = curiosity_ratio; end" f.puts "puts '\nTrain On'" f.puts "puts '[a] Fear [b] Danger [c] Hunger'" f.puts "puts '[d] Lust [e] Comfort [f] Creativity'" f.puts "puts '[g] Curiosity'" f.puts "print '\n >> '" f.puts "input = gets.chomp" f.puts " " f.puts "if input == 'a'; a = asagi_fear" f.puts "elsif input == 'b'; a = asagi_danger" f.puts "elsif input == 'c'; a = asagi_hunger" f.puts "elsif input == 'd'; a = asagi_lust" f.puts "elsif input == 'e'; a = asagi_comfort" f.puts "elsif input == 'f'; a = asagi_creativity" f.puts "elsif input == 'g'; a = asagi_curiosity" f.puts "else" f.puts " puts 'No training critera...'" f.puts "end" } end