<commit_before>#include <cstdlib>
#include <ctime>
#include <stack>

#include "DFSMazeGenerator.h"
#include "Maze.h"
#include "Point.h"

#define NUM_DIRECTIONS 4

Point DFSMazeGenerator::getRandomUnvisitedDirection(Maze& m, Point p) {

    static Point directions[] = {Point(1,0), Point(-1,0), Point(0,1), Point(0,-1)};

    short directionIndex = rand() % NUM_DIRECTIONS;
    short attempts = 0;

    while (m.isConnected(p + 2 * directions[directionIndex]) && attempts < NUM_DIRECTIONS) {
        directionIndex = (directionIndex + 1) % NUM_DIRECTIONS;
        ++attempts;
    }

    if (attempts == NUM_DIRECTIONS)
        return Point(0, 0);

    return directions[directionIndex];
}

void DFSMazeGenerator::generate(Maze& m) {

    Point current = m.end;

    srand(time(NULL));

    std::stack<Point> pointStack;
    pointStack.push(current);

    while(!pointStack.empty()) {
        Point p = pointStack.top();
        Point neighborDirection = getRandomUnvisitedDirection(m, p);
        if (neighborDirection == Point(0, 0)) {
            pointStack.pop();
        } else {
            Point wall = p + neighborDirection;
            Point dest = wall + neighborDirection;
            m.setType(wall, MazeCell::Type::OPEN);
            pointStack.push(dest);
        }
    }
}
<commit_msg>Undo me being an idiot I forgot that there was a state in between connected and unconnected It caused a segfault Whoops<commit_after>#include <cstdlib>
#include <ctime>
#include <stack>

#include "DFSMazeGenerator.h"
#include "Maze.h"
#include "Point.h"

#define NUM_DIRECTIONS 4

Point DFSMazeGenerator::getRandomUnvisitedDirection(Maze& m, Point p) {

    static Point directions[] = {Point(1,0), Point(-1,0), Point(0,1), Point(0,-1)};

    short directionIndex = rand() % NUM_DIRECTIONS;
    short attempts = 0;

    while (!m.isUnconnected(p + 2 * directions[directionIndex]) && attempts < NUM_DIRECTIONS) {
        directionIndex = (directionIndex + 1) % NUM_DIRECTIONS;
        ++attempts;
    }

    if (attempts == NUM_DIRECTIONS)
        return Point(0, 0);

    return directions[directionIndex];
}

void DFSMazeGenerator::generate(Maze& m) {

    Point current = m.end;

    srand(time(NULL));

    std::stack<Point> pointStack;
    pointStack.push(current);

    while(!pointStack.empty()) {
        Point p = pointStack.top();
        Point neighborDirection = getRandomUnvisitedDirection(m, p);
        if (neighborDirection == Point(0, 0)) {
            pointStack.pop();
        } else {
            Point wall = p + neighborDirection;
            Point dest = wall + neighborDirection;
            m.setType(wall, MazeCell::Type::OPEN);
            pointStack.push(dest);
        }
    }
}

{'fraction_non_alphanumeric': 0.12828096118299445, 'fraction_numerical': 0.011829944547134935, 'mean_word_length': 3.063063063063063, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4134279', 'n_tokens_mistral': 899, 'n_tokens_neox': 837, 'n_words': 197}