ruby版のwobotロボット
1675 ワード
この2,3日rubyのコードを突き刺して、感じは悪くなくて、書くのはとても簡単で、いっそwobotをrubyで書き直して、練習しました.
puts "I'm wobot, 。"
time = Time.new
questionAliasSetting = Hash.new # hash
#
questionAliasSetting.store(" , 。",Array[" ","hello"," "," ","hi"])
questionAliasSetting.store(" leo heo。",Array[" "," "," "," "," ","name"," "," "])
questionAliasSetting.store(" , 。 , ",Array[" "," "," "," ","eee"])
questionAliasSetting.store(time.strftime("%Y-%m-%d"),Array[" "," "," ","date","today"])
questionAliasSetting.store(time.strftime("%Y-%m-%d %H:%M:%S"),Array[" "," "," ","now","time"])
qSetting=Hash.new
questionAliasSetting.each_key do |qamswer|
questionAliasSetting[qamswer].each do |qquestion|
qSetting.store(qquestion,qamswer);
end
end
noAnswer = Array[" "," "," "," "," "]# ,
loop{
qput = gets.chomp()
qput = qput.encode("UTF-8")
if qput=="exit"
puts " exit, ";
break;
else
if qSetting[qput]!= nil
puts " ->"+qSetting[qput]
else
puts " ->"+noAnswer[rand(noAnswer.length)]
end
end
}