<commit_before>
"use strict";

//////////////////////////////////////////////////////////////////////////////////////////
function Cursor( x, y ) {
	this.x = x;
	this.y = y;
}
Cursor.prototype.add = function( cursor, y ) {
	if( cursor instanceof Cursor )
		return new Cursor( this.x+cursor.x, this.y+cursor.y );
	else return new Cursor(this.x+cursor, this.y+y);
}
Cursor.prototype.minus = function( cursor ) {
	return new Cursor( this.x - cursor.x, this.y-cursor.y);
}
Cursor.prototype.isEqualTo = function( cursor ) {
	return this.x == cursor.x && this.y == cursor.y;
}

//////////////////////////////////////////////////////////////////////////////////////////
function Grid( width, height ) {
	this.width = width;
	this.height = height;
	this.grid = new Array( width * height );
	for( var i = 0; i < this.grid.length; i++ )
		this.grid[i] = " ";
}

Grid.prototype.toString = function() {
	var str = "";
	for(var i = 0; i < this.height; i++) {
		for(var j = 0; j < this.width; j++)
			str += this.grid[j + i*this.width] || " ";
		if(i<this.height-1) str += "\n";
	}
	return str;
}

Grid.prototype.set = function( cursor, ch ) {
	this.grid[ cursor.x + cursor.y*this.width ] = ch[0];
}
Grid.prototype.get = function( cursor ) {
	return this.grid[ cursor.x + cursor.y*this.width ];
}
Grid.prototype.isInside = function( cursor ) {
	return cursor.x >= 0 && cursor.x < this.width &&
		cursor.y >= 0 && cursor.y < this.height;
}
Grid.prototype.look = function( character ) {
	var ret = [];
	this.grid.forEach(function(char, index) {
		if( char === character )
			ret.push( new Cursor( index % this.width, Math.floor( index/this.width ) ) );
	}, this);
	return ret;
}
Grid.prototype.write = function( cursor, text ) {
	for( var i = 0; i < text.length; i++ )
		this.set(cursor.add( new Cursor(i, 0) ), text[i]);
}

//////////////////////////////////////////////////////////////////////////////////////////
function Character( grid, cursor, ch ) {
	grid.set(cursor, ch);
	this.grid = grid;
	this.cursor = cursor;
	this.char = ch;
}
Character.prototype.erase = function() {
	this.grid.set(this.cursor, " ");
}
Character.prototype.write = function() {
	this.grid.set(this.cursor, this.char);
}
Character.prototype.move = function( cursor ) {
	if(this.freeze) return false;
	var newCurs =  this.cursor.add( cursor );
	if( this.grid.isInside( newCurs )
		&& this.onCollide(this.grid.get(newCurs), newCurs) ) {
		this.erase();
		this.cursor = newCurs;
		this.write();
	}
}
Character.prototype.onCollide = function() { return true; };

//////////////////////////////////////////////////////////////////////////////////////////
function Map( sketch ) {
	this.grid = new Grid(sketch[0].length, sketch.length);
	sketch.forEach(function(line, y) {
		for(var x = 0; x < line.length; x++)
			this.grid.set( new Cursor(x,y), line[x] );
	}, this);
}
Map.prototype.toString = function() {
	return this.grid.toString();
}
Map.prototype.addCharacter = function(cursor, char) {
	return new Character(this.grid, cursor, char);
}

//////////////////////////////////////////////////////////////////////////////////////////
function Level( sketch ) {
	this.sketch = sketch;
	this.map = new Map(sketch);
	var stars = this.map.grid.look("⋆");
	if( stars[0].x > stars[1].x) {
		stars.push( stars.shift() );
	}
	this.player = this.map.addCharacter( this.map.grid.look("^")[0], "^" );
	this.mirror = this.map.addCharacter( this.map.grid.look("`")[0], "`" );
	this.player.star = this.map.addCharacter( stars[0], "⋆" );
	this.mirror.star = this.map.addCharacter( stars[1], "⋆" );
	
	var switches = [{
		"key": "▪",
		"door-locked": "■▶◀▮",
		"door-unlocked": "▬►◄◆"
	},{
		"key": "▫",
		"door-locked": "□",
		"door-unlocked": "▭"
	}];

	
	this.switches = [];
	
	// FILTRAR LA VARIABLE SWITCHES.
	switches.forEach(function(swch) {
		var arr = this.map.grid.look(swch.key);
		if( arr ) {
			swch.keyObjects = arr.map(function(cursor) {
				return this.map.addCharacter(cursor, swch.key);
			}, this);
			var doorObjects = [], doors = swch["door-locked"];
			for( var i = 0; i < doors.length; i++) {
				doorObjects = doorObjects.concat( this.map.grid.look(doors[i]).map(function(cursor) {
					var ret = this.map.addCharacter(cursor, swch["door-locked"][i]);
					ret.INDEX = i;
					return ret;
				}, this) );
			}
			swch.doorObjects = doorObjects;
			this.switches.push(swch);
		}
	}, this);
	
	var level = this;
	this.player.onCollide = function(char, pos) {
		if( "#|°¬&■▬▶◀▮".indexOf(char) != -1 ) {
			this.write();
			return false;
		} if(char=="%"||char=="-") {
			this.freeze = true;
			this.char = getDeadChar(this.char, char);
			level.status = -1;
			level.onStatusChange();
		}
		return true;
	}<commit_msg>walls mechanics<commit_after>
"use strict";

//////////////////////////////////////////////////////////////////////////////////////////
function Cursor( x, y ) {
	this.x = x;
	this.y = y;
}
Cursor.prototype.add = function( cursor, y ) {
	if( cursor instanceof Cursor )
		return new Cursor( this.x+cursor.x, this.y+cursor.y );
	else return new Cursor(this.x+cursor, this.y+y);
}
Cursor.prototype.minus = function( cursor ) {
	return new Cursor( this.x - cursor.x, this.y-cursor.y);
}
Cursor.prototype.isEqualTo = function( cursor ) {
	return this.x == cursor.x && this.y == cursor.y;
}

//////////////////////////////////////////////////////////////////////////////////////////
function Grid( width, height ) {
	this.width = width;
	this.height = height;
	this.grid = new Array( width * height );
	for( var i = 0; i < this.grid.length; i++ )
		this.grid[i] = " ";
}

Grid.prototype.toString = function() {
	var str = "";
	for(var i = 0; i < this.height; i++) {
		for(var j = 0; j < this.width; j++)
			str += this.grid[j + i*this.width] || " ";
		if(i<this.height-1) str += "\n";
	}
	return str;
}

Grid.prototype.set = function( cursor, ch ) {
	this.grid[ cursor.x + cursor.y*this.width ] = ch[0];
}
Grid.prototype.get = function( cursor ) {
	return this.grid[ cursor.x + cursor.y*this.width ];
}
Grid.prototype.isInside = function( cursor ) {
	return cursor.x >= 0 && cursor.x < this.width &&
		cursor.y >= 0 && cursor.y < this.height;
}
Grid.prototype.look = function( character ) {
	var ret = [];
	this.grid.forEach(function(char, index) {
		if( char === character )
			ret.push( new Cursor( index % this.width, Math.floor( index/this.width ) ) );
	}, this);
	return ret;
}
Grid.prototype.write = function( cursor, text ) {
	for( var i = 0; i < text.length; i++ )
		this.set(cursor.add( new Cursor(i, 0) ), text[i]);
}

//////////////////////////////////////////////////////////////////////////////////////////
function Character( grid, cursor, ch ) {
	grid.set(cursor, ch);
	this.grid = grid;
	this.cursor = cursor;
	this.char = ch;
}
Character.prototype.erase = function() {
	this.grid.set(this.cursor, " ");
}
Character.prototype.write = function() {
	this.grid.set(this.cursor, this.char);
}
Character.prototype.move = function( cursor ) {
	if(this.freeze) return false;
	var newCurs =  this.cursor.add( cursor );
	if( this.grid.isInside( newCurs )
		&& this.onCollide(this.grid.get(newCurs), newCurs) ) {
		this.erase();
		this.cursor = newCurs;
		this.write();
	}
}
Character.prototype.onCollide = function() { return true; };

//////////////////////////////////////////////////////////////////////////////////////////
function Map( sketch ) {
	this.grid = new Grid(sketch[0].length, sketch.length);
	sketch.forEach(function(line, y) {
		for(var x = 0; x < line.length; x++)
			this.grid.set( new Cursor(x,y), line[x] );
	}, this);
}
Map.prototype.toString = function() {
	return this.grid.toString();
}
Map.prototype.addCharacter = function(cursor, char) {
	return new Character(this.grid, cursor, char);
}

//////////////////////////////////////////////////////////////////////////////////////////
function Level( sketch ) {
	this.sketch = sketch;
	this.map = new Map(sketch);
	var stars = this.map.grid.look("⋆");
	if( stars[0].x > stars[1].x) {
		stars.push( stars.shift() );
	}
	this.player = this.map.addCharacter( this.map.grid.look("^")[0], "^" );
	this.mirror = this.map.addCharacter( this.map.grid.look("`")[0], "`" );
	this.player.star = this.map.addCharacter( stars[0], "⋆" );
	this.mirror.star = this.map.addCharacter( stars[1], "⋆" );
	
	var switches = [{
		"key": "▪",
		"door-locked": "■▶◀▮",
		"door-unlocked": "▬►◄◆"
	},{
		"key": "▫",
		"door-locked": "□",
		"door-unlocked": "▭"
	}];

	
	this.switches = [];
	
	// FILTRAR LA VARIABLE SWITCHES.
	switches.forEach(function(swch) {
		var arr = this.map.grid.look(swch.key);
		if( arr ) {
			swch.keyObjects = arr.map(function(cursor) {
				return this.map.addCharacter(cursor, swch.key);
			}, this);
			var doorObjects = [], doors = swch["door-locked"];
			for( var i = 0; i < doors.length; i++) {
				doorObjects = doorObjects.concat( this.map.grid.look(doors[i]).map(function(cursor) {
					var ret = this.map.addCharacter(cursor, swch["door-locked"][i]);
					ret.INDEX = i;
					return ret;
				}, this) );
			}
			swch.doorObjects = doorObjects;
			this.switches.push(swch);
		}
	}, this);
	
	var level = this;
	this.player.onCollide = function(char, pos) {
		if( "#|°¬&■▶◀▮".indexOf(char) != -1 ) {
			this.write();
			return false;
		} if(char=="%"||char=="-") {
			this.freeze = true;
			this.char = getDeadChar(this.char, char);
			level.status = -1;
			level.onStatusChange();
		}
		return true;
	}
{'fraction_non_alphanumeric': 0.27420215604653647, 'fraction_numerical': 0.004269399082079198, 'mean_word_length': 2.368080517613228, 'pattern_counts': {'":': 12, '<': 21, '<?xml version=': 0, '>': 9, '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': '3537859', 'n_tokens_mistral': 3456, 'n_tokens_neox': 3256, 'n_words': 681}