4 # :title: Roshambo (rock-paper-scissors) plugin for rbot
7 # Copyright:: (C) 2004 Hans Fugal
9 # Play the game of roshambo (rock-paper-scissors)
11 # Distributed under the same license as rbot itself
15 class RoshamboPlugin < Plugin
20 @beats = { :rock => :scissors, :paper => :rock, :scissors => :paper}
24 def help(plugin, topic="")
25 "roshambo <rock|paper|scissors> or rps <rock|paper|scissors> => play roshambo"
30 bot_choice = @plays.pick_one
33 if not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600
34 @scoreboard[m.sourcenick] = { 'me' => 0, 'you' => 0, 'timestamp' => Time.now }
36 human_choice = params[:play].to_sym
37 s = score(bot_choice, human_choice)
38 @scoreboard[m.sourcenick]['timestamp'] = Time.now
39 myscore=@scoreboard[m.sourcenick]['me']
40 yourscore=@scoreboard[m.sourcenick]['you']
43 yourscore = @scoreboard[m.sourcenick]['you'] += 1
44 m.reply "#{bot_choice}. You win. Score: me #{myscore} you #{yourscore}"
46 m.reply "#{bot_choice}. We tie. Score: me #{myscore} you #{yourscore}"
48 myscore = @scoreboard[m.sourcenick]['me'] += 1
49 m.reply "#{bot_choice}! I win! Score: me #{myscore} you #{yourscore}"
53 def score(bot_choice, human_choice)
54 return -1 if @beats[bot_choice] == human_choice
55 return 1 if @beats[human_choice] == bot_choice
60 plugin = RoshamboPlugin.new
61 plugin.map "roshambo :play", :action => :rps, :requirements => { :play => /rock|paper|scissors/ }
62 plugin.map "rps :play", :action => :rps, :requirements => { :play => /rock|paper|scissors/ }