<commit_before>var Game = function(boardString) {
  if ( boardString.length !== 81 ) {
    throw "Invalid board string";
  }

  var i = 0;

  this.board = [];

  for (i; i<81; i++) {
    this.board.push(new Cell(boardString.charAt(i), i));
  }
};

Game.prototype = {
  solve: function() {
    while ( !this.isSolved() ){
      if ( !this.checkAllCells() ) {
        this.guessNextEmptyCell();
      }
    }
  },

  isSolved: function() {
    var emptyCellsFound = false,
    i = 0;

    while ( !emptyCellsFound && i<81 ) {
      if ( this.board[i].digit === "0" ) {
        return emptyCellsFound;
      }
      i++;
    }

    return !emptyCellsFound;
  },

  checkAllCells: function() {
    var i = 0,
    anyChanges = false;

    for (i; i<81; i++) {
      if( this.board[i].digit === "0" ) {
        if( this.findCellValue(i) ) {
          anyChanges = i;
        }
      }
    }

    return anyChanges;
  },

  guessNextEmptyCell: function() {
    var i = (this.hasOwnProperty("lastGuessedCell") ? this.lastGuessedCell : 0),
    possibleValues;

    for (i; i<81; i++) {
      if ( this.board[i].digit === "0" ) {
        possibleValues = this.buildPossibleValues(i);
        if ( possibleValues[0] === '' ) {
          this.clearGuesses();
        } else {
          this.board[i].guessNext(possibleValues);
          this.hasGuesses = true;
          this.lastGuessedCell = i;
          return;
        }
      } else if ( i === 80 ) {
        i = -1;
      }
    }
  },

  findCellValue: function(currentIndex) {
    var possibleValues = this.buildPossibleValues(currentIndex);

    if ( possibleValues.length === 1 ) {
      if ( possibleValues[0] === "" ) {
        this.clearGuesses();
        return;
      }
      this.board[currentIndex].digit = possibleValues[0];
      if ( this.hasOwnProperty("hasGuesses") ) {
        this.board[currentIndex].isGuess = true;
      }
      return this.board[currentIndex].digit;
    }
  },

  buildRelatedValues: function(currentIndex) {
    var i = 0,
        NUM_OF_RELATED_CELLS = 20,
        relatedValues = [];

    for(i; i<NUM_OF_RELATED_CELLS; i++) {
      if ( this.board[this.board[currentIndex].relatedCells[i]].digit !== "0" ) {
        relatedValues.push( this.board[this.board[currentIndex].relatedCells[i]].digit );
      }
    }

    return util.flattenAndUniq(relatedValues).sort();
  },

  buildPossibleValues: function(currentIndex) {
    var POSSIBLE_VALUES = ["1","2","3","4","5","6","7","8","9"],
        relatedValues = this.buildRelatedValues(currentIndex);

    return util.diffArrays(POSSIBLE_VALUES, relatedValues);
  },

  clearGuesses: function() {
    var i = 0;

    for (i; i<81; i++) {
      if ( this.board[i].hasOwnProperty("isGuess") ) {
        this.board[i].digit = "0";
        delete this.board[i].isGuess;
      }
    }

    delete this.hasGuesses;
  },
};

var Cell = function(digit, index) {
  this.digit = digit;
  this.index = index;
  this.getRelatedCellIndeces();<commit_msg>Change constructors from global var to function syntax<commit_after>function Game(boardString) {
  if ( boardString.length !== 81 ) {
    throw "Invalid board string";
  }

  var i = 0;

  this.board = [];

  for (i; i<81; i++) {
    this.board.push(new Cell(boardString.charAt(i), i));
  }
};

Game.prototype = {
  solve: function() {
    while ( !this.isSolved() ){
      if ( !this.checkAllCells() ) {
        this.guessNextEmptyCell();
      }
    }
  },

  isSolved: function() {
    var emptyCellsFound = false,
    i = 0;

    while ( !emptyCellsFound && i<81 ) {
      if ( this.board[i].digit === "0" ) {
        return emptyCellsFound;
      }
      i++;
    }

    return !emptyCellsFound;
  },

  checkAllCells: function() {
    var i = 0,
    anyChanges = false;

    for (i; i<81; i++) {
      if( this.board[i].digit === "0" ) {
        if( this.findCellValue(i) ) {
          anyChanges = i;
        }
      }
    }

    return anyChanges;
  },

  guessNextEmptyCell: function() {
    var i = (this.hasOwnProperty("lastGuessedCell") ? this.lastGuessedCell : 0),
    possibleValues;

    for (i; i<81; i++) {
      if ( this.board[i].digit === "0" ) {
        possibleValues = this.buildPossibleValues(i);
        if ( possibleValues[0] === '' ) {
          this.clearGuesses();
        } else {
          this.board[i].guessNext(possibleValues);
          this.hasGuesses = true;
          this.lastGuessedCell = i;
          return;
        }
      } else if ( i === 80 ) {
        i = -1;
      }
    }
  },

  findCellValue: function(currentIndex) {
    var possibleValues = this.buildPossibleValues(currentIndex);

    if ( possibleValues.length === 1 ) {
      if ( possibleValues[0] === "" ) {
        this.clearGuesses();
        return;
      }
      this.board[currentIndex].digit = possibleValues[0];
      if ( this.hasOwnProperty("hasGuesses") ) {
        this.board[currentIndex].isGuess = true;
      }
      return this.board[currentIndex].digit;
    }
  },

  buildRelatedValues: function(currentIndex) {
    var i = 0,
        NUM_OF_RELATED_CELLS = 20,
        relatedValues = [];

    for(i; i<NUM_OF_RELATED_CELLS; i++) {
      if ( this.board[this.board[currentIndex].relatedCells[i]].digit !== "0" ) {
        relatedValues.push( this.board[this.board[currentIndex].relatedCells[i]].digit );
      }
    }

    return util.flattenAndUniq(relatedValues).sort();
  },

  buildPossibleValues: function(currentIndex) {
    var POSSIBLE_VALUES = ["1","2","3","4","5","6","7","8","9"],
        relatedValues = this.buildRelatedValues(currentIndex);

    return util.diffArrays(POSSIBLE_VALUES, relatedValues);
  },

  clearGuesses: function() {
    var i = 0;

    for (i; i<81; i++) {
      if ( this.board[i].hasOwnProperty("isGuess") ) {
        this.board[i].digit = "0";
        delete this.board[i].isGuess;
      }
    }

    delete this.hasGuesses;
  },
};

function Cell(digit, index) {
  this.digit = digit;
  this.index = index;
  this.getRelatedCellIndeces();
{'fraction_non_alphanumeric': 0.15860799732307176, 'fraction_numerical': 0.013719257152417601, 'mean_word_length': 2.365990990990991, 'pattern_counts': {'":': 0, '<': 15, '<?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': '856974', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2000, 'n_words': 352}