<commit_before>'use strict';

// GLOBAL VAR INIT =====

// size of the grid
var gridSize = 16;
// tiles remaining after clicked
var tilesRemain = gridSize;
// the total number of turns for the entire game
var startTurns = gridSize * 2;
// array of flipped Tiles
var flipped = [];


// OBJ CONSTRUCTOR =====

// per player
function Player (name){
  this.name = name;
  this.turns = startTurns;
  this.points = 0;
}

// per tile
function Tile(path){
  this.path = 'temp/' + path;
  this.active = true;
}

// construct Player
var currentPlayer = new Player('<NAME>');

// init array of tiles
var sortedTiles = [
  new Tile('kitten_01.jpg'),
  new Tile('kitten_02.jpg'),
  new Tile('kitten_03.jpg'),
  new Tile('kitten_04.jpg'),
  new Tile('kitten_05.jpg'),
  new Tile('kitten_06.jpg'),
  new Tile('kitten_07.jpg'),
  new Tile('kitten_08.jpg'),
  new Tile('kitten_01.jpg'),
  new Tile('kitten_02.jpg'),
  new Tile('kitten_03.jpg'),
  new Tile('kitten_04.jpg'),
  new Tile('kitten_05.jpg'),
  new Tile('kitten_06.jpg'),
  new Tile('kitten_07.jpg'),
  new Tile('kitten_08.jpg')
];

// shuffle the array of tiles
var randomTiles = shuffle(sortedTiles.slice(0));

// FUNCTIONS =====

// returns tile object
function tile(elementId){
  // error handling
  if(elementId.length < 4){
    return null;
  } else {
    console.log(randomTiles[parseInt(elementId.slice(4) - 1)]);
    return randomTiles[parseInt(elementId.slice(4) - 1)];
  }
}

// checks to see if tiles are matching
function checkMatch(){
  // checks flipped array to see if tiles are matching
  if(tile(flipped[0]).path == tile(flipped[1]).path){
    // iterate points to current player
    addPoints();
    // if match is found
    matchFound(flipped[0]);
    matchFound(flipped[1]);
  } else {
    // finally call flipTile on both elements
    flipTile(flipped[1]);
    flipTile(flipped[0]);
  }

  // clear array of flipped elements
  clearFlippedArray();
  // remove turn from current Player
  removeTurn();
  // check if game is over
  checkGameOver();
}


// if match is found
function matchFound(elementId){
  var clickedTile = document.getElementById(elementId);
  // subtract from remaining tiles
  tilesRemain --;
  // deactivates tile
  tile(elementId).active = false;
  // TODO: visual cue of deactivated state ie opacity for now
  clickedTile.setAttribute('style', 'opacity: 0.25');
}

// CRUD Functions =====

function createOrUpdatePlayerInfo () {
  var stringifiedPlayerInfo = JSON.stringify(currentPlayer);
  localStorage.setItem('player', stringifiedPlayerInfo);
}

function retrievePlayerInfo () {
  var stringifiedPlayerInfo = localStorage.getItem('player');
}

function deletePlayerInfo () {
  localStorage.clear();
}

// HELPER FUNCTIONS =====

// modeled after Fisher-Yates Shuffle in https://bost.ocks.org/mike/shuffle/
// shuffles the sortedTiles array to prep for display
function shuffle(array) {
  var m = array.length, t, i;

  while (m) {<commit_msg>Complete game info CRUD functions<commit_after>'use strict';

// GLOBAL VAR INIT =====

// size of the grid
var gridSize = 16;
// tiles remaining after clicked
var tilesRemain = gridSize;
// the total number of turns for the entire game
var startTurns = gridSize * 2;
// array of flipped Tiles
var flipped = [];


// OBJ CONSTRUCTOR =====

// per player
function Player (name){
  this.name = name;
  this.turns = startTurns;
  this.points = 0;
}

// per tile
function Tile(path){
  this.path = 'temp/' + path;
  this.active = true;
}

// construct Player
var currentPlayer = new Player('Test Player');

// init array of tiles
var sortedTiles = [
  new Tile('kitten_01.jpg'),
  new Tile('kitten_02.jpg'),
  new Tile('kitten_03.jpg'),
  new Tile('kitten_04.jpg'),
  new Tile('kitten_05.jpg'),
  new Tile('kitten_06.jpg'),
  new Tile('kitten_07.jpg'),
  new Tile('kitten_08.jpg'),
  new Tile('kitten_01.jpg'),
  new Tile('kitten_02.jpg'),
  new Tile('kitten_03.jpg'),
  new Tile('kitten_04.jpg'),
  new Tile('kitten_05.jpg'),
  new Tile('kitten_06.jpg'),
  new Tile('kitten_07.jpg'),
  new Tile('kitten_08.jpg')
];

// shuffle the array of tiles
var randomTiles = shuffle(sortedTiles.slice(0));

// FUNCTIONS =====

// returns tile object
function tile(elementId){
  // error handling
  if(elementId.length < 4){
    return null;
  } else {
    console.log(randomTiles[parseInt(elementId.slice(4) - 1)]);
    return randomTiles[parseInt(elementId.slice(4) - 1)];
  }
}

// checks to see if tiles are matching
function checkMatch(){
  // checks flipped array to see if tiles are matching
  if(tile(flipped[0]).path == tile(flipped[1]).path){
    // iterate points to current player
    addPoints();
    // if match is found
    matchFound(flipped[0]);
    matchFound(flipped[1]);
  } else {
    // finally call flipTile on both elements
    flipTile(flipped[1]);
    flipTile(flipped[0]);
  }

  // clear array of flipped elements
  clearFlippedArray();
  // remove turn from current Player
  removeTurn();
  // check if game is over
  checkGameOver();
}


// if match is found
function matchFound(elementId){
  var clickedTile = document.getElementById(elementId);
  // subtract from remaining tiles
  tilesRemain --;
  // deactivates tile
  tile(elementId).active = false;
  // TODO: visual cue of deactivated state ie opacity for now
  clickedTile.setAttribute('style', 'opacity: 0.25');
}

// CRUD Functions =====

function createOrUpdatePlayerInfo () {
  var stringifiedPlayerInfo = JSON.stringify(currentPlayer);
  localStorage.setItem('player', stringifiedPlayerInfo);
}

function retrievePlayerInfo () {
  var stringifiedPlayerInfo = localStorage.getItem('player');
  var parsedPlayerInfo = JSON.parse(stringifiedPlayerInfo);
  return parsedPlayerInfo;
}

function deletePlayerInfo () {
  localStorage.clear();
}

// HELPER FUNCTIONS =====

// modeled after Fisher-Yates Shuffle in https://bost.ocks.org/mike/shuffle/
// shuffles the sortedTiles array to prep for display
function shuffle(array) {
  var m = array.length, t, i;

  while (m) {
{'fraction_non_alphanumeric': 0.13946488294314383, 'fraction_numerical': 0.01705685618729097, 'mean_word_length': 3.780975219824141, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '6216572', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1974, 'n_words': 534}