mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-27 13:12:42 +01:00
C Jeopardy: Add time-limit to hints
This commit is contained in:
parent
88dc009ae7
commit
236b4c1d06
@ -13,7 +13,7 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 756,
|
||||
BUILD_REVISION => 757,
|
||||
BUILD_DATE => "2014-07-29",
|
||||
};
|
||||
|
||||
|
@ -3,12 +3,14 @@
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use Text::Levenshtein qw(fastdistance);
|
||||
use Time::HiRes qw/gettimeofday/;
|
||||
use Time::Duration qw/duration/;
|
||||
|
||||
my $CJEOPARDY_DATA = 'cjeopardy.dat';
|
||||
my $CJEOPARDY_HINT = 'cjeopardy.hint';
|
||||
|
||||
my @hints = (0.90, 0.75, 0.50, 0.25, 0.10);
|
||||
my $timeout = 60;
|
||||
|
||||
my $channel = shift @ARGV;
|
||||
|
||||
@ -37,17 +39,26 @@ foreach my $answer (@valid_answers) {
|
||||
}
|
||||
}
|
||||
|
||||
my $hint_counter;
|
||||
my ($hint_counter, $last_timeout);
|
||||
my $ret = open $fh, "<", "$CJEOPARDY_HINT-$channel";
|
||||
if (defined $ret) {
|
||||
$hint_counter = <$fh>;
|
||||
$last_timeout = <$fh>;
|
||||
close $fh;
|
||||
}
|
||||
|
||||
my $duration = scalar gettimeofday - $last_timeout;
|
||||
if ($duration < $timeout) {
|
||||
$duration = duration($timeout - $duration);
|
||||
print "Please wait $duration before requesting another hint.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$hint_counter++;
|
||||
|
||||
open $fh, ">", "$CJEOPARDY_HINT-$channel" or die "Couldn't open $CJEOPARDY_HINT-$channel: $!";
|
||||
print $fh "$hint_counter\n";
|
||||
print $fh scalar gettimeofday, "\n";
|
||||
close $fh;
|
||||
|
||||
my $hidden_character_count = int length ($hint) * $hints[$hint_counter > $#hints ? $#hints : $hint_counter];
|
||||
|
Loading…
Reference in New Issue
Block a user