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
- if w < @word\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
- else\r
+ return [:in, @range]\r
+ elsif w > @word and w < @range.last\r
@range.last.replace(w)\r
+ return [:in, @range]\r
end\r
- return [:in, @range]\r
+ return [:out, @range]\r
end\r
\r
# TODO scoring: base score is t = ceil(100*exp(-((n-1)^2)/(50^2)))+p for n attempts\r
: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
end\r
\r
def word_check(m, k, word)\r
- isit = @games[k].check(word)\r
- case isit.first\r
- when :bingo\r
- m.reply _("%{bold}BINGO!%{bold} the word was %{underline}%{word}%{underline}. Congrats, %{bold}%{player}%{bold}!") % {:bold => Bold, :underline => Underline, :word => word, :player => m.sourcenick}\r
- @games[k].total_tries += 1\r
- @games[k].tries[m.source] += 1\r
- @games[k].winner = m.source\r
- ar = @games[k].score.inject([]) { |res, kv|\r
- res.push("%s: %d (%s)" % kv.flatten)\r
- }\r
- m.reply _("The game was won after %{tries} tries. Scores for this game: %{scores}") % {:tries => @games[k].total_tries, :scores => ar.join('; ')}\r
- @games.delete(k)\r
- 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
- 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
- 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
- when :ignore\r
- m.reply _("%{word} is already one of the range extrema: %{range}") % {:word => word, :range => isit.last} if m.address?\r
- else\r
- m.reply _("hm, something went wrong while verifying %{word}")\r
- end\r
+ # Not really safe ... what happens\r
+ Thread.new {\r
+ isit = @games[k].check(word)\r
+ case isit.first\r
+ when :bingo\r
+ m.reply _("%{bold}BINGO!%{bold} the word was %{underline}%{word}%{underline}. Congrats, %{bold}%{player}%{bold}!") % {:bold => Bold, :underline => Underline, :word => word, :player => m.sourcenick}\r
+ @games[k].total_tries += 1\r
+ @games[k].tries[m.source] += 1\r
+ @games[k].winner = m.source\r
+ ar = @games[k].score.inject([]) { |res, kv|\r
+ res.push("%s: %d (%s)" % kv.flatten)\r
+ }\r
+ m.reply _("The game was won after %{tries} tries. Scores for this game: %{scores}") % {:tries => @games[k].total_tries, :scores => ar.join('; ')}\r
+ @games.delete(k)\r
+ 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
+ when :ignore\r
+ m.reply _("%{word} is already one of the range extrema: %{range}") % {:word => word, :range => isit.last} if m.address?\r
+ else\r
+ m.reply _("hm, something went wrong while verifying %{word}")\r
+ end\r
+ }\r
end\r
\r
def manual_word_check(m, params)\r
: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
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
wc = @wordcache[:italian]\r
return true if wc.key?(word.to_sym)\r
rules = @rules[:italian]\r
- p = @bot.httputil.get(rules[:wapurl] % word)\r
+ p = @bot.httputil.get(rules[:wapurl] % word, :open_timeout => 60, :read_timeout => 60)\r
if not p\r
error "could not connect!"\r
return false\r