mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 02:49:49 +01:00
Spinach: Do not attempt to choose categories that do not contain questions that meet game configuration (min_difficulty, seen_expiry, etc); slightly speed up some delays
This commit is contained in:
parent
6dc911c100
commit
7f8272c0f3
@ -1582,17 +1582,31 @@ sub choosecategory {
|
|||||||
|
|
||||||
my $no_infinite_loops = 0;
|
my $no_infinite_loops = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
last if ++$no_infinite_loops > 200;
|
last if ++$no_infinite_loops > 10000;
|
||||||
my $cat = $categories[rand @categories];
|
my $cat = $categories[rand @categories];
|
||||||
|
|
||||||
my $count = keys %{$self->{categories}{$cat}};
|
my @questions = keys %{$self->{categories}{$cat}};
|
||||||
$self->{pbot}->{logger}->log("random cat: [$cat] $count questions\n");
|
|
||||||
|
|
||||||
if (not $count) {
|
if (not @questions) {
|
||||||
$self->{pbot}->{logger}->log("no count for random cat!\n");
|
$self->{pbot}->{logger}->log("No questions for category $cat\n");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exists $self->{metadata}->{hash}->{settings}->{min_difficulty}) {
|
||||||
|
@questions = grep { $self->{categories}{$cat}{$_}->{value} >= $self->{metadata}->{hash}->{settings}->{min_difficulty} } @questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists $self->{metadata}->{hash}->{settings}->{max_difficulty}) {
|
||||||
|
@questions = grep { $self->{categories}{$cat}{$_}->{value} <= $self->{metadata}->{hash}->{settings}->{max_difficulty} } @questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists $self->{metadata}->{hash}->{settings}->{seen_expiry}) {
|
||||||
|
my $now = time;
|
||||||
|
@questions = grep { $now - $self->{categories}{$cat}{$_}->{seen_timestamp} >= $self->{metadata}->{hash}->{settings}->{seen_expiry} } @questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
next if not @questions;
|
||||||
|
|
||||||
if (not grep { $_ eq $cat } @choices) {
|
if (not grep { $_ eq $cat } @choices) {
|
||||||
push @choices, $cat;
|
push @choices, $cat;
|
||||||
}
|
}
|
||||||
@ -1600,6 +1614,11 @@ sub choosecategory {
|
|||||||
last if @choices == $self->{metadata}->{hash}->{settings}->{category_choices} or @categories < $self->{metadata}->{hash}->{settings}->{category_choices};;
|
last if @choices == $self->{metadata}->{hash}->{settings}->{category_choices} or @categories < $self->{metadata}->{hash}->{settings}->{category_choices};;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (not @choices) {
|
||||||
|
$self->{pbot}->{logger}->log("Out of questions with current settings!\n");
|
||||||
|
# XXX: do something useful here
|
||||||
|
}
|
||||||
|
|
||||||
push @choices, 'RANDOM CATEGORY';
|
push @choices, 'RANDOM CATEGORY';
|
||||||
push @choices, 'REROLL CATEGORIES';
|
push @choices, 'REROLL CATEGORIES';
|
||||||
|
|
||||||
@ -2084,7 +2103,7 @@ sub showlies {
|
|||||||
sub showtruth {
|
sub showtruth {
|
||||||
my ($self, $state) = @_;
|
my ($self, $state) = @_;
|
||||||
|
|
||||||
if ($state->{ticks} % 4 == 0) {
|
if ($state->{ticks} % 3 == 0) {
|
||||||
my $player_id;
|
my $player_id;
|
||||||
my $player_data;
|
my $player_data;
|
||||||
my $players;
|
my $players;
|
||||||
@ -2247,7 +2266,7 @@ sub showfinalscore {
|
|||||||
if ($state->{first_tock}) {
|
if ($state->{first_tock}) {
|
||||||
$tock = 2;
|
$tock = 2;
|
||||||
} else {
|
} else {
|
||||||
$tock = 5;
|
$tock = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($state->{ticks} % $tock == 0) {
|
if ($state->{ticks} % $tock == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user