while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Find the distance to the enemy with distanceTo.
        var distance = hero.distanceTo(enemy);
        // If the distance is less than 5 meters...
        if(distance < 5){
                  

// This function attacks the nearest enemy.
function findAndAttackEnemy() {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
}

// Define a function to cleave enemies (but only when the ability is ready).
function findAndCleaveEnemy() {
    // Find the nearest enemy:
    var enemy = hero.findNearestEnemy();
    // If an enemy exists:
    if (enemy) {
        
    
        // And if "cleave" is ready:
        if (hero.isReady("cleave")) {
        
            // It's time to cleave!
       
        hero.cleave(enemy);
    }
    }
}

// Destroy the mines!
// Use `say` to call out the range to the mines.
// Use division to calculate the range.

var enemy = hero.findNearestEnemy();
var distanceToEnemy = hero.distanceTo(enemy);
// Say first Range: distanceToEnemy divided by 3
hero.say(distanceToEnemy / 3);
hero.say("Fire!");
// Say second range: distanceToEnemy divided by 1.5
hero.say(distanceToEnemy / 1.5);
hero.say("Fire!");

while(true) {
    // Check the distance to the nearest enemy.
    var nearestEnemy = hero.findNearestEnemy();
    var distance = hero.distanceTo(nearestEnemy);
    // If it comes closer than 10 meters, cleave it!
    if (distance<10) {
        hero.cleave(nearestEnemy);
    }

// Kolejny kufer do otwarcia!
// Atakuj kufer, aby go otworzyć.
// Munchkiny na pewno nie będą się biernie przyglądać, kiedy dobierasz się do ich skarbu!
// Kiedy munchkiny podejdą blisko Bohatera, zaatakuj je.

while(true) {
    var enemy = hero.findNearestEnemy();
    var distance = hero.distanceTo(enemy);

// Kule `evilstone` oznaczają zagrożenie. Zatem unikaj ich, jak ognia.
while (true) {
    var evilstone = hero.findNearestItem();
    if (evilstone) {
        var pos = evilstone.pos;
        if (pos.x == 34) {     // == oznacza "równy"
            // Jeśli kula `evilstone` jest po LEWEJ, idź na PRAWO.
            hero.moveXY(46, 22);
        } else {

// Use charges to soften up packs of ogres.
// Then pick them off with your bow.

while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        if (hero.isReady("throw")) {
            var distance = hero.distanceTo(enemy);
            // Only throw if the ogres are more than 15m away.
            // Use "if" to compare distance to 15.
            if (distance>15) {
                hero.throw(enemy);
                
            }