summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/games/azgame.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-11-01 22:10:58 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-11-01 22:10:58 +0000
commite0449035d5e73fe90f65c8969b9e1e627d946dfe (patch)
tree05a33d84056ded4ea4a2485b6e339e128fab834f /data/rbot/plugins/games/azgame.rb
parentfbdf7a4eb950187a2c551f1dfd03cfaadf1938d8 (diff)
azgame plugin: better handling of late checks
Diffstat (limited to 'data/rbot/plugins/games/azgame.rb')
-rw-r--r--data/rbot/plugins/games/azgame.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/data/rbot/plugins/games/azgame.rb b/data/rbot/plugins/games/azgame.rb
index f84fa159..fb81b6d7 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]
@@ -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