mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Implement "quickest answer" score tracking (and disable wrong answer streaks)
This commit is contained in:
parent
e6c18eb428
commit
0da2287cde
@ -5,6 +5,7 @@ use strict;
|
|||||||
|
|
||||||
use Text::Levenshtein qw(fastdistance);
|
use Text::Levenshtein qw(fastdistance);
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
use Time::Duration qw(duration);
|
||||||
use Fcntl qw(:flock);
|
use Fcntl qw(:flock);
|
||||||
|
|
||||||
use Scorekeeper;
|
use Scorekeeper;
|
||||||
@ -94,7 +95,14 @@ if (defined $ret) {
|
|||||||
if ($last_nick eq $nick) {
|
if ($last_nick eq $nick) {
|
||||||
print "$color{red}Er, you already correctly answered that question.$color{reset}\n";
|
print "$color{red}Er, you already correctly answered that question.$color{reset}\n";
|
||||||
} else {
|
} else {
|
||||||
print "$color{red}Too slow! $color{orange}$last_nick$color{red} got the correct answer.$color{reset}\n";
|
my $elapsed = scalar gettimeofday - $last_timestamp;
|
||||||
|
my $duration;
|
||||||
|
if ($elapsed < 2) {
|
||||||
|
$duration = sprintf("%.2f", $elapsed);
|
||||||
|
} else {
|
||||||
|
$duration = sprintf("%d", $elapsed);
|
||||||
|
}
|
||||||
|
print "$color{red}Too slow by $color{orange}$duration $color{red}second" . ($duration != 1 ? "s" : "") . "! $color{orange}$last_nick$color{red} got the correct answer.$color{reset}\n";
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -126,7 +134,7 @@ foreach my $answer (@valid_answers) {
|
|||||||
$supplemental_text = $1;
|
$supplemental_text = $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($answer =~ /^[0-9]+$/ and $lctext =~ /^[0-9]+$/) {
|
if ($answer =~ /^[+-]*[0-9]+$/ and $lctext =~ /^[+-]*[0-9]+$/) {
|
||||||
my $is_wrong = 0;
|
my $is_wrong = 0;
|
||||||
|
|
||||||
if ($lctext > $answer) {
|
if ($lctext > $answer) {
|
||||||
@ -157,9 +165,15 @@ foreach my $answer (@valid_answers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined $supplemental_text) {
|
if (defined $supplemental_text) {
|
||||||
print " $color{purple}$supplemental_text$color{reset}\n";
|
print " $color{purple}$supplemental_text$color{reset}";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $elapsed = scalar gettimeofday - $data[2];
|
||||||
|
if ($elapsed < 60) {
|
||||||
|
printf " It took %.2f seconds to answer that question!\n", $elapsed;
|
||||||
} else {
|
} else {
|
||||||
print "\n";
|
my $duration = duration($elapsed);
|
||||||
|
print " It took $duration to answer that question.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $streakers = $scores->get_all_correct_streaks($channel);
|
my $streakers = $scores->get_all_correct_streaks($channel);
|
||||||
@ -181,6 +195,10 @@ foreach my $answer (@valid_answers) {
|
|||||||
$player_data->{last_correct_timestamp} = scalar gettimeofday;
|
$player_data->{last_correct_timestamp} = scalar gettimeofday;
|
||||||
$player_data->{wrong_streak} = 0;
|
$player_data->{wrong_streak} = 0;
|
||||||
|
|
||||||
|
if ($player_data->{quickest_correct} == 0 or $elapsed < $player_data->{quickest_correct}) {
|
||||||
|
$player_data->{quickest_correct} = $elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
if ($player_data->{correct_streak} > $player_data->{highest_correct_streak}) {
|
if ($player_data->{correct_streak} > $player_data->{highest_correct_streak}) {
|
||||||
$player_data->{highest_correct_streak} = $player_data->{correct_streak};
|
$player_data->{highest_correct_streak} = $player_data->{correct_streak};
|
||||||
}
|
}
|
||||||
@ -261,6 +279,7 @@ if ($player_data->{highest_wrong_streak} > $player_data->{lifetime_highest_wrong
|
|||||||
$player_data->{lifetime_highest_wrong_streak} = $player_data->{highest_wrong_streak};
|
$player_data->{lifetime_highest_wrong_streak} = $player_data->{highest_wrong_streak};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=cut
|
||||||
my %streaks = (
|
my %streaks = (
|
||||||
3 => "$color{red}Guessing, are we, $color{orange}$nick$color{red}?",
|
3 => "$color{red}Guessing, are we, $color{orange}$nick$color{red}?",
|
||||||
4 => "$color{red}Please use better guesses, $color{orange}$nick!",
|
4 => "$color{red}Please use better guesses, $color{orange}$nick!",
|
||||||
@ -275,6 +294,7 @@ my %streaks = (
|
|||||||
if (exists $streaks{$player_data->{wrong_streak}}) {
|
if (exists $streaks{$player_data->{wrong_streak}}) {
|
||||||
print "$streaks{$player_data->{wrong_streak}}$color{reset}\n";
|
print "$streaks{$player_data->{wrong_streak}}$color{reset}\n";
|
||||||
}
|
}
|
||||||
|
=cut
|
||||||
|
|
||||||
$scores->update_player_data($player_id, $player_data);
|
$scores->update_player_data($player_id, $player_data);
|
||||||
$scores->end;
|
$scores->end;
|
||||||
|
@ -4,6 +4,7 @@ use warnings;
|
|||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
use Time::Duration qw(duration);
|
||||||
|
|
||||||
use Scorekeeper;
|
use Scorekeeper;
|
||||||
use IRCColors;
|
use IRCColors;
|
||||||
@ -40,6 +41,18 @@ if (lc $command eq 'score') {
|
|||||||
$score .= "current streak: $color{orange}$player_data->{correct_streak}$color{green}, ";
|
$score .= "current streak: $color{orange}$player_data->{correct_streak}$color{green}, ";
|
||||||
$score .= "$color{green}highest streak: $color{orange}$player_data->{highest_correct_streak}" . ($player_data->{lifetime_highest_correct_streak} > $player_data->{highest_correct_streak} ? " [$player_data->{lifetime_highest_correct_streak}]" : "") . "$color{green}, ";
|
$score .= "$color{green}highest streak: $color{orange}$player_data->{highest_correct_streak}" . ($player_data->{lifetime_highest_correct_streak} > $player_data->{highest_correct_streak} ? " [$player_data->{lifetime_highest_correct_streak}]" : "") . "$color{green}, ";
|
||||||
|
|
||||||
|
$score .= "quickest answer: $color{orange}";
|
||||||
|
|
||||||
|
if ($player_data->{quickest_correct} == 0) {
|
||||||
|
$score .= "N/A";
|
||||||
|
} elsif ($player_data->{quickest_correct} < 60) {
|
||||||
|
$score .= sprintf("%.2f seconds", $player_data->{quickest_correct});
|
||||||
|
} else {
|
||||||
|
$score .= duration($player_data->{quickest_correct});
|
||||||
|
}
|
||||||
|
|
||||||
|
$score .= "$color{green}, ";
|
||||||
|
|
||||||
$score .= "$color{red}wrong: $color{orange}$player_data->{wrong_answers}" . ($player_data->{lifetime_wrong_answers} > $player_data->{wrong_answers} ? " [$player_data->{lifetime_wrong_answers}]" : "") . "$color{red}, ";
|
$score .= "$color{red}wrong: $color{orange}$player_data->{wrong_answers}" . ($player_data->{lifetime_wrong_answers} > $player_data->{wrong_answers} ? " [$player_data->{lifetime_wrong_answers}]" : "") . "$color{red}, ";
|
||||||
$score .= "current streak: $color{orange}$player_data->{wrong_streak}$color{red}, ";
|
$score .= "current streak: $color{orange}$player_data->{wrong_streak}$color{red}, ";
|
||||||
$score .= "$color{red}highest streak: $color{orange}$player_data->{highest_wrong_streak}" . ($player_data->{lifetime_highest_wrong_streak} > $player_data->{highest_wrong_streak} ? " [$player_data->{lifetime_highest_wrong_streak}]" : "") . "$color{red}, ";
|
$score .= "$color{red}highest streak: $color{orange}$player_data->{highest_wrong_streak}" . ($player_data->{lifetime_highest_wrong_streak} > $player_data->{highest_wrong_streak} ? " [$player_data->{lifetime_highest_wrong_streak}]" : "") . "$color{red}, ";
|
||||||
|
Loading…
Reference in New Issue
Block a user