<commit_before>'use strict';

// Make a N x M rectangular maze by walking through it,
// dropping bread crumbs, and knocking down walls.
//
// Use:
//      var maze = new Maze();
//      maze.createMaze(36, 11);
//      maze.display();
//
// By <NAME>. I just did this as an exercise after
// reading about mazes and spanning trees. No fancy algorithms,
// weighting, stacks or anything.
//
function Maze() {
    var self = this;

    // Set true before calling createMaze() to see the walk through.
    self.debug = false;

    var x, y; // Current position
    var breadcrumb; // Current bread crumb
    var count, total; // How many cells visited and how many total cells.

    function atBottom() {
        return y == 0;
    }

    function atLeft() {
        return x == 0;
    }

    function atRight() {
        return x == self.xSize - 1;
    }

    function atTop() {
        return y == self.ySize - 1;
    }

    // Follow the maze backwards until we find a cell with unvisited neighbors.
    //
    // Returns: boolean
    //      true - We found a cell with unvisited neighbors.
    //      false - We couldn't find any. Try another method.
    function backTrack() {

        function breadCrumbAbove() {
            return self.maze[x][y + 1].breadcrumb;

        }

        function breadCrumbBelow() {
            return self.maze[x][y - 1].breadcrumb;
        }

        function breakCrumbToTheLeft() {
            return self.maze[x - 1][y].breadcrumb;
        }

        function breakCrumbToTheRight() {
            return self.maze[x + 1][y].breadcrumb;
        }

        function isOpenAbove() {
            return !atTop() && !self.maze[x][y + 1].bottomWall;
        }

        function isOpenBelow() {
            // Still need to test atBottom() because the exit is down here
            // and we don't count the exit.
            return !atBottom() && !self.maze[x][y].bottomWall;
        }

        function isOpenLeft() {
            return !atLeft() && !self.maze[x - 1][y].rightWall;
        }

        function isOpenRight() {
            return !self.maze[x][y].rightWall;
        }

        function rememberBreadCrumb() {
            breadcrumb = self.maze[x][y].breadcrumb;
        }

        for (; ;) {
            // If we're back at the beginning of the maze, then we're done.
            if (breadcrumb == 1) return false;

            // Look at the bread crumbs next to us that we can see (not through walls).
            // If one has a smaller number, it's closer to the exit than we are.
            // Move there and remember the new bread crumb.
            if (self.debug) console.log("(", x, ", ", y, "): backtrack ", self.maze[x][y]);
            if (isOpenAbove() && breadCrumbAbove() < breadcrumb) {
                moveUp();
                rememberBreadCrumb();
            } else if (isOpenLeft() && breakCrumbToTheLeft() < breadcrumb) {
                moveLeft();
                rememberBreadCrumb();
            } else if (isOpenRight() && breakCrumbToTheRight() < breadcrumb) {
                moveRight();
                rememberBreadCrumb();
            } else if (isOpenBelow() && breadCrumbBelow() < breadcrumb) {
                moveDown();<commit_msg>I only pretend to know how to spell.<commit_after>'use strict';

// Make a N x M rectangular maze by walking through it,
// dropping bread crumbs, and knocking down walls.
//
// Use:
//      var maze = new Maze();
//      maze.createMaze(36, 11);
//      maze.display();
//
// By <NAME>. I just did this as an exercise after
// reading about mazes and spanning trees. No fancy algorithms,
// weighting, stacks or anything.
//
function Maze() {
    var self = this;

    // Set true before calling createMaze() to see the walk through.
    self.debug = false;

    var x, y; // Current position
    var breadcrumb; // Current bread crumb
    var count, total; // How many cells visited and how many total cells.

    function atBottom() {
        return y == 0;
    }

    function atLeft() {
        return x == 0;
    }

    function atRight() {
        return x == self.xSize - 1;
    }

    function atTop() {
        return y == self.ySize - 1;
    }

    // Follow the maze backwards until we find a cell with unvisited neighbors.
    //
    // Returns: boolean
    //      true - We found a cell with unvisited neighbors.
    //      false - We couldn't find any. Try another method.
    function backTrack() {

        function breadCrumbAbove() {
            return self.maze[x][y + 1].breadcrumb;

        }

        function breadCrumbBelow() {
            return self.maze[x][y - 1].breadcrumb;
        }

        function breadCrumbToTheLeft() {
            return self.maze[x - 1][y].breadcrumb;
        }

        function breadCrumbToTheRight() {
            return self.maze[x + 1][y].breadcrumb;
        }

        function isOpenAbove() {
            return !atTop() && !self.maze[x][y + 1].bottomWall;
        }

        function isOpenBelow() {
            // Still need to test atBottom() because the exit is down here
            // and we don't count the exit.
            return !atBottom() && !self.maze[x][y].bottomWall;
        }

        function isOpenLeft() {
            return !atLeft() && !self.maze[x - 1][y].rightWall;
        }

        function isOpenRight() {
            return !self.maze[x][y].rightWall;
        }

        function rememberBreadCrumb() {
            breadcrumb = self.maze[x][y].breadcrumb;
        }

        for (; ;) {
            // If we're back at the beginning of the maze, then we're done.
            if (breadcrumb == 1) return false;

            // Look at the bread crumbs next to us that we can see (not through walls).
            // If one has a smaller number, it's closer to the exit than we are.
            // Move there and remember the new bread crumb.
            if (self.debug) console.log("(", x, ", ", y, "): backtrack ", self.maze[x][y]);
            if (isOpenAbove() && breadCrumbAbove() < breadcrumb) {
                moveUp();
                rememberBreadCrumb();
            } else if (isOpenLeft() && breadCrumbToTheLeft() < breadcrumb) {
                moveLeft();
                rememberBreadCrumb();
            } else if (isOpenRight() && breadCrumbToTheRight() < breadcrumb) {
                moveRight();
                rememberBreadCrumb();
            } else if (isOpenBelow() && breadCrumbBelow() < breadcrumb) {
                moveDown();
{'fraction_non_alphanumeric': 0.11918379965991653, 'fraction_numerical': 0.004637501932292472, 'mean_word_length': 1.7614169867690994, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1124131', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1825, 'n_words': 594}