]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/roulette.rb
markov: refactor triplet learning
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / roulette.rb
index 5c9a86c6c32834e427a25a7a6c9d171a153c3c78..6d8347888cf52c94b2bba658697a5b21eb9d6b7e 100644 (file)
@@ -1,20 +1,21 @@
-RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins)
+define_structure :RouletteHistory, :games, :shots, :deaths, :misses, :wins
 
 class RoulettePlugin < Plugin
-  BotConfig.register BotConfigBooleanValue.new('roulette.autospin',
-    :default => true, 
+  Config.register Config::BooleanValue.new('roulette.autospin',
+    :default => true,
     :desc => "Automatically spins the roulette at the butlast shot")
-  BotConfig.register BotConfigBooleanValue.new('roulette.kick',
-    :default => false, 
+  Config.register Config::BooleanValue.new('roulette.kick',
+    :default => false,
     :desc => "Kicks shot players from the channel")
-  BotConfig.register BotConfigBooleanValue.new('roulette.twice_in_a_row',
-    :default => false, 
+  Config.register Config::BooleanValue.new('roulette.twice_in_a_row',
+    :default => false,
     :desc => "Allow players to go twice in a row")
 
   def initialize
     super
     reset_chambers
     @players = Array.new
+    @last = ''
   end
 
   def help(plugin, topic="")
@@ -46,11 +47,12 @@ class RoulettePlugin < Plugin
       totals = RouletteHistory.new(0,0,0,0,0)
     end
 
-    if @players.last == m.sourcenick and not @bot.config['roulette.twice_in_a_row']
+    if @last == m.sourcenick and not @bot.config['roulette.twice_in_a_row']
       m.reply "you can't go twice in a row!"
       return
     end
 
+    @last = m.sourcenick
     unless @players.include?(m.sourcenick)
       @players << m.sourcenick
       playerdata.games += 1
@@ -71,7 +73,8 @@ class RoulettePlugin < Plugin
         totals.wins += 1
         @registry["player " + plyr] = pdata
       }
-      @players = Array.new
+      @players.clear
+      @last = ''
       @bot.kick(m.replyto, m.sourcenick, "*BANG*") if @bot.config['roulette.kick']
     else
       m.reply "#{m.sourcenick}: chamber #{6 - @chambers.length} of 6 => +click+"
@@ -117,7 +120,8 @@ class RoulettePlugin < Plugin
     totals.games += 1
     @registry["totals"] = totals
 
-    @players = Array.new
+    @players.clear
+    @last = ''
   end
 
   def spin(m, params={})
@@ -170,7 +174,7 @@ class RoulettePlugin < Plugin
       k = match[1]
 
       total_players += 1
-      
+
       win_rate = v.wins.to_f / v.games * 100
       if h_win_percent[0].nil? || win_rate > h_win_percent[1] && v.games > 2
         h_win_percent = [[k], win_rate]