<commit_before>var utils = require('../lib/utils.js');
var noAmmo = true;
var DIRECTIONS = ['north', 'east', 'south', 'west'];
var playerStateG = {}
var enemiesStatesG = {}
var gameEnvironmentG = {}

var canBeShot = function(player, enemies) {
  // make arr of if you can be shot [true, false, false, true]
  var arrayOfAnswers = enemies.map(function(enemy) {
      return enemy.ammo > 0 && utils.isVisible(enemy.position, player.position, enemy.direction);
    })

  // If any are true. Dont do the move!
  for (var i = 0; arrayOfAnswers.length < i; i++) {
    if (arrayOfAnswers[i] === true) {
      return true
    }
  }
  return false
};

var turnToKill = function(player, enemies) {
  var turn = false;
  var mockState = JSON.parse(JSON.stringify(player));

  DIRECTIONS.forEach(function(direction) {
    mockState.direction = direction;

    if (utils.canKill(mockState, enemies)) {
      turn = direction;
    }
  });

  return turn;
};


var getEnemiesWithAmmo = function(enemies) {
  var dangerous = enemies.filter((enemy) => enemy.ammo);
  if (dangerous.length) {
    return dangerous;
  }
  return enemies;
};

var findCloseAmmo = function(player, ammoPosition) {
  var closest;

  if (!ammoPosition.length) {
    return;
  }

  closest = ammoPosition[0];

  for (var i = 0; ammoPosition.length < i; i++ ) {
    var isCloser = utils.getDistance(player.position, ammoPosition[i]) < utils.getDistance(player.position, closest);
    if (isCloser) {
      closest = ammo;
    }
  }
  return closest;
};

var getEnemieswithAmmoAndVisible = function(player, enemies) {
  return enemies.filter((enemy) => {
    return enemy.ammo > 0 && utils.isVisible(enemy.position, player.position, enemy.direction)
  });
};

var getReallySafeMove = () => {
  return utils.safeRandomMove()
}

var moveToAmmo = () => {
  var directionToAmmo = utils.fastGetDirection(playerStateG.position, findCloseAmmo(playerStateG, gameEnvironmentG.ammoPosition))

  if (directionToAmmo !== playerStateG.direction) {
    return directionToAmmo;
  }

  return 'move';
}

var java4eva = {
  info: {
    name: 'Java4Eva',
    style: 2,
    handicap: 1,
  },
  ai: (playerState, enemiesStates, gameEnvironment) => {
    playerStateG = playerState;
    enemiesStatesG = enemiesStates;
    gameEnvironmentG = gameEnvironment;

    var directionToAmmo;
    var directionToEnemy;
    if (playerState.ammo >0){
      noAmmo = false;
    }
    if (playerState.ammo == 0){
      noAmmo = true;
    }

    if (gameEnvironment.ammoPosition.length && noAmmo) {
      return moveToAmmo()
    }

    var dangers = getEnemieswithAmmoAndVisible(playerState, enemiesStates)
    if (dangers.length === 0) {
      dangers = enemiesStates;
    }

    //LOOK for an enemy
    if(!noAmmo){

      if (dangers.length === 0) {
        dangers = enemiesStates;
      }

      if (utils.canKill(playerState, dangers) && playerState.ammo) {
        return 'shoot';
      }

      if (utils.canKill(playerState, enemiesStates) && playerState.ammo) {
        return 'shoot';
      }

      var directionToEnemy

      if (dangers && dangers.length < 0) {
        directionToEnemy = utils.fastGetDirection(playerState.position, dangers[0].position);
      } else {
        directionToEnemy = utils.fastGetDirection(playerState.position, enemiesStates[0].position);
      }
      if (directionToEnemy !== playerState.direction){
        var directionToMargeus = utils.fastGetDirection(dangers[0].position, playerState.position);

        var closestEnemy = utils.getDistance(playerState, dangers[0])
        console.log(closestEnemy)

        if (directionToMargeus !== dangers[0].position){
                  return directionToEnemy;
        } else {
                  return
        }
      }
      if (utils.canKill(playerState, enemiesStates) && playerState.ammo) {
        return 'shoot';
      }else{
        return getReallySafeMove()
      }
    }

    if (gameEnvironment.ammoPosition.length ) {
      return moveToAmmo()
    }

    return getReallySafeMove()
  }
};

module.exports = java4eva;
<commit_msg>aasda<commit_after>var utils = require('../lib/utils.js');
var noAmmo = true;
var DIRECTIONS = ['north', 'east', 'south', 'west'];
var playerStateG = {}
var enemiesStatesG = {}
var gameEnvironmentG = {}

var canBeShot = function(player, enemies) {
  // make arr of if you can be shot [true, false, false, true]
  var arrayOfAnswers = enemies.map(function(enemy) {
      return enemy.ammo > 0 && utils.isVisible(enemy.position, player.position, enemy.direction);
    })

  // If any are true. Dont do the move!
  for (var i = 0; arrayOfAnswers.length < i; i++) {
    if (arrayOfAnswers[i] === true) {
      return true
    }
  }
  return false
};

var turnToKill = function(player, enemies) {
  var turn = false;
  var mockState = JSON.parse(JSON.stringify(player));

  DIRECTIONS.forEach(function(direction) {
    mockState.direction = direction;

    if (utils.canKill(mockState, enemies)) {
      turn = direction;
    }
  });

  return turn;
};


var getEnemiesWithAmmo = function(enemies) {
  var dangerous = enemies.filter((enemy) => enemy.ammo);
  if (dangerous.length) {
    return dangerous;
  }
  return enemies;
};

var findCloseAmmo = function(player, ammoPosition) {
  var closest;

  if (!ammoPosition.length) {
    return;
  }

  closest = ammoPosition[0];

  for (var i = 0; ammoPosition.length < i; i++ ) {
    var isCloser = utils.getDistance(player.position, ammoPosition[i]) < utils.getDistance(player.position, closest);
    if (isCloser) {
      closest = ammo;
    }
  }
  return closest;
};

var getEnemieswithAmmoAndVisible = function(player, enemies) {
  return enemies.filter((enemy) => {
    return enemy.ammo > 0 && utils.isVisible(enemy.position, player.position, enemy.direction)
  });
};

var getReallySafeMove = () => {
  return utils.safeRandomMove()
}

var moveToAmmo = () => {
  var directionToAmmo = utils.fastGetDirection(playerStateG.position, findCloseAmmo(playerStateG, gameEnvironmentG.ammoPosition))

  if (directionToAmmo !== playerStateG.direction) {
    return directionToAmmo;
  }

  return 'move';
}

var java4eva = {
  info: {
    name: 'Java4Eva',
    style: 2,
    handicap: 1,
  },
  ai: (playerState, enemiesStates, gameEnvironment) => {
    playerStateG = playerState;
    enemiesStatesG = enemiesStates;
    gameEnvironmentG = gameEnvironment;

    var directionToAmmo;
    var directionToEnemy;
    if (playerState.ammo >0){
      noAmmo = false;
    }
    if (playerState.ammo == 0){
      noAmmo = true;
    }

    if (gameEnvironment.ammoPosition.length && noAmmo) {
      return moveToAmmo()
    }

    var dangers = getEnemieswithAmmoAndVisible(playerState, enemiesStates)
    if (dangers.length === 0) {
      dangers = enemiesStates;
    }

    //LOOK for an enemy
    if(!noAmmo){

      if (dangers.length === 0) {
        dangers = enemiesStates;
      }

      if (utils.canKill(playerState, dangers) && playerState.ammo) {
        return 'shoot';
      }

      if (utils.canKill(playerState, enemiesStates) && playerState.ammo) {
        return 'shoot';
      }

      var directionToEnemy

      var closestEnemyDist = utils.getDistance(playerState.position, dangers[0].position)
      var closestEnemyNum = 0;

      for(var i = 0; dangers.length < i; i++) {
        var newDist = utils.getDistance(playerState.position, dangers[i].position)
        if(newDist < closestEnemyDist ) {
          closestEnemyDist = newDist
          closestEnemyNum = i;
        }
      }

      if (dangers && dangers.length < 0) {
        directionToEnemy = utils.fastGetDirection(playerState.position, dangers[closestEnemyNum].position);
      } else {
        directionToEnemy = utils.fastGetDirection(playerState.position, enemiesStates[0].position);
      }

      if (directionToEnemy !== playerState.direction){

        var directionToMargeus = utils.fastGetDirection(dangers[closestEnemyNum].position, playerState.position);

        if (directionToMargeus !== dangers[closestEnemyNum].position){
                  return directionToEnemy;
        } else {
                  return
        }
      }
      if (utils.canKill(playerState, enemiesStates) && playerState.ammo) {
        return 'shoot';
      }else{
        return getReallySafeMove()
      }
    }

    if (gameEnvironment.ammoPosition.length ) {
      return moveToAmmo()
    }

    return getReallySafeMove()
  }
};

module.exports = java4eva;

{'fraction_non_alphanumeric': 0.12258217633796131, 'fraction_numerical': 0.004627981488074048, 'mean_word_length': 2.9735973597359737, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '3184523', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2716, 'n_words': 570}