]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Keep track of invalid tries in azgame, but report them without considering them for...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 26 Jan 2007 00:52:38 +0000 (00:52 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 26 Jan 2007 00:52:38 +0000 (00:52 +0000)
data/rbot/plugins/azgame.rb

index ae410e87a16144c4408954e0766ba44f48d84794..c1ad3ea5b759019f38d1fcc9f71cdb6ff94bbfe5 100644 (file)
@@ -27,14 +27,16 @@ AZ_RULES = {
 class AzGame\r
 \r
   attr_reader :range, :word\r
-  attr_accessor :tries, :total_tries, :winner\r
+  attr_accessor :tries, :total_tries, :total_failed, :failed, :winner\r
   def initialize(plugin, lang, word)\r
     @plugin = plugin\r
     @lang = lang.to_sym\r
     @word = word.downcase\r
     @range = [AZ_RULES[lang][:first].dup, AZ_RULES[lang][:last].dup]\r
     @total_tries = 0\r
+    @total_failed = 0 # not used, reported, updated\r
     @tries = Hash.new(0)\r
+    @failed = Hash.new(0) # not used, not reported, updated\r
     @winner = nil\r
     def @range.to_s\r
       return "%s -- %s" % self\r
@@ -132,6 +134,8 @@ class AzGamePlugin < Plugin
       m.reply "#{word} is not in the range #{Bold}#{isit.last}#{Bold}" if m.address?\r
     when :noexist\r
       m.reply "#{word} doesn't exist or is not acceptable for the game"\r
+      @games[k].total_failed += 1\r
+      @games[k].failed[m.source] += 1\r
     when :in\r
       m.reply "close, but no cigar. New range: #{Bold}#{isit.last}#{Bold}"\r
       @games[k].total_tries += 1\r
@@ -193,7 +197,28 @@ class AzGamePlugin < Plugin
       @games[k] = AzGame.new(self, lang, word)\r
     end\r
     tr = @games[k].total_tries\r
-    m.reply "A-Z: #{Bold}#{@games[k].range}#{Bold}" + (tr > 0 ? " (after #{tr} tries)" : "")\r
+    case tr\r
+    when 0\r
+      tr_msg = ""\r
+    when 1\r
+      tr_msg = " (after 1 try"\r
+    else\r
+      tr_msg = " (after #{tr} tries"\r
+    end\r
+\r
+    unless tr_msg.empty?\r
+      f_tr = @games[k].total_failed\r
+      case f_tr\r
+      when 0\r
+        tr_msg << ")"\r
+      when 1\r
+        tr_msg << " and 1 invalid try)"\r
+      else\r
+        tr_msg << " and #{f_tr} invalid tries)"\r
+      end\r
+    end\r
+\r
+    m.reply "A-Z: #{Bold}#{@games[k].range}#{Bold}" + tr_msg\r
     return\r
   end\r
 \r