<commit_before>package TreeTraversal;

    use strict;
    use warnings;

    use Board;
    use Move;

    use Time::HiRes qw( time );
    use Data::Dumper;

sub list_available_moves {
    my ($board) = shift;

    my @moves;

    for (my $y=0; $y<$board->height; $y++) {
        for (my $x=0; $x<$board->width; $x++) {
            my $cell = $board->{cells}[$y][$x];
            next if ($cell == -11 || $cell == 10);

            foreach my $dir (1..4) {
                push @moves, new Move(x => $x, y => $y, dir => $dir);
            }
        }
    }
    return \@moves;
}


# iterative deepening depth-first search
sub IDDFS {
    my ($board) = @_;

    for (my $depth=1;  ; $depth++) {
        print "==== trying to depth $depth ====\n";
        my $started = time();

        my $ret = _IDDFS($board, $depth);
        return $ret if defined($ret);

        my $duration = time() - $started;
        printf "%6.2f seconds\n", $duration;
    }

    return undef;
}


# Returns a list-ref of moves, if a solution was found.
sub _IDDFS {
    my ($board, $depth_remaining) = @_;

    my @moves = @{ list_available_moves($board) };

    foreach my $move (@moves) {
        my $new_board = $board->clone;
        $move->apply($new_board);
        if ($new_board->has_won) {<commit_msg>bugfix<commit_after>package TreeTraversal;

    use strict;
    use warnings;

    use Board;
    use Move;

    use Time::HiRes qw( time );
    use Data::Dumper;

sub list_available_moves {
    my ($board) = shift;

    my @moves;

    for (my $y=0; $y<$board->height; $y++) {
        for (my $x=0; $x<$board->width; $x++) {
            my $cell = $board->{cells}[$y][$x];
            next if ($cell == -11 || $cell == 10);

            foreach my $dir (1..4) {
                push @moves, new Move(x => $x, y => $y, dir => $dir);
            }
        }
    }
    return \@moves;
}


# iterative deepening depth-first search
sub IDDFS {
    my ($board) = @_;

    for (my $depth=1;  ; $depth++) {
        print "==== trying to depth $depth ====\n";
        my $started = time();

        my $ret = _IDDFS($board, $depth);
        return $ret if defined($ret);

        my $duration = time() - $started;
        printf "%6.2f seconds\n", $duration;
    }

    return undef;
}


# Returns a list-ref of moves, if a solution was found.
sub _IDDFS {
    my ($board, $depth_remaining) = @_;

    my @moves = @{ list_available_moves($board) };

    foreach my $move (@moves) {
        my $new_board = $board->clone;
        $move->apply($new_board)
            or next;
        if ($new_board->has_won) {
{'fraction_non_alphanumeric': 0.17226728466589417, 'fraction_numerical': 0.008497489378138278, 'mean_word_length': 2.0151338766006983, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '2526869', 'n_tokens_mistral': 943, 'n_tokens_neox': 896, 'n_words': 250}