<commit_before>(function (angular) {
    'use strict';

    angular.module('squares').factory('gameService', ['$interval', '$timeout', 'colorService', 'squareService',
        function ($interval, $timeout, colorService, squareService) {
            var gameServiceInstance;

            gameServiceInstance = {
                _:{
                    squares: null,
                    retryCount: 0,
                    intervalId: null,
                    streakData: { Count: 0, Text: 'Wins', LastGameWon: false },
                    colorCounts: {},
                    colorProvider: colorService.SimpleColors,
                    initialSeconds: 8,

                    getSquares: function (colorCounts, colorProvider) {
                        var squareRows = [];

                        for (var row = 0; row < 8; row++) {
                            var rowArray = [];
                            for (var col = 0; col < 8; col++) {
                                var color,
                                    colorId,
                                    colorIndex;

                                colorIndex = Math.round(Math.random() * colorProvider.Max);
                                color = colorProvider.GetColor(colorIndex);
                                colorId = color.GetColorId();

                                if (!colorCounts[colorId]) {
                                    colorCounts[colorId] = 0;
                                }
                                colorCounts[colorId]++;

                                rowArray.push(squareService.GetSquare(50, color));
                            }
                            squareRows.push(rowArray)
                        }
                        return squareRows;
                    },

                    getSecondScore:  function (gameMode) {
                        var result = 0;
                        switch (gameMode) {
                            case gameServiceInstance.GameModes.Simple:
                                result = 1000;
                                break;
                            case gameServiceInstance.GameModes.Medium:
                                result = 1500;
                                break;
                            case gameServiceInstance.GameModes.Hard:
                                result = 2500;
                                break;
                            case gameServiceInstance.GameModes.VeryHard:
                                result = 5000;
                                break;
                        }
                        return result;
                    },

                    getCurrentStreak : function (gameWon, streakData) {
                        if (gameWon) {
                            if (streakData.LastGameWon) {
                                streakData.Count++;
                                if (streakData.Count === 1) {
                                    streakData.Text = 'Win';
                                }
                                else {
                                    streakData.Text = 'Wins';
                                }
                            }
                            else {
                                streakData.Count = 1;
                                streakData.Text = 'Win';
                            }

                            streakData.LastGameWon = true;
                        }
                        else {
                            if (!streakData.LastGameWon) {
                                streakData.Count++;
                                if (streakData.Count === 1) {
                                    streakData.Text = 'Loss';
                                }
                                else {
                                    streakData.Text = 'Losses';
                                }
                            }
                            else {
                                streakData.Count = 1;
                                streakData.Text = 'Loss';
                            }
                            streakData.LastGameWon = false;
                        }

                        return streakData.Count + ' ' + streakData.Text;
                    },

                    scoreGame: function (chosenSquare, colorCounts, gameMode, seconds, retryCount) {
                        var result = {
                            gameWon : false,
                            score : 0
                        };

                        if (!(null === chosenSquare || undefined === chosenSquare)) {

                            var gameWon = true,
                                chosenColorId = chosenSquare.Color.GetColorId();


                            for(var colorId in colorCounts){
                               if (colorCounts.hasOwnProperty(colorId)
                                   && colorId !== chosenColorId
                                   && colorCounts[colorId] > colorCounts[chosenColorId]) {

                                    gameWon = false;
                                    break;
                                }
                            }

                            if (gameWon){
                                var scoreMod = gameServiceInstance._.getSecondScore(gameMode);
                                var score = scoreMod * seconds;
                                if (retryCount > 0) {
                                    score = Math.round(score / (retryCount + 1));
                                }
                                result.gameWon = true;
                                result.score =  score;
                            }
                        }

                        return result;
                    },

                    initGame : function(initialSeconds){
                        gameServiceInstance.OutcomeText = '';
                        gameServiceInstance.LastGameWon = false;
                        gameServiceInstance.GameStarted = true;
                        gameServiceInstance.Seconds = initialSeconds;
                        gameServiceInstance.GameOver = false;
                        gameServiceInstance.SelectedColor = null;
                    },

                    cancelCountDown: function (intervalId) {
                        if(null !== intervalId){
                            try {
                                $interval.cancel(intervalId);
                                intervalId = null;
                            }
                            catch (e) {
                                console.log('Failed to cancel intervalId [' + intervalId + '] ' + e);
                            }
                        }
                    },

                    countDown: function () {
                        var intervalId;

                        intervalId = $interval(function () {
                            gameServiceInstance.Seconds--;
                            if (gameServiceInstance.Seconds <= 0) {<commit_msg>fixing scoring<commit_after>(function (angular) {
    'use strict';

    angular.module('squares').factory('gameService', ['$interval', '$timeout', 'colorService', 'squareService',
        function ($interval, $timeout, colorService, squareService) {
            var gameServiceInstance;

            gameServiceInstance = {
                _:{
                    squares: null,
                    retryCount: 0,
                    intervalId: null,
                    streakData: { Count: 0, Text: 'Wins', LastGameWon: false },
                    colorCounts: {},
                    colorProvider: colorService.SimpleColors,
                    initialSeconds: 8,

                    getSquares: function (colorCounts, colorProvider) {
                        var squareRows = [];

                        for (var row = 0; row < 8; row++) {
                            var rowArray = [];
                            for (var col = 0; col < 8; col++) {
                                var color,
                                    colorId,
                                    colorIndex;

                                colorIndex = Math.round(Math.random() * colorProvider.Max);
                                color = colorProvider.GetColor(colorIndex);
                                colorId = color.GetColorId();

                                if (!colorCounts[colorId]) {
                                    colorCounts[colorId] = 0;
                                }
                                colorCounts[colorId]++;

                                rowArray.push(squareService.GetSquare(50, color));
                            }
                            squareRows.push(rowArray)
                        }
                        return squareRows;
                    },

                    getSecondScore:  function (gameMode) {
                        var result = 0;
                        switch (gameMode) {
                            case gameServiceInstance.GameModes.Simple:
                                result = 1000;
                                break;
                            case gameServiceInstance.GameModes.Medium:
                                result = 1500;
                                break;
                            case gameServiceInstance.GameModes.Hard:
                                result = 2500;
                                break;
                            case gameServiceInstance.GameModes.VeryHard:
                                result = 5000;
                                break;
                        }
                        return result;
                    },

                    getCurrentStreak : function (gameWon, streakData) {
                        if (gameWon) {
                            if (streakData.LastGameWon) {
                                streakData.Count++;
                                if (streakData.Count === 1) {
                                    streakData.Text = 'Win';
                                }
                                else {
                                    streakData.Text = 'Wins';
                                }
                            }
                            else {
                                streakData.Count = 1;
                                streakData.Text = 'Win';
                            }

                            streakData.LastGameWon = true;
                        }
                        else {
                            if (!streakData.LastGameWon) {
                                streakData.Count++;
                                if (streakData.Count === 1) {
                                    streakData.Text = 'Loss';
                                }
                                else {
                                    streakData.Text = 'Losses';
                                }
                            }
                            else {
                                streakData.Count = 1;
                                streakData.Text = 'Loss';
                            }
                            streakData.LastGameWon = false;
                        }

                        return streakData.Count + ' ' + streakData.Text;
                    },

                    scoreGame: function (chosenSquare, colorCounts, gameMode, seconds, retryCount) {
                        var result = {
                            gameWon : false,
                            score : 0
                        };

                        if (!(null === chosenSquare || undefined === chosenSquare)) {

                            var gameWon = true,
                                chosenColorId = chosenSquare.Color.GetColorId();


                            for(var colorId in colorCounts){
                               if (colorCounts.hasOwnProperty(colorId)
                                   && colorId !== chosenColorId
                                   && colorCounts[colorId] > colorCounts[chosenColorId]) {

                                    gameWon = false;
                                    break;
                                }
                            }

                            if (gameWon){
                                var scoreMod = gameServiceInstance._.getSecondScore(gameMode);
                                var score = scoreMod * seconds;
                                if (retryCount > 0) {
                                    score = Math.round(score / (retryCount + 1));
                                }
                                result.gameWon = true;
                                result.score =  score;
                            }
                        }

                        return result;
                    },

                    initGame : function(initialSeconds){
                        gameServiceInstance._.colorCounts = {};
                        gameServiceInstance.OutcomeText = '';
                        gameServiceInstance.LastGameWon = false;
                        gameServiceInstance.GameStarted = true;
                        gameServiceInstance.Seconds = initialSeconds;
                        gameServiceInstance.GameOver = false;
                        gameServiceInstance.SelectedColor = null;
                    },

                    cancelCountDown: function (intervalId) {
                        if(null !== intervalId){
                            try {
                                $interval.cancel(intervalId);
                                intervalId = null;
                            }
                            catch (e) {
                                console.log('Failed to cancel intervalId [' + intervalId + '] ' + e);
                            }
                        }
                    },

                    countDown: function () {
                        var intervalId;

                        intervalId = $interval(function () {
                            gameServiceInstance.Seconds--;
                            if (gameServiceInstance.Seconds <= 0) {
{'fraction_non_alphanumeric': 0.06916954286116785, 'fraction_numerical': 0.004930619144889766, 'mean_word_length': 0.6662363572350664, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '802253', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2668, 'n_words': 506}