<commit_before>var AI = function(board){
  var board = board;
  var self = this;
  var diagonals = ["top-left", "top-right"];
  
  this.move = function(possibleMoves){
    if (this.getWinning()){
      return this.getWinning();
      
    } else if (this.getDefending()){
      return this.getDefending();

    } else if (checkCenter()){
      return checkCenter();

    } else if (checkAttack()){
      return checkAttack();

    } else if(checkTakenCenter()){
      return checkTakenCenter();

    } else if (this.checkCorners()){
      return this.checkCorners();

    } else {
      return getOther(possibleMoves)
    }
  }

  var checkAttack = function(){
    var cellInEmptySection = checkSingled("empty", "O");
    var result = false

    if (cellInEmptySection) {
      var emptySection = getCellEmptySection(cellInEmptySection)

      if (emptySection[2].getValue() == "empty"){
        result = emptySection[2];
      } else if(emptySection[1].getValue() == "empty"){
        result = emptySection[1];
      } else{
        result = emptySection[0];
      }
    }
    return result
  }

  var getCellEmptySection = function(cell){
    var cellRow = checkForDoubles(board.getRowCells(cell.row), "empty")
    var cellCol = checkForDoubles(board.getColCells(cell.column), "empty")
    var topLeftDiag;
    var topRightDiag;
    
    if (cell.isDiagonal ){
      if (cell.diagonal.indexOf("top-left") != -1){
        topLeftDiag = checkForDoubles(board.getDiagonalCells("top-left"), "empty");<commit_msg>added neighbours check to attack move, favoring the cell that has more enemy cells next to in<commit_after>var AI = function(board){
  var board = board;
  var self = this;
  var diagonals = ["top-left", "top-right"];
  
  this.move = function(possibleMoves){
    if (this.getWinning()){
      return this.getWinning();

    } else if (this.getDefending()){
      return this.getDefending();

    } else if (checkCenter()){
      return checkCenter();

    } else if (checkAttack()){
      return checkAttack();

    } else if(checkTakenCenter()){
      return checkTakenCenter();

    } else if (this.checkCorners()){
      return this.checkCorners();

    } else {
      return getOther(possibleMoves)
    }
  }

  var checkAttack = function(){
    var cellInEmptySection = checkSingled("empty", "O");
    var result = false

    if (cellInEmptySection) {
      var emptySection = getCellEmptySection(cellInEmptySection)

      if (emptySection[0].getValue() == "empty" && hasOpponentNeighbours(emptySection[0]) != 0){
        result = emptySection[0];
      } else if(emptySection[1].getValue() == "empty" && hasOpponentNeighbours(emptySection[1]) != 0){
        result = emptySection[1];
      } else{
        result = emptySection[2];
      }
    }
    return result
  }

  var hasOpponentNeighbours = function(cell){
    return getRowNeighbours(cell) + getColNeighbours(cell);
  }

  var getRowNeighbours = function(cell){
    var count = 0;
    if (cell.row > 1){
      topNeighbour = board.cells[cell.number - 3]
      if (topNeighbour.getValue() == "X"){
        count++
      }
    }

    if (cell.row < 3){
      bottomNeighbour = board.cells[cell.number + 3]
      if (bottomNeighbour.getValue() == "X"){
        count++
      }
    }
    return count
  }

  var getColNeighbours = function(cell){
    var count = 0;
    if (cell.column > 1){
      leftNeighbour = board.cells[cell.number - 1]
      if (leftNeighbour.getValue() == "X"){
        count++
      }
    }

    if (cell.column < 3){
      rightNeighbour = board.cells[cell.number + 1]
      if (rightNeighbour.getValue() == "X"){
        count++
      }
    }
    return count
  }

  var getCellEmptySection = function(cell){
    var cellRow = checkForDoubles(board.getRowCells(cell.row), "empty")
    var cellCol = checkForDoubles(board.getColCells(cell.column), "empty")
    var topLeftDiag;
    var topRightDiag;
    
    if (cell.isDiagonal ){
      if (cell.diagonal.indexOf("top-left") != -1){
        topLeftDiag = checkForDoubles(board.getDiagonalCells("top-left"), "empty");
{'fraction_non_alphanumeric': 0.13818539463978363, 'fraction_numerical': 0.006392918613228424, 'mean_word_length': 2.8413597733711047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2901759', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1288, 'n_words': 279}