From c8aa153ea27b06bccc78b3c0d35366a79a4d5f1e Mon Sep 17 00:00:00 2001 From: Okasu Date: Mon, 26 Dec 2011 03:53:16 -0500 Subject: [PATCH] Add a Greed dice game. --- data/rbot/plugins/games/greed.rb | 115 +++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 data/rbot/plugins/games/greed.rb diff --git a/data/rbot/plugins/games/greed.rb b/data/rbot/plugins/games/greed.rb new file mode 100644 index 00000000..c7dd4de3 --- /dev/null +++ b/data/rbot/plugins/games/greed.rb @@ -0,0 +1,115 @@ +#-- vim:sw=2:et +#++ +# +# :title: Greed dice game plugin for rbot +# +# Author:: Okasu +# +# Distributed under the same license as rbot itself +# + + +class Greed < Plugin + + def initialize + super + @scoreboard = {} + end + + def help(plugin, topic="") + "Simple dice game. Rules: https://en.wikipedia.org/wiki/Greed_(dice_game)" + end + + def diceroll + dice = Array.new + for i in 0..5 do + dice[i] = rand(6) + 1 + end + dice + end + + def scores + roll = diceroll + one = two = three = four = five = six = score = 0 + roll.each do |x| + case x + when 1 + one += 1 + if one == 3 + score += 1000 + elsif one == 6 + score += 7000 + else + score += 100 + end + when 2 + two += 1 + if two == 3 + score += 200 + elsif two == 4 + score += 400 + end + when 3 + three += 1 + if three == 3 + score += 300 + elsif three == 5 + score += 1200 + end + when 4 + four += 1 + if four == 3 + score += 400 + elsif four == 6 + score += 3600 + end + when 5 + five += 1 + if five == 3 + score += 500 + else + score += 50 + end + when 6 + six += 6 + if six == 3 + score += 600 + end + end + end + if roll.sort == [1,2,3,4,5,6] + score = 1200 + elsif roll.sort == [2,2,3,3,4,4] + score = 800 + end + [score, roll] + end + + def greed(m, params) + player = scores + mhash = {m.sourcenick => player[0]} + @scoreboard.merge! mhash + m.reply "You have #{player[0]} points. (#{player[1].join("-")})" + if params[:single] == "bot" + bot = scores + m.reply "I have #{bot[0]} points. (#{bot[1].join("-")})" + if player[0] < bot[0] + m.reply "Bot wins!" + else + m.reply "Human player wins!" + end + end + if @scoreboard.values.size == 2 + if @scoreboard.values[0] > @scoreboard.values[1] + m.reply "#{@scoreboard.keys.first} wins!" + else + m.reply "#{@scoreboard.keys.last} wins!" + end + @scoreboard.clear + end + end +end + +plugin = Greed.new +plugin.map "greed :single", :action => :greed, :requirements => {:single => /bot/}, :thread => "yes" +plugin.map "greed", :action => :greed, :thread => "yes" -- 2.32.0.93.g670b81a890