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