<commit_before>"use strict";

function Robot() {
	this.x = null;
	this.y = null;
	this.orientation = null;
	this.maze = null;
}

Robot.prototype.setMaze = function(maze) {
	this.maze = maze;
	this.x = maze.startX;
	this.y = maze.startY;
	this.orientation = maze.startOrientation;
};

Robot.prototype.turnRight = function() {
	if(!this.maze || !this.maze.isValidDirection(this.orientation)) {
		return false;
	}
	var rights = {
		north: "east",
		east: "south",
		south: "west",
		west: "north"
	}
	this.orientation = rights[this.orientation];
	return true;
}

Robot.prototype.turnLeft = function() {
	if(!this.maze || !this.maze.isValidDirection(this.orientation)) {
		return false;
	}
	var lefts = {
		north: "west",
		east: "north",
		south: "east",
		west: "south"
	}
	this.orientation = lefts[this.orientation];
	return true;
}

Robot.prototype.moveForward = function() {
	if(!this.canMoveForward()) {
		return false;
	}

	switch (this.orientation) {
		case "north":
			this.y += 1;
			break;
		case "east":
			this.x += 1;
			break;
		case "south":
			this.y -= 1;
			break;
		case "west":
			this.x -= 1;
			break;

	}
	return true;
}

Robot.prototype.canMoveForward = function() {
	if(!this.maze) {
		return false;
	}

	return this.maze.canMove(this.x, this.y, this.orientation);
}<commit_msg>added algorithm to have the robot move to the end of the maze by following the left wall<commit_after>"use strict";

function Robot() {
	this.x = null;
	this.y = null;
	this.orientation = null;
	this.maze = null;
}

Robot.prototype.setMaze = function(maze) {
	this.maze = maze;
	this.x = maze.startX;
	this.y = maze.startY;
	this.orientation = maze.startOrientation;
};

Robot.prototype.turnRight = function() {
	if(!this.maze || !this.maze.isValidDirection(this.orientation)) {
		return false;
	}
	var rights = {
		north: "east",
		east: "south",
		south: "west",
		west: "north"
	}
	this.orientation = rights[this.orientation];
	return true;
}

Robot.prototype.turnLeft = function() {
	if(!this.maze || !this.maze.isValidDirection(this.orientation)) {
		return false;
	}
	var lefts = {
		north: "west",
		east: "north",
		south: "east",
		west: "south"
	}
	this.orientation = lefts[this.orientation];
	return true;
}

Robot.prototype.moveForward = function() {
	if(!this.canMoveForward()) {
		return false;
	}

	switch (this.orientation) {
		case "north":
			this.y += 1;
			break;
		case "east":
			this.x += 1;
			break;
		case "south":
			this.y -= 1;
			break;
		case "west":
			this.x -= 1;
			break;
	}

	return true;
}

Robot.prototype.canMoveForward = function() {
	if(!this.maze) {
		return false;
	}

	return this.maze.canMove(this.x, this.y, this.orientation);
}

Robot.prototype.exitMaze = function(steps) {
	if(this.maze) {
		while(steps != 0) {
			steps -= 1;
			if(this.canMoveForward()) {
				this.moveForward();
				this.turnLeft();
			} else { 
				this.turnRight();
			}
			if(this.x === this.maze.endX && this.y === this.maze.endY) {
				return true;
			}
		}
		return false;
	}
}
{'fraction_non_alphanumeric': 0.16522318454363757, 'fraction_numerical': 0.0033311125916055963, 'mean_word_length': 3.3521739130434782, 'pattern_counts': {'":': 8, '<': 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': '7336311', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1144, 'n_words': 237}