diff options
author | Chris Gahan <chris@ill-logic.com> | 2007-02-16 06:28:21 +0000 |
---|---|---|
committer | Chris Gahan <chris@ill-logic.com> | 2007-02-16 06:28:21 +0000 |
commit | ac4bae6db135bb64bf6cafcb5bb1819a9f546b1c (patch) | |
tree | c99276c9f7445fe5bb6a1d922f64c5a5a7fa10e3 /data/rbot/plugins/roshambo.rb | |
parent | dbb8a509f170a4b43f9db9755eb0f503d1b34f25 (diff) |
* Fixed roshambo (the bot would always tie if it picked scissors)
* Fixed figlet (if you didn't have the font "rectangles", it wouldn't work)
Diffstat (limited to 'data/rbot/plugins/roshambo.rb')
-rw-r--r-- | data/rbot/plugins/roshambo.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/data/rbot/plugins/roshambo.rb b/data/rbot/plugins/roshambo.rb index 7f776c39..74b94a4c 100644 --- a/data/rbot/plugins/roshambo.rb +++ b/data/rbot/plugins/roshambo.rb @@ -11,8 +11,8 @@ class RoshamboPlugin < Plugin def initialize super @scoreboard = {} - @plays = [:rock, :paper, :scissor] @beats = { :rock => :scissors, :paper => :rock, :scissors => :paper} + @plays = @beats.keys end def help(plugin, topic="") @@ -21,32 +21,32 @@ class RoshamboPlugin < Plugin def rps(m, params) # simultaneity - choice = @plays.pick_one + bot_choice = @plays.pick_one # init scoreboard if not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600 @scoreboard[m.sourcenick] = { 'me' => 0, 'you' => 0, 'timestamp' => Time.now } end - play = params[:play].to_sym - s = score(choice, play) + human_choice = params[:play].to_sym + s = score(bot_choice, human_choice) @scoreboard[m.sourcenick]['timestamp'] = Time.now myscore=@scoreboard[m.sourcenick]['me'] yourscore=@scoreboard[m.sourcenick]['you'] case s when 1 yourscore = @scoreboard[m.sourcenick]['you'] += 1 - m.reply "#{choice}. You win. Score: me #{myscore} you #{yourscore}" + m.reply "#{bot_choice}. You win. Score: me #{myscore} you #{yourscore}" when 0 - m.reply "#{choice}. We tie. Score: me #{myscore} you #{yourscore}" + m.reply "#{bot_choice}. We tie. Score: me #{myscore} you #{yourscore}" when -1 myscore = @scoreboard[m.sourcenick]['me'] += 1 - m.reply "#{choice}! I win! Score: me #{myscore} you #{yourscore}" + m.reply "#{bot_choice}! I win! Score: me #{myscore} you #{yourscore}" end end - def score(a, b) - return -1 if @beats[a] == b - return 1 if @beats[b] == a + def score(bot_choice, human_choice) + return -1 if @beats[bot_choice] == human_choice + return 1 if @beats[human_choice] == bot_choice return 0 end end |