<commit_before>'use strict';

var fb = new Firebase('https://battlewhich.firebaseio.com'),
    gameBoard = [],
   guessBoard = [],
  //TODO: add function that toggles isPlayer1 to true or false depending on whether the player is the first or second to join the game
  playerId,
  gameId,
  boardCounter = 1;


$(document).ready(function(){
  clearBoard(gameBoard)
  clearBoard(guessBoard)
//  setNewGame();
  renderBoards(gameBoard, guessBoard);
});

function clearBoard(boardToClear){
  boardToClear.splice(0, boardToClear.length);
  for(var i = 0; boardToClear.length < 10; i++) {boardToClear.unshift([0,0,0,0,0,0,0,0,0,0])}
}


function setNewGame() {
  var playerObj = {
    isPlayer1: true,
    isTurn: true
  };
  var gameObj = {
    boardState: gameBoard,
    winner: '',
    loser: '',
    player1: '',
    player2: '',
    isActive: true,
    player1Turn: true
  }
  playerId = fb.child('players').push(playerObj).key();
  gameId = fb.child('games').push(gameObj).key();
}


//Create board

function renderBoards(board1, board2) {
  $('#table1,#table2').empty();
  var $tbody = $('<tbody></tbody>');
  var $tbody2 = $('<tbody></tbody>');

//create game board
  board1.forEach(function(row) {
    var $tr = $('<tr></tr>');
    row.forEach(function(cell) {
      $tr.append($('<td>' + cell + '</td>'));
    });
    $tbody.append($tr);
  });
  $('#table1').append($tbody);

//create guess board
  board2.forEach(function(row) {
    var $tr = $('<tr></tr>');
    row.forEach(function(cell) {
      $tr.append($('<td>' + cell + '</td>'));
    });
    $tbody2.append($tr);
  });
  $('#table2').append($tbody2);
}


//Click to set peices

$('.gameWrapper').on('click', 'tbody tr td', function(){
  var row = this.parentElement.sectionRowIndex,
      col = this.cellIndex;
  if (gameBoard[row][col] === 0) {
    gameBoard[row][col] += 2;
    renderBoards(gameBoard, guessBoard);
  } else {
    alert('That space is taken please choose another:)');
  }
});

//click to guess

$('.guessWrapper').on('click', 'tbody tr td', function(){
  var row = this.parentElement.sectionRowIndex,
      col = this.cellIndex;
  if (gameBoard[row][col] === '') {
    gameBoard[row][col] = currPlayer;
    sendBoardState();
    if(checkForWin(gameBoard) === true) {
      alert('Hooray!!! ' + currPlayer + ' wins!!!');<commit_msg>make row and col index values global<commit_after>'use strict';

var fb = new Firebase('https://battlewhich.firebaseio.com'),
    gameBoard = [],
   guessBoard = [],
  //TODO: add function that toggles isPlayer1 to true or false depending on whether the player is the first or second to join the game
  playerId,
  gameId,
  boardCounter = 1,
  row,
  col;


$(document).ready(function(){
  clearBoard(gameBoard)
  clearBoard(guessBoard)
//  setNewGame();
  renderBoards(gameBoard, guessBoard);
});

function clearBoard(boardToClear){
  boardToClear.splice(0, boardToClear.length);
  for(var i = 0; boardToClear.length < 10; i++) {boardToClear.unshift([0,0,0,0,0,0,0,0,0,0])}
}


function setNewGame() {
  var playerObj = {
    isPlayer1: true,
    isTurn: true
  };
  var gameObj = {
    boardState: gameBoard,
    winner: '',
    loser: '',
    player1: '',
    player2: '',
    isActive: true,
    player1Turn: true
  }
  playerId = fb.child('players').push(playerObj).key();
  gameId = fb.child('games').push(gameObj).key();
}


//Create board

function renderBoards(board1, board2) {
  $('#table1,#table2').empty();
  var $tbody = $('<tbody></tbody>');
  var $tbody2 = $('<tbody></tbody>');

//create game board
  board1.forEach(function(row) {
    var $tr = $('<tr></tr>');
    row.forEach(function(cell) {
      $tr.append($('<td>' + cell + '</td>'));
    });
    $tbody.append($tr);
  });
  $('#table1').append($tbody);

//create guess board
  board2.forEach(function(row) {
    var $tr = $('<tr></tr>');
    row.forEach(function(cell) {
      $tr.append($('<td>' + cell + '</td>'));
    });
    $tbody2.append($tr);
  });
  $('#table2').append($tbody2);
}


//Click to set peices

$('.gameWrapper').on('click', 'tbody tr td', function(){
      row = this.parentElement.sectionRowIndex,
      col = this.cellIndex;
  if (gameBoard[row][col] === 0) {
    gameBoard[row][col] += 2;
    renderBoards(gameBoard, guessBoard);
  } else {
    alert('That space is taken please choose another:)');
  }
});

//click to guess

$('.guessWrapper').on('click', 'tbody tr td', function(){
      row = this.parentElement.sectionRowIndex,
      col = this.cellIndex;
  if (gameBoard[row][col] === '') {
    gameBoard[row][col] = currPlayer;
    sendBoardState();
    if(checkForWin(gameBoard) === true) {
      alert('Hooray!!! ' + currPlayer + ' wins!!!');
{'fraction_non_alphanumeric': 0.19824072087534864, 'fraction_numerical': 0.014160051491096332, 'mean_word_length': 3.6480558325024925, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '2929872', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1620, 'n_words': 339}