<commit_before>/*********************************************************\
* Structural definition of the game                       *
\*********************************************************/

function Game(width, height, rate)
{
	this.paused = false;
	width = width || 100;
	height = height || 100;
	this.rect = new Rectangle(0, 0, width, height);
	this.levels = [new Level('')];

	this.level = this.levels[0].clone();
	this.paused = true;
	this.score = 0;
	this.slices = [];
	this.rate = rate || 1000;
}

Game.prototype.addLevel = function addLevel(def)
{
	if (!def.constructor == Level)
		throw new TypeError();
	this.levels.push(def);
}

Game.prototype.start = function start(level)
{
	this.pause();
	this.level = this.levels[level].clone();
	this.resume();
}

Game.prototype.pause = function pause()
{
	if (this.paused) return;
	this.paused = true;
	clearInterval(this.interval);
}

Game.prototype.resume = function resume()
{
	if (!this.paused) return;
	this.paused = false;
	this.interval = setInterval(this.update.bind(this), this.rate);
}

Game.prototype.slice = function slice(line)
{
	this.slices.push(new Slice(line, this.rect.shrink(-10)));
}

Game.prototype.update = function update()
{
	if(this.paused) return;
	for (var i = 0, l = this.level.entities.length, ent; i < l; ++i)
	{
		ent = this.level.entities[i];
		ent.behavior.update.call(ent, this.rate);
	}

	for (var i = 0, l = this.level.goals.length; i < l; ++i)
		if (this.level.goals[i].check())
			; // Todo: do something
}

//------------------------------------------------------------------------------

function Level(name)
{<commit_msg>added game win stub<commit_after>/*********************************************************\
* Structural definition of the game                       *
\*********************************************************/

function Game(width, height, rate)
{
	this.paused = false;
	width = width || 100;
	height = height || 100;
	this.rect = new Rectangle(0, 0, width, height);
	this.levels = [new Level('')];

	this.level = this.levels[0].clone();
	this.paused = true;
	this.score = 0;
	this.slices = [];
	this.rate = rate || 1000;
}

Game.prototype.addLevel = function addLevel(def)
{
	if (!def.constructor == Level)
		throw new TypeError();
	this.levels.push(def);
}

Game.prototype.start = function start(level)
{
	this.pause();
	this.level = this.levels[level].clone();
	if (level + 1 < this.levels.length)
		this.level.next = level + 1;
	this.resume();
}

Game.prototype.pause = function pause()
{
	if (this.paused) return;
	this.paused = true;
	clearInterval(this.interval);
}

Game.prototype.resume = function resume()
{
	if (!this.paused) return;
	this.paused = false;
	this.interval = setInterval(this.update.bind(this), this.rate);
}

Game.prototype.slice = function slice(line)
{
	this.slices.push(new Slice(line, this.rect.shrink(-10)));
}

Game.prototype.update = function update()
{
	if(this.paused) return;
	for (var i = 0, l = this.level.entities.length, ent; i < l; ++i)
	{
		ent = this.level.entities[i];
		ent.behavior.update.call(ent, this.rate);
	}

	for (var i = 0, l = this.level.goals.length; i < l; ++i)
		if (this.level.goals[i].check())
			this.win();
}

Game.prototype.win = function win()
{
	// Todo: do something
	if (this.level.next)
		this.start(this.level.next);
}

//------------------------------------------------------------------------------

function Level(name)
{
{'fraction_non_alphanumeric': 0.26750659244066805, 'fraction_numerical': 0.011133899794901847, 'mean_word_length': 3.1838235294117645, 'pattern_counts': {'":': 0, '<': 8, '<?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': '3235792', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1135, 'n_words': 247}