3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-01 17:16:39 +02:00

C Jeopardy: Show correctness percentage when an answer is almost correct; recommend #cjeopardy channel when attempting to play via /msg

This commit is contained in:
Pragmatic Software 2014-08-31 20:21:09 +00:00
parent 34d9a2a6d9
commit 021401b538
4 changed files with 25 additions and 8 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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";
}

View File

@ -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";