X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgames%2Fazgame.rb;h=12cdf724196d8f9566403d3cf793603d67c5ef65;hb=8afa7a66180ea8fae1eca9d6841c0d2711c40108;hp=04efb810f0a7b023668d693a80561b6f56ed8add;hpb=0873ce4d2f31f240d05ab8c16d31150aff289c82;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/azgame.rb b/data/rbot/plugins/games/azgame.rb index 04efb810..12cdf724 100644 --- a/data/rbot/plugins/games/azgame.rb +++ b/data/rbot/plugins/games/azgame.rb @@ -45,15 +45,17 @@ class AzGame return [:ignore, @range] if w == @range.first or w == @range.last return [:noexist, @range] unless @plugin.send("is_#{@lang}?", w) debug "we like it" - if w < @word + if w < @word and w > @range.first @range.first.replace(w) - else + return [:in, @range] + elsif w > @word and w < @range.last @range.last.replace(w) + return [:in, @range] end - return [:in, @range] + return [:out, @range] end -# TODO scoring: base score is t = ceil(100*exp(-(n-1)^2/50))+p for n attempts +# TODO scoring: base score is t = ceil(100*exp(-((n-1)^2)/(50^2)))+p for n attempts # done by p players; players that didn't win but contributed # with a attempts will get t*a/n points @@ -62,16 +64,16 @@ class AzGame def score n = @total_tries p = @tries.keys.length - t = (100*exp(-(n-1)**2/50**2)).ceil + p + t = (100*exp(-((n-1)**2)/(50.0**2))).ceil + p debug "Total score: #{t}" ret = Hash.new @tries.each { |k, a| - ret[k] = [t*a/n, "%d %s" % [a, a > 1 ? "tries" : "try"]] + ret[k] = [t*a/n, n_("%{count} try", "%{count} tries", a) % {:count => a}] } if @winner debug "replacing winner score of %d with %d" % [ret[@winner].first, t] tries = ret[@winner].last - ret[@winner] = [t, "winner, #{tries}"] + ret[@winner] = [t, _("winner, %{tries}") % {:tries => tries}] end return ret.sort_by { |h| h.last.first }.reverse end @@ -147,33 +149,36 @@ class AzGamePlugin < Plugin end def word_check(m, k, word) - isit = @games[k].check(word) - case isit.first - when :bingo - m.reply _("%{bold}BINGO!%{bold} the word was %{underline}%{word}%{underline}. Congrats, %{bold}%{player}%{bold}!") % {:bold => Bold, :underline => Underline, :word => word, :player => m.sourcenick} - @games[k].total_tries += 1 - @games[k].tries[m.source] += 1 - @games[k].winner = m.source - ar = @games[k].score.inject([]) { |res, kv| - res.push("%s: %d (%s)" % kv.flatten) - } - m.reply _("The game was won after %{tries} tries. Scores for this game: %{scores}") % {:tries => @games[k].total_tries, :scores => ar.join('; ')} - @games.delete(k) - 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 - 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 - 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 - when :ignore - m.reply _("%{word} is already one of the range extrema: %{range}") % {:word => word, :range => isit.last} if m.address? - else - m.reply _("hm, something went wrong while verifying %{word}") - end + # Not really safe ... what happens + Thread.new { + isit = @games[k].check(word) + case isit.first + when :bingo + m.reply _("%{bold}BINGO!%{bold} the word was %{underline}%{word}%{underline}. Congrats, %{bold}%{player}%{bold}!") % {:bold => Bold, :underline => Underline, :word => word, :player => m.sourcenick} + @games[k].total_tries += 1 + @games[k].tries[m.source] += 1 + @games[k].winner = m.source + ar = @games[k].score.inject([]) { |res, kv| + res.push("%s: %d (%s)" % kv.flatten) + } + m.reply _("The game was won after %{tries} tries. Scores for this game: %{scores}") % {:tries => @games[k].total_tries, :scores => ar.join('; ')} + @games.delete(k) + 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 + 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 + 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 + when :ignore + m.reply _("%{word} is already one of the range extrema: %{range}") % {:word => word, :range => isit.last} if m.address? + else + m.reply _("hm, something went wrong while verifying %{word}") + end + } end def manual_word_check(m, params) @@ -232,7 +237,7 @@ class AzGamePlugin < Plugin else f_tr = @games[k].total_failed if f_tr > 0 - tr_msg = _(" (after %{total_tries} and %{invalid_tries}") % + tr_msg = _(" (after %{total_tries} and %{invalid_tries})") % { :total_tries => n_("%{count} try", "%{count} tries", tr) % {:count => tr}, :invalid_tries => n_("%{count} invalid try", "%{count} invalid tries", tr) %