-
-
Save anonymous/229a20e71d6bf3b8a9b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
#main function | |
def whos_on_first(old_context) | |
begin | |
costellos_line = $stdin.gets.chomp | |
end while costellos_line.empty? | |
#break up input into words | |
costellos_words = costellos_line.split(/\W+/) | |
#try cues | |
new_context = get_context(costellos_words, old_context) | |
strong_reply = try_strong_cues(costellos_words) | |
weak_reply = try_weak_cues(new_context) | |
had_enough = wants_to_end(costellos_words) | |
if !had_enough.empty? | |
puts had_enough | |
elsif !strong_reply.empty? | |
puts strong_reply | |
whos_on_first(new_context) | |
elsif !weak_reply.empty? | |
puts weak_reply | |
whos_on_first(new_context) | |
# old_context = new_context | |
else | |
puts hedge() | |
whos_on_first(new_context) | |
end | |
end | |
def try_cues(words, cues, database) | |
#compare words to cues | |
words.each do |word| | |
cues.each do |cue| | |
if word == cue | |
return database[cue][rand(database[cue].length)] | |
end | |
end | |
end | |
return "" | |
end | |
def get_context(words, old_context) | |
context = ["first", "second", "third"] | |
words.each do |word| | |
context.each do |cue| | |
if word == cue | |
return cue | |
end | |
end | |
end | |
return old_context | |
end | |
def try_strong_cues(words) | |
cues = ["big", "meat", "daddy"] | |
replies = { | |
"meat" => ["one", "two", "three"], | |
"big" => ["one", "two", "three"], | |
"daddy" => ["one", "two", "three"] | |
} | |
return try_cues(words, cues, replies) | |
end | |
def try_weak_cues(context) | |
replies = { | |
"first"=> ["one", "two", "three"], | |
"second" => ["one", "two", "three"], | |
"third" => ["one", "two", "three"] | |
} | |
if !context.empty? | |
return replies[context][rand(replies[context].length)] | |
else | |
return "" | |
end | |
end | |
def wants_to_end(words) | |
words.each do |word| | |
if word == "quit" | |
return "peaces homes" | |
end | |
end | |
return "" | |
end | |
def hedge() | |
hedges = ["yo", "big", "meat", "dope", "socks"] | |
return hedges[rand(hedges.length)] | |
end | |
whos_on_first("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment