<commit_before>var directions = [ 'N', 'S', 'E', 'W' ];

function ScoreCalculator( board ) {
	this.board = board;
	this.boardSize = board.getSize();
}

ScoreCalculator.prototype.scoreFor = function( row, col ) {
	var adjacentTilesToCheck = this.board.getAdjacentTiles( row, col ),
		centerTile = adjacentTilesToCheck.C,
		shapeScore, colorScore;
	this.tilesCounted = 0;
	shapeScore = this._countShapeScore( centerTile, adjacentTilesToCheck, [ centerTile ], 1 );
	this.tilesCounted = 0;
	colorScore = this._countColorScore( centerTile, adjacentTilesToCheck, [ centerTile ], 1 );
	return shapeScore + colorScore;
};

ScoreCalculator.prototype._countShapeScore = function ( comparisonTile, adjacentTiles, countedTiles, score ) {
	var direction, currentTile, adjacentTilesToCheck;

	// should never happen
	if( this.tilesCounted > this.boardSize ) { 
		throw Error( 'Recursion error, now you\'re in trouble' );
	}

	for ( direction in directions ) {
		currentTile = adjacentTiles[ directions[ direction ] ];
		if ( currentTile === null || countedTiles.indexOf( currentTile ) > -1 ) {
			continue;
		}
		this.tilesCounted += 1;
		if ( comparisonTile.sameShape( currentTile ) ) {
			score += 1;
			countedTiles.push( currentTile );
			adjacentTilesToCheck = this.board.getAdjacentTiles( currentTile.row, currentTile.col );
			score = this._countShapeScore( comparisonTile, adjacentTilesToCheck, countedTiles, score );
		}
	}
	return score;
}

ScoreCalculator.prototype._countColorScore = function ( comparisonTile, adjacentTiles, countedTiles, score ) {
	var direction, currentTile, adjacentTilesToCheck;

	// should never happen
	if( this.tilesCounted > this.boardSize ) { 
		throw Error( 'Recursion error, now you\'re in trouble' );
	}

	for ( direction in directions ) {
		currentTile = adjacentTiles[ directions[ direction ] ];
		if ( currentTile === null || countedTiles.indexOf( currentTile ) > -1 ) {
			continue;
		}
		this.tilesCounted += 1;
		if ( comparisonTile.sameColor( currentTile ) ) {
			score += 1;
			countedTiles.push( currentTile );
			adjacentTilesToCheck = this.board.getAdjacentTiles( currentTile.row, currentTile.col );
			score = this._countShapeScore( comparisonTile, adjacentTilesToCheck, countedTiles, score );
		}
	}
	return score;
}


module.exports = ScoreCalculator;<commit_msg>Refactor ScoreCalculator<commit_after>var directions = [ 'N', 'S', 'E', 'W' ];

function ScoreCalculator( board ) {
	this.board = board;
	this.boardSize = board.getSize();
}

ScoreCalculator.prototype.scoreFor = function( row, col ) {
	var adjacentTilesToCheck = this.board.getAdjacentTiles( row, col ),
		centerTile = adjacentTilesToCheck.C,
		shapeScore, colorScore;
	this.tilesCounted = 0;
	shapeScore = this._countScore( centerTile, adjacentTilesToCheck, [ centerTile ], 1, "sameShape" );
	this.tilesCounted = 0;
	colorScore = this._countScore( centerTile, adjacentTilesToCheck, [ centerTile ], 1, "sameColor" );
	return shapeScore + colorScore;
};

ScoreCalculator.prototype._countScore = function ( comparisonTile, adjacentTiles, countedTiles, score, comparisonMethod ) {
	var direction, currentTile, adjacentTilesToCheck;

	// should never happen
	if( this.tilesCounted > this.boardSize ) { 
		throw Error( 'Recursion error, now you\'re in trouble' );
	}

	for ( direction in directions ) {
		currentTile = adjacentTiles[ directions[ direction ] ];
		if ( currentTile === null || countedTiles.indexOf( currentTile ) > -1 ) {
			continue;
		}
		this.tilesCounted += 1;
		if ( comparisonTile[ comparisonMethod ]( currentTile ) ) {
			score += 1;
			countedTiles.push( currentTile );
			adjacentTilesToCheck = this.board.getAdjacentTiles( currentTile.row, currentTile.col );
			score = this._countScore( comparisonTile, adjacentTilesToCheck, countedTiles, score, comparisonMethod );
		}
	}
	return score;
}

module.exports = ScoreCalculator;
{'fraction_non_alphanumeric': 0.11636363636363636, 'fraction_numerical': 0.004415584415584416, 'mean_word_length': 4.705185185185186, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5272196', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1201, 'n_words': 279}