<commit_before>use strict;
use warnings;
use Data::Dumper;

my $store = require('data.pm');
my $is_playing = 0;

sub ask_question {
    my $about = shift;
    print $store->{$about},"\n";
}

sub start_msg {
    print $store->{'start'},"\n";
    $is_playing = 1;
}

sub exit_msg {
    print $store->{'exit'},"\n";
}

sub list_known_animals {
    print join(', ',  map { (@{$_})[1,2] } @{$store->{'data'}}), "\n";
}

sub play {
    my $about = shift;
    ask_question($about);
    my $answer = <STDIN>;
    chomp $answer;

    if (("$about" eq 'confirmExit') && ("$answer" =~ /[Yy]/)){
        $is_playing = 0;
        return;
    }

    if ("$answer" =~ /list/){
        list_known_animals();
        return;
    }

    if ("$answer" =~ /[Qq]/){
        play('confirmExit');
    }
    else{
        play('mood');
    }
}

sub game_loop {
    while($is_playing){
        play('mood');
    }
}

start_msg();
game_loop();
exit_msg();
<commit_msg>Simplify handling of list command. Handle the case where user don't think to an animal and propose to quit. Add function to test if question exists in our knowledge base<commit_after>use strict;
use warnings;
use Data::Dumper;

my $store = require('data.pm');
my $is_playing = 0;

sub ask_question {
    my $about = shift;
    print $store->{$about},"\n";
}

sub start_msg {
    print $store->{'start'},"\n";
    $is_playing = 1;
}

sub exit_msg {
    print $store->{'exit'},"\n";
}

sub list_known_animals {
    print join(', ',  map { (@{$_})[1,2] } @{$store->{'data'}}), "\n";
}

sub is_exists_question {
  my $subject = shift;
  my $result = grep { $_->[0] eq "$subject" } @{$store->{'data'}} ? 1 : 0;
  return $result;
}

sub play {
    my $about = shift;
    ask_question($about);
    my $answer = <STDIN>;
    chomp $answer;

    if (("$about" eq 'confirmExit') && ("$answer" =~ /[Yy]/)){
        $is_playing = 0;
        return;
    }

    if ("$answer" =~ /^(?:l|list)$/i){
        list_known_animals();
        return;
    }

    if ("$answer" =~ /[Qq]/){
        play('confirmExit');
    }
    elsif (("$about" eq 'mood') && ("$answer" =~ /[Nn]/)){
      play('confirmExit');
    }
    else{
        play('mood');
    }
}

sub game_loop {
    while($is_playing){
        play('mood');
    }
}

start_msg();
game_loop();
exit_msg();

{'fraction_non_alphanumeric': 0.21050328227571116, 'fraction_numerical': 0.0056892778993435445, 'mean_word_length': 2.6343402225755166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896302', 'n_tokens_mistral': 888, 'n_tokens_neox': 858, 'n_words': 202}