From 021401b53869ccb33bd03c7ad77b961afc680da2 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 31 Aug 2014 20:21:09 +0000 Subject: [PATCH] C Jeopardy: Show correctness percentage when an answer is almost correct; recommend #cjeopardy channel when attempting to play via /msg --- PBot/VERSION.pm | 4 ++-- modules/cjeopardy.pl | 2 +- modules/cjeopardy_answer.pl | 23 ++++++++++++++++++++--- modules/cjeopardy_hint.pl | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index f81ac083..8c7682d6 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 778, - BUILD_DATE => "2014-08-18", + BUILD_REVISION => 779, + BUILD_DATE => "2014-08-31", }; 1; diff --git a/modules/cjeopardy.pl b/modules/cjeopardy.pl index cac06143..de3d31bb 100755 --- a/modules/cjeopardy.pl +++ b/modules/cjeopardy.pl @@ -19,7 +19,7 @@ sub encode { my $str = shift; $str =~ s/\\(.)/{sprintf "\\%03d", ord($1)}/ge; re sub decode { my $str = shift; $str =~ s/\\(\d{3})/{"\\" . chr($1)}/ge; return $str } if ($channel !~ /^#/) { - print "Sorry, C Jeopardy must be played in a channel.\n"; + print "Sorry, C Jeopardy must be played in a channel. Feel free to join #cjeopardy.\n"; exit; } diff --git a/modules/cjeopardy_answer.pl b/modules/cjeopardy_answer.pl index e1cbd7de..5a38c380 100755 --- a/modules/cjeopardy_answer.pl +++ b/modules/cjeopardy_answer.pl @@ -20,7 +20,7 @@ sub encode { my $str = shift; $str =~ s/\\(.)/{sprintf "\\%03d", ord($1)}/ge; re sub decode { my $str = shift; $str =~ s/\\(\d{3})/{"\\" . chr($1)}/ge; return $str } if ($channel !~ /^#/) { - print "Sorry, C Jeopardy must be played in a channel.\n"; + print "Sorry, C Jeopardy must be played in a channel. Feel free to join #cjeopardy.\n"; exit; } @@ -105,6 +105,8 @@ if (not @data) { my @valid_answers = map { decode $_ } split /\|/, encode $data[1]; +my $incorrect_percentage = 100; + foreach my $answer (@valid_answers) { chomp $answer; $answer =~ s/\\\|/|/g; @@ -117,7 +119,13 @@ foreach my $answer (@valid_answers) { my $distance = fastdistance($lctext, lc $answer); my $length = (length($lctext) > length($answer)) ? length $lctext : length $answer; - if ($distance / $length < 0.15) { + my $percentage = $distance / $length * 100; + + if ($percentage < $incorrect_percentage) { + $incorrect_percentage = $percentage; + } + + if ($percentage < 15) { if ($distance == 0) { print "'$answer' is correct!"; } else { @@ -153,4 +161,13 @@ foreach my $answer (@valid_answers) { } } -print "Sorry, '$text' is incorrect.\n"; +my $correct_percentage = 100 - $incorrect_percentage; +if ($correct_percentage >= 80) { + printf "Sorry, '$text' is %.1f%% correct. So close!\n", $correct_percentage; +} elsif ($correct_percentage >= 70) { + printf "Sorry, '$text' is %.1f%% correct. Almost.\n", $correct_percentage; +} elsif ($correct_percentage >= 50) { + printf "Sorry, '$text' is only %.1f%% correct.\n", $correct_percentage; +} else { + print "Sorry, '$text' is incorrect.\n"; +} diff --git a/modules/cjeopardy_hint.pl b/modules/cjeopardy_hint.pl index 44181661..e54b9475 100755 --- a/modules/cjeopardy_hint.pl +++ b/modules/cjeopardy_hint.pl @@ -18,7 +18,7 @@ sub encode { my $str = shift; $str =~ s/\\(.)/{sprintf "\\%03d", ord($1)}/ge; re sub decode { my $str = shift; $str =~ s/\\(\d{3})/{"\\" . chr($1)}/ge; return $str } if ($channel !~ /^#/) { - print "Sorry, C Jeopardy must be played in a channel.\n"; + print "Sorry, C Jeopardy must be played in a channel. Feel free to join #cjeopardy.\n"; exit; } @@ -88,7 +88,7 @@ while (@indices <= $hidden_character_count - $spaces - $dashes - $underscores) { } foreach my $index (@indices) { - substr $hint, $index, 1, '?'; + substr $hint, $index, 1, '.'; } print "Hint: $hint\n";