<commit_before>// images for game pieces

const xImage = "http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/black-ink-grunge-stamps-textures-icons-alphanumeric/068726-black-ink-grunge-stamp-textures-icon-alphanumeric-x-solid.png"
const oImage ="http://www.drodd.com/images14/o25.png"
const emptySquare = "http://1.bp.blogspot.com/-jJUO43k6ReU/T7ivfcr4fgI/AAAAAAAAQqU/8YdJwPwT4OE/s1600/transparent.png"

//role for local player
var playerRole;

//local reference for firebase data
let whoseTurn;
let gameover;
var plays;
var users;

//hide the playagain button


const maxMsg = 10

const form = document.querySelector('form')
const messagesRef = firebase.database().ref('messages')
const messagesDiv = document.querySelector('.messages')




$(".playAgain").hide()
$(".exit-game").hide()

//--------- PAGE LOAD -----------------
//on pageload, reset firebase array
firebase.database().ref("moves").set(["Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z"]);
//current player is x
firebase.database()
  .ref("currentPlayer").set("x");
//moves = zero
firebase.database()
  .ref("plays").set(0)

//game is not over
firebase.database()
.ref("gameover").set(false)




//------------------ FIREBASE SNAPS ------------------
//listen for change in the player on firebase on game start
firebase.database()
  .ref("currentPlayer")
  .once("value")
  .then(snap => snap.val())
  .then((value)=>{
    whoseTurn = value;
  })
  //listens for set of gameover value at start
  firebase.database()
  .ref("gameover")
  .once("value")
  .then(snap => snap.val())
  .then((value)=>{
    gameover = value;
    console.log("gameover", gameover)
  })



//listens for change in moves array
firebase.database()
  .ref("moves")
  .on("value", setCurrentArray)

function setCurrentArray(snap) {
  if(snap) {
    let val = snap.val()
    currentArray = val;
    //updates board to current array value
    updateBoard(val)
    console.log("currentArray", currentArray)
    //calls the check for win function

    checkForWin(val)

  }
}


//listens for change in player in
firebase.database()
  .ref("currentPlayer")
  .on("value", setWhoseTurn)

  function setWhoseTurn(snap) {
    if(snap) {
      let val = snap.val()
      whoseTurn = val;
      console.log("whoseTurn", whoseTurn)
    }
  }

//listens for change in gameover
firebase.database()
  .ref("gameover")
  .on("value", setGameOver)

  function setGameOver(snap) {
    if(snap) {
      let val = snap.val()
      gameover = val;
      console.log("gameover", gameover)
      if(gameover === true) {
        $(".playAgain").show()
        $(".exit-game").show()
      } else {
        $(".playAgain").hide()
        $(".exit-game").hide()
      }
    }
  }
//listens for change in play count

firebase.database()
  .ref("plays")
  .on("value", setPlay)

function setPlay(snap){
    if(snap) {
      let val = snap.val()
      plays = val;
      console.log("plays", plays)

    }
}

//listens for change in user count

firebase.database()
  .ref("users")
  .on("value", setUser)

function setUser(snap){
    if(snap) {
      let val = snap.val()
      users = val;
      console.log("users", users)

    }
}




//event listeners on DOM
$("td").click(changeSquare) //calls function to change image

$(".playAgain").click(playAgain)

function changeSquare(evt) {
  console.log("I've been clicked")

  //resets the image of the clicked on square to new value
   let clickedSquare = evt.target
   //captures data position of clicked target
   let squarePosition = parseInt(evt.target.closest('td').dataset.position);

   //if valid array, update firebase
   if(clickedSquare.src === emptySquare && gameover !== true) {
    //adds data position to array that stores the players choices
   firebase.database().ref("moves").update({ [squarePosition] : whoseTurn})
   //add play to count of plays
   let newPlayCount = (plays + 1)
   firebase.database().ref("plays").set(newPlayCount)

   //run the check for win function

  }
 }





// ------------------------ Check For Win ----------------------------

// firebase.database().ref("moves").on('value', checkForWin)

function checkForWin(snap) {
  let a = snap
  var wc = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6],[1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6] ];

  for(var i = 0; i < wc.length; i++) {

    if(a[wc[i][0]] !== "Z") {
      if ((a[wc[i][0]] === a[wc[i][1]]) && (a[wc[i][1]] === a[wc[i][2]])) {<commit_msg>signout button on both sites<commit_after>// images for game pieces

const xImage = "http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/black-ink-grunge-stamps-textures-icons-alphanumeric/068726-black-ink-grunge-stamp-textures-icon-alphanumeric-x-solid.png"
const oImage ="http://www.drodd.com/images14/o25.png"
const emptySquare = "http://1.bp.blogspot.com/-jJUO43k6ReU/T7ivfcr4fgI/AAAAAAAAQqU/8YdJwPwT4OE/s1600/transparent.png"

//role for local player
var playerRole;

//local reference for firebase data
let whoseTurn;
let gameover;
var plays;
var users;

//hide the playagain button


const maxMsg = 10

const form = document.querySelector('form')
const messagesRef = firebase.database().ref('messages')
const messagesDiv = document.querySelector('.messages')




$(".playAgain").hide()
$(".exit-game").hide()

//--------- PAGE LOAD -----------------
//on pageload, reset firebase array
firebase.database().ref("moves").set(["Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z"]);
//current player is x
firebase.database()
  .ref("currentPlayer").set("x");
//moves = zero
firebase.database()
  .ref("plays").set(0)

//game is not over
firebase.database()
.ref("gameover").set(false)




//------------------ FIREBASE SNAPS ------------------
//listen for change in the player on firebase on game start
firebase.database()
  .ref("currentPlayer")
  .once("value")
  .then(snap => snap.val())
  .then((value)=>{
    whoseTurn = value;
  })
  //listens for set of gameover value at start
  firebase.database()
  .ref("gameover")
  .once("value")
  .then(snap => snap.val())
  .then((value)=>{
    gameover = value;
    console.log("gameover", gameover)
  })



//listens for change in moves array
firebase.database()
  .ref("moves")
  .on("value", setCurrentArray)

function setCurrentArray(snap) {
  if(snap) {
    let val = snap.val()
    currentArray = val;
    //updates board to current array value
    updateBoard(val)
    console.log("currentArray", currentArray)
    //calls the check for win function

    checkForWin(val)

  }
}


//listens for change in player in
firebase.database()
  .ref("currentPlayer")
  .on("value", setWhoseTurn)

  function setWhoseTurn(snap) {
    if(snap) {
      let val = snap.val()
      whoseTurn = val;
      console.log("whoseTurn", whoseTurn)
    }
  }

//listens for change in gameover
firebase.database()
  .ref("gameover")
  .on("value", setGameOver)

  function setGameOver(snap) {
    if(snap) {
      let val = snap.val()
      gameover = val;
      console.log("gameover", gameover)
      // if(gameover === true) {
      //   $(".playAgain").show()
      //   $(".exit-game").show()
      // } else {
      //   $(".playAgain").hide()
      //   $(".exit-game").hide()
      // }
    }
  }
//listens for change in play count

firebase.database()
  .ref("plays")
  .on("value", setPlay)

function setPlay(snap){
    if(snap) {
      let val = snap.val()
      plays = val;
      console.log("plays", plays)

    }
}

//listens for change in user count

firebase.database()
  .ref("users")
  .on("value", setUser)

  firebase.database()
  .ref("users")
  .once("value", assignRole)

function setUser(snap){
    if(snap) {
      let val = snap.val()
      users = val;
      console.log("users", users)

    }
}

function assignRole(snap) {
    if(snap) {
      let val = snap.val()
      users = val;
      if (users === null || users === 0) {
        playerRole = "x"
      } else {
        playerRole = "o"
      }
      console.log("playerRole", playerRole)
    }
}


//event listeners on DOM
$("td").click(changeSquare) //calls function to change image

$(".playAgain").click(playAgain)

function changeSquare(evt) {
  console.log("I've been clicked")

  //resets the image of the clicked on square to new value
   let clickedSquare = evt.target
   //captures data position of clicked target
   let squarePosition = parseInt(evt.target.closest('td').dataset.position);

   //if valid array, update firebase
   if(clickedSquare.src === emptySquare && gameover !== true && whoseTurn === playerRole) {
    //adds data position to array that stores the players choices
   firebase.database().ref("moves").update({ [squarePosition] : whoseTurn})
   //add play to count of plays
   let newPlayCount = (plays + 1)
   firebase.database().ref("plays").set(newPlayCount)

   //run the check for win function

  }
 }





// ------------------------ Check For Win ----------------------------

// firebase.database().ref("moves").on('value', checkForWin)

function checkForWin(snap) {
  let a = snap
  var wc = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6],[1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6] ];

  for(var i = 0; i < wc.length; i++) {

    if(a[wc[i][0]] !== "Z") {
      if ((a[wc[i][0]] === a[wc[i][1]]) && (a[wc[i][1]] === a[wc[i][2]])) {
{'fraction_non_alphanumeric': 0.19469122426868907, 'fraction_numerical': 0.012892741061755147, 'mean_word_length': 2.8688181056160937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4460928', 'n_tokens_mistral': 3282, 'n_tokens_neox': 3143, 'n_words': 766}