]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/azgame.rb
azgame plugin: whitespace cleanup
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / azgame.rb
index 775214509da8ff364afe05c5eff22a64ee88b3bb..495173b34fdd89c6a7f6f4cf72ef8ca0446c5278 100644 (file)
@@ -40,11 +40,18 @@ class AzGame
   def check(word)\r
     w = word.downcase\r
     debug "checking #{w} for #{@word} in #{@range}"\r
+    # Since we're called threaded, bail out early if a winner\r
+    # was assigned already\r
+    return [:ignore, nil] if @winner\r
     return [:bingo, nil] if w == @word\r
     return [:out, @range] if w < @range.first or w > @range.last\r
     return [:ignore, @range] if w == @range.first or w == @range.last\r
+    # This is potentially slow (for languages that check online)\r
     return [:noexist, @range] unless @plugin.send("is_#{@lang}?", w)\r
     debug "we like it"\r
+    # Check again if there was a winner in the mean time,\r
+    # and bail out if there was\r
+    return [:ignore, nil] if @winner\r
     if w < @word and w > @range.first\r
       @range.first.replace(w)\r
       return [:in, @range]\r
@@ -114,7 +121,7 @@ class AzGamePlugin < Plugin
       :listener => /^[a-z]+$/\r
     },\r
     }\r
-    \r
+\r
     japanese_wordlist = "#{@bot.botclass}/azgame/wordlist-japanese"\r
     if File.exist?(japanese_wordlist)\r
       words = File.readlines(japanese_wordlist) \\r
@@ -166,10 +173,14 @@ class AzGamePlugin < Plugin
       when :out\r
         m.reply _("%{word} is not in the range %{bold}%{range}%{bold}") % {:word => word, :bold => Bold, :range => isit.last} if m.address?\r
       when :noexist\r
+        # bail out early if the game was won in the mean time\r
+        return if !@games[k] or @games[k].winner\r
         m.reply _("%{word} doesn't exist or is not acceptable for the game") % {:word => word}\r
         @games[k].total_failed += 1\r
         @games[k].failed[m.source] += 1\r
       when :in\r
+        # bail out early if the game was won in the mean time\r
+        return if !@games[k] or @games[k].winner\r
         m.reply _("close, but no cigar. New range: %{bold}%{range}%{bold}") % {:bold => Bold, :range => isit.last}\r
         @games[k].total_tries += 1\r
         @games[k].tries[m.source] += 1\r
@@ -243,7 +254,7 @@ class AzGamePlugin < Plugin
              :invalid_tries => n_("%{count} invalid try", "%{count} invalid tries", tr) %\r
                                {:count => f_tr} }\r
       else\r
-        tr_msg = _(" (after %{total_tries}") %\r
+        tr_msg = _(" (after %{total_tries})") %\r
                  { :total_tries => n_("%{count} try", "%{count} tries", tr) %\r
                              {:count => tr}}\r
       end\r
@@ -328,12 +339,12 @@ class AzGamePlugin < Plugin
   def is_japanese?(word)\r
     @rules[:japanese][:list].include?(word)\r
   end\r
-  \r
+\r
   # return integer between min and max, inclusive\r
   def rand_between(min, max)\r
     rand(max - min + 1) + min\r
   end\r
-  \r
+\r
   def random_pick_japanese(min=nil, max=nil)\r
     rules = @rules[:japanese]\r
     min = rules[:first] if min.nil_or_empty?\r