<commit_before>"use strict";
var Frame = require("./Frame");

const FRAMES_NUMBER = 10;

class Game {
    constructor() {
        this.currentFrame = 0;
        this.frames = [];
        for (var i=0; i<FRAMES_NUMBER; i++) {
            this.frames.push(new Frame());
        }
    }
    rollAll(framesListWithScores) {
        var framesArray = JSON.parse(framesListWithScores);
        return Array.isArray(framesArray);
    }
    roll(pins) {
        this.frames[this.currentFrame].roll(pins);
        if (this.frames[this.currentFrame].areFrameRollsFinished()) {
            this.currentFrame++;
        }
    }
    score() {
        let totalScore = 0;
        for (var i=0; i<FRAMES_NUMBER; i++) {
            totalScore += this.frames[i].score();
        }
        return totalScore;
    }
}

module.exports = Game;<commit_msg>Spares and Strikes are being counted properly, but only once the next frame has been completed. Thus, in the case of a spare, we should update the bonues once we roll the first ball of the next frame<commit_after>"use strict";
var Frame = require("./Frame");

const FRAMES_NUMBER = 10;

class Game {
    constructor() {
        this.currentFrame = 0;
        this.frames = [];
        for (var i=0; i<FRAMES_NUMBER; i++) {
            this.frames.push(new Frame());
        }
    }
    rollAll(framesListWithScores) {
        var framesArray = JSON.parse(framesListWithScores);
        return Array.isArray(framesArray);
    }
    roll(pins) {
        this.frames[this.currentFrame].roll(pins);
        if (this.frames[this.currentFrame].areFrameRollsFinished()) {
            if (this.currentFrame > 0) {
                let previousFrame = this.currentFrame - 1;
                if (this.frames[previousFrame].isSpare()) {
                    this.frames[previousFrame].bonus(this.frames[this.currentFrame].firstRoll)
                }
                else if (this.frames[previousFrame].isStrike()) {
                    this.frames[previousFrame].bonus(this.frames[this.currentFrame].firstRoll + this.frames[this.currentFrame].secondRoll)
                }
            }
            this.currentFrame++;
        }
    }
    score() {
        let totalScore = 0;
        for (var i=0; i<FRAMES_NUMBER; i++) {
            totalScore += this.frames[i].score();
        }
        return totalScore;
    }
}

module.exports = Game;
{'fraction_non_alphanumeric': 0.12436548223350254, 'fraction_numerical': 0.005922165820642978, 'mean_word_length': 2.128306878306878, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '2777161', 'n_tokens_mistral': 715, 'n_tokens_neox': 684, 'n_words': 145}