// Twoim zadaniem jest powiedzieć im jaka jest odległość do ogrów.

// Ta funkcja znajduje najbliższego przeciwnika i zwraca odległość do niego.
function nearestEnemyDistance() {
    var enemy = hero.findNearestEnemy();
    // Jeśli nie ma wrogów, funkcja zwraca 0
    var result = 0;
    if (enemy) {
        result = hero.distanceTo(enemy);
    }

// Attack munchkins, call brawlers and ignore burls.

// This function defines the hero's behaviour about enemies.
function dealEnemy(enemy) {
    // If enemy.type is "munchkin":
    if (enemy.type == "munchkin") {
        // Then attack it:
         hero.attack(enemy);
    }

// Zostałeś uwięziony.Nie ruszaj się, to może być bolesne.

// Ta funkcja sprawdza czy wróg jest w zasięgu twojego ataku.
function inAttackRange(enemy) {
    var distance = hero.distanceTo(enemy);
    // Prawie wszystkie miecze mają zasięg ataku równy 3 .
    if (distance <= 3) {
        return true;
    } else {
        return false;
    }
}

// To make the training more interesting Senick poisoned you.
// While you aren't moving the poison is harmless.

// This function should check if a coin is closer than 20m.
function isCoinClose(coin) {
    // Find the distance to the `coin`.
    var distance = hero.distanceTo(item);
    // If the distance is less than 20:
    if (distance < 20) {
        
    
        // Return true
        return(true);
    }

// Ogres are attacking a nearby settlement!
// Be careful, though, for the ogres have sown the ground with poison.
// Gather coins and defeat the ogres, but avoid the burls and poison!

while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy.type == "munchkin" || enemy.type == "thrower") {
        hero.attack(enemy);

// Artyleria używa monet jako celu.
// Posłużysz jako dalmierz dla artylerii.

// Napisz funkcję.
function coinDistance() {
    // Znajdź najbliższą monetę.
    var coin = hero.findNearestItem();
    
    
    // Jeśli  jest tam moneta , zwróć dystans do niej.
    if (coin) {
    var distance = hero.distanceTo(coin);
    return distance;
    }

// Certain coins and gems attract lightning.
// The hero should only grab silver coins and blue gems.

while (true) {
    var item = hero.findNearestItem();
    // A silver coin has a value of 2.
    // Collect if item.type is equal to "coin"
    // AND item.value is equal to 2.