1 # Play the game of roshambo (rock-paper-scissors)
2 # Copyright (C) 2004 Hans Fugal
3 # Distributed under the same license as rbot itself
5 class RoshamboPlugin < Plugin
10 def help(plugin, topic="")
11 "roshambo <rock|paper|scissors> => play roshambo"
18 if (not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600)
19 @scoreboard[m.sourcenick] = {'me'=>0,'you'=>0,'timestamp'=>Time.now}
22 when 'rock','paper','scissors'
23 s = score(choice,m.params)
24 @scoreboard[m.sourcenick]['timestamp'] = Time.now
25 myscore=@scoreboard[m.sourcenick]['me']
26 yourscore=@scoreboard[m.sourcenick]['you']
29 yourscore=@scoreboard[m.sourcenick]['you'] += 1
30 m.reply "#{choice}. You win. Score: me #{myscore} you #{yourscore}"
32 m.reply "#{choice}. We tie. Score: me #{myscore} you #{yourscore}"
34 myscore=@scoreboard[m.sourcenick]['me'] += 1
35 m.reply "#{choice}! I win! Score: me #{myscore} you #{yourscore}"
38 m.reply "incorrect usage: " + help(m.plugin)
43 ['rock','paper','scissors'][rand(3)]
46 beats = {'rock'=>'scissors', 'paper'=>'rock', 'scissors'=>'paper'}
47 return -1 if beats[a] == b
48 return 1 if beats[b] == a
52 plugin = RoshamboPlugin.new
53 plugin.register("roshambo")
54 plugin.register("rps")