<commit_before>
function point(x, y) {
    return {
        x: x,
        y: y
    };
}

function Rover(args) {
    this.x = 0;
    this.y = 0;
    this.direction = 0;
    if (args) {
        this.planetCircumference = args.planetCircumference || 7232000;
        this.obstacles = args.obstacles || [];
    } else {
        this.planetCircumference = 7232000; // the real circumference of Pluto
        this.obstacles = [];
    }
}

Rover.prototype.move = function(instructions) {
    instructions = instructions.split('');
    var obstacleEncountered = false;
    instructions.forEach(function(instruction) {
        if (obstacleEncountered) {
            console.log('returning');
            return;
        }
        var oldX = this.x;
        var oldY = this.y;
        switch (instruction) {
            case 'F':
                this.moveForward();
                break;
            case 'B':
                this.moveBackward();
                break;
            case 'R':
                this.direction = (this.direction + 1) % 4;
                break;
            case 'L':
                this.direction = (this.direction - 1 + 4) % 4;
        }
        obstacleEncountered = this.obstacles.some(function(obstacle) {
            return obstacle.x === this.x &&
                obstacle.y === this.y;
        }.bind(this));
        if (obstacleEncountered) {
            console.log('encountered');
            this.x = oldX;
            this.y = oldY;
        }
        console.log(obstacleEncountered);
    }.bind(this));
};

Rover.prototype.getPosition = function() {
    return point(this.x, this.y);
};

Rover.prototype.getDirection = function() {
    switch (this.direction) {
        case 0:
            return 'N';
        case 1:
            return 'E';
        case 2:
            return 'S';
        case 3:
            return 'W';
    };
};

Rover.prototype.moveBackward = function() {
    this.move('RR');
    this.moveForward();
    this.move('LL');
};

Rover.prototype.moveForward = function() {
    var circumference = this.planetCircumference;
    var xMax = Math.floor(circumference / 2);
    var yMax = Math.floor(circumference / 2);
    var xMin = Math.floor((circumference - 1) / 2) || 0;
    var yMin = Math.floor((circumference - 1) / 2) || 0;
    switch (this.direction) {
        case 0:
            if (this.y === yMax) {
                this.y = yMin;
            } else {
                this.y += 1;
            }
            break;
        case 1:
            if (this.x === xMax) {
                this.x = xMin;
            } else {
                this.x += 1;
            }
            break;
        case 2:
            if (this.y === yMin) {
                this.y = yMax;
            } else {
                this.y -= 1;
            }
            break;
        case 3:
            if (this.x === xMin) {
                this.x = xMax;
            } else {
                this.x -= 1;
            }
            break;
    }
};

module.exports = {
    Rover: Rover,
    point: point
};
<commit_msg>Added some comments for clarity<commit_after>// A cleaner way of writing a point, instead of {x: x, y: y} every time
function point(x, y) {
    return {
        x: x,
        y: y
    };
}

// args:
// planetCircumference: the circumference for the rover to travel around
// obstacles: A list of points relating to obstacles on the planet
function Rover(args) {
    this.x = 0;
    this.y = 0;
    this.direction = 0;
    if (args) {
        this.planetCircumference = args.planetCircumference || 7232000;
        this.obstacles = args.obstacles || [];
    } else {
        this.planetCircumference = 7232000; // the real circumference of Pluto
        this.obstacles = [];
    }
}

// moves the rover as per the spec
Rover.prototype.move = function(instructions) {
    instructions = instructions.split('');
    var obstacleEncountered = false;
    instructions.forEach(function(instruction) {
        if (obstacleEncountered) {
            console.log('returning');
            return;
        }
        var oldX = this.x;
        var oldY = this.y;
        switch (instruction) {
            case 'F':
                this.moveForward();
                break;
            case 'B':
                this.moveBackward();
                break;
            case 'R':
                this.direction = (this.direction + 1) % 4;
                break;
            case 'L':
                this.direction = (this.direction - 1 + 4) % 4;
        }
        obstacleEncountered = this.obstacles.some(function(obstacle) {
            return obstacle.x === this.x &&
                obstacle.y === this.y;
        }.bind(this));
        if (obstacleEncountered) {
            this.x = oldX;
            this.y = oldY;
        }
        console.log(obstacleEncountered);
    }.bind(this));
};

Rover.prototype.getPosition = function() {
    return point(this.x, this.y);
};

Rover.prototype.getDirection = function() {
    switch (this.direction) {
        case 0:
            return 'N';
        case 1:
            return 'E';
        case 2:
            return 'S';
        case 3:
            return 'W';
    };
};

Rover.prototype.moveBackward = function() {
    this.move('RR');
    this.moveForward();
    this.move('LL');
};

Rover.prototype.moveForward = function() {
    var circumference = this.planetCircumference;
    var xMax = Math.floor(circumference / 2);
    var yMax = Math.floor(circumference / 2);
    var xMin = Math.floor((circumference - 1) / 2) || 0;
    var yMin = Math.floor((circumference - 1) / 2) || 0;
    switch (this.direction) {
        case 0:
            if (this.y === yMax) {
                this.y = yMin;
            } else {
                this.y += 1;
            }
            break;
        case 1:
            if (this.x === xMax) {
                this.x = xMin;
            } else {
                this.x += 1;
            }
            break;
        case 2:
            if (this.y === yMin) {
                this.y = yMax;
            } else {
                this.y -= 1;
            }
            break;
        case 3:
            if (this.x === xMin) {
                this.x = xMax;
            } else {
                this.x -= 1;
            }
            break;
    }
};

module.exports = {
    Rover: Rover,
    point: point
};

{'fraction_non_alphanumeric': 0.12652029695150846, 'fraction_numerical': 0.013268046122255567, 'mean_word_length': 1.360924683072334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6906656', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1900, 'n_words': 442}