From ac4bae6db135bb64bf6cafcb5bb1819a9f546b1c Mon Sep 17 00:00:00 2001 From: Chris Gahan Date: Fri, 16 Feb 2007 06:28:21 +0000 Subject: * 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) --- data/rbot/plugins/roshambo.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'data/rbot/plugins/roshambo.rb') 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 -- cgit v1.2.3