function locationOfSuroundings(y, x, secondTakeOption) {
  //Record the value of the selected piece
  var element = $('#b' + selectedX + selectedY).val();
  $("#b" + x + y).css({
    "background-color": "green",
  })

  //If it is a king it can move up or down
  if (element == kingPlayer) {
    var offsetx = [-1, 1, -1, 1, -2, 2, -2, 2];
    var offsety = [-1, -1, 1, 1, -2, -2, 2, 2];
    var offsetSize = 4
    //If not, it can only move one direction
  } else {
    var offsetx = [-1, 1, -2, 2];
    var offsety = [1, 1, 2, 2];
    var offsetSize = 2
  }

  //Reverse off set if just y
  if (counterInPlay == "Y" && element != kingPlayer) {
    for (var i = 0; i < offsety.length; i++) {
      offsety[i] = -1 * offsety[i]
    }
  }

  var availableMoves = [];
  var oppositionKing = counterOpposition.concat(counterOpposition);

  //See if next row has any free moves
  for (let i = 0; i < offsetSize; i++) {
    let optionx = x + offsetx[i];
    let optiony = y + offsety[i];

    //Make sure the option is within the board.
    if (optionx >= 0 && optiony <= 7 && optionx <= 7 && optiony <= 7 && optionx <= 7 && optiony >= 0 && optionx >= 0 && optiony >= 0) {
      if (table[optiony][optionx] == 0) {
        var availableMove = [optiony, optionx]
        //If overtaking for second time, this is not a valid option
        if (secondTakeOption == 1) {
          availableMoves.push(availableMove)
          $("#b" + optionx + optiony).css({
            "background-color": "orange",
          })
        }
        //If it has an oppostion in it can check the row after.
      } else if (table[optiony][optionx] == counterOpposition || table[optiony][optionx] == oppositionKing) { //Can it overtake?
        let optionLobx = x + offsetx[i + offsetSize];
        let optionLoby = y + offsety[i + offsetSize];
        //Make sure that the lob option is within the board
        if (optionLobx >= 0 && optionLoby <= 7 && optionLobx <= 7 && optionLoby <= 7 && optionLobx <= 7 && optionLoby >= 0 && optionLobx >= 0 && optionLoby >= 0) {
          //The cell is blank, therefore it can be moved if only option available.
          if (table[optionLoby][optionLobx] == 0) {
            $("#b" + optionLobx + optionLoby).css({
              "background-color": "red",
            })
            var availableMove = [optionLoby, optionLobx]
            availableMoves.push(availableMove)
          }
        }
      }
    }
  }
  //Send back what moves are availble.
  return availableMoves
}
/**
 * @function locationOfSuroundings - displays availble moves to player. Returns an array which can then be used to compare where the user wants to move thier piece.
 */
@function locationOfSuroundings - displays availble moves to player. Returns an array which can then be used to compare where the user wants to move thier piece.
@function locationOfSuroundings - displays availble moves to player . Returns an array which can then be used to compare where the user wants to move thier piece .
function locationOfSuroundings(y, x, secondTakeOption) {
  var element = $('#b' + selectedX + selectedY).val();
  $("#b" + x + y).css({
    "background-color": "green",
  })
  if (element == kingPlayer) {
    var offsetx = [-1, 1, -1, 1, -2, 2, -2, 2];
    var offsety = [-1, -1, 1, 1, -2, -2, 2, 2];
    var offsetSize = 4
  } else {
    var offsetx = [-1, 1, -2, 2];
    var offsety = [1, 1, 2, 2];
    var offsetSize = 2
  }
  if (counterInPlay == "Y" && element != kingPlayer) {
    for (var i = 0; i < offsety.length; i++) {
      offsety[i] = -1 * offsety[i]
    }
  }
  var availableMoves = [];
  var oppositionKing = counterOpposition.concat(counterOpposition);
  for (let i = 0; i < offsetSize; i++) {
    let optionx = x + offsetx[i];
    let optiony = y + offsety[i];
    if (optionx >= 0 && optiony <= 7 && optionx <= 7 && optiony <= 7 && optionx <= 7 && optiony >= 0 && optionx >= 0 && optiony >= 0) {
      if (table[optiony][optionx] == 0) {
        var availableMove = [optiony, optionx]
        if (secondTakeOption == 1) {
          availableMoves.push(availableMove)
          $("#b" + optionx + optiony).css({
            "background-color": "orange",
          })
        }
      } else if (table[optiony][optionx] == counterOpposition || table[optiony][optionx] == oppositionKing) { 
        let optionLobx = x + offsetx[i + offsetSize];
        let optionLoby = y + offsety[i + offsetSize];
        if (optionLobx >= 0 && optionLoby <= 7 && optionLobx <= 7 && optionLoby <= 7 && optionLobx <= 7 && optionLoby >= 0 && optionLobx >= 0 && optionLoby >= 0) {
          if (table[optionLoby][optionLobx] == 0) {
            $("#b" + optionLobx + optionLoby).css({
              "background-color": "red",
            })
            var availableMove = [optionLoby, optionLobx]
            availableMoves.push(availableMove)
          }
        }
      }
    }
  }
  return availableMoves
}
function locationOfSuroundings ( y , x , secondTakeOption ) { var element = $ ( '#b' + selectedX + selectedY ) . val ( ) ; $ ( "#b" + x + y ) . css ( { "background-color" : "green" , } ) if ( element == kingPlayer ) { var offsetx = [ - 1 , 1 , - 1 , 1 , - 2 , 2 , - 2 , 2 ] ; var offsety = [ - 1 , - 1 , 1 , 1 , - 2 , - 2 , 2 , 2 ] ; var offsetSize = 4 } else { var offsetx = [ - 1 , 1 , - 2 , 2 ] ; var offsety = [ 1 , 1 , 2 , 2 ] ; var offsetSize = 2 } if ( counterInPlay == "Y" && element != kingPlayer ) { for ( var i = 0 ; i < offsety . length ; i ++ ) { offsety [ i ] = - 1 * offsety [ i ] } } var availableMoves = [ ] ; var oppositionKing = counterOpposition . concat ( counterOpposition ) ; for ( let i = 0 ; i < offsetSize ; i ++ ) { let optionx = x + offsetx [ i ] ; let optiony = y + offsety [ i ] ; if ( optionx >= 0 && optiony <= 7 && optionx <= 7 && optiony <= 7 && optionx <= 7 && optiony >= 0 && optionx >= 0 && optiony >= 0 ) { if ( table [ optiony ] [ optionx ] == 0 ) { var availableMove = [ optiony , optionx ] if ( secondTakeOption == 1 ) { availableMoves . push ( availableMove ) $ ( "#b" + optionx + optiony ) . css ( { "background-color" : "orange" , } ) } } else if ( table [ optiony ] [ optionx ] == counterOpposition || table [ optiony ] [ optionx ] == oppositionKing ) { let optionLobx = x + offsetx [ i + offsetSize ] ; let optionLoby = y + offsety [ i + offsetSize ] ; if ( optionLobx >= 0 && optionLoby <= 7 && optionLobx <= 7 && optionLoby <= 7 && optionLobx <= 7 && optionLoby >= 0 && optionLobx >= 0 && optionLoby >= 0 ) { if ( table [ optionLoby ] [ optionLobx ] == 0 ) { $ ( "#b" + optionLobx + optionLoby ) . css ( { "background-color" : "red" , } ) var availableMove = [ optionLoby , optionLobx ] availableMoves . push ( availableMove ) } } } } } return availableMoves }
@function locationOfSuroundings - displays availble moves to player.
@function locationOfSuroundings - displays availble moves to player .
//Record the value of the selected piece //If it is a king it can move up or down //If not, it can only move one direction //Reverse off set if just y //See if next row has any free moves //Make sure the option is within the board. //If overtaking for second time, this is not a valid option //If it has an oppostion in it can check the row after. //Can it overtake? //Make sure that the lob option is within the board //The cell is blank, therefore it can be moved if only option available. //Send back what moves are availble.