Skip to content

Instantly share code, notes, and snippets.

@Pnoexz
Last active October 6, 2019 13:59
Show Gist options
  • Save Pnoexz/3886724a2441ccca68c29ab7290c90ab to your computer and use it in GitHub Desktop.
Save Pnoexz/3886724a2441ccca68c29ab7290c90ab to your computer and use it in GitHub Desktop.

You can PM me any feedback in Adam's discord @PlayingWithScissors.

Table of Contents

Undocumented findings

Common functions

Undocumented findings

Sensors

  • Duration: 2
  • Cooldown: 5

Life

  • Bots: 2000
  • CPU: 12000
  • Chips: 4000

Looping over arrays

The variable being named array1 is required. Not sure if other arrays need to be array2/3/etc.

    array1 = findEntities(ENEMY, BOT, false);
    arrayLength = count(array1);
    for (i = 0; i < arrayLength; i++ ) {
        enemy = array1[i];
        enemyX = getX(enemy);
        enemyY = getY(enemy);
        
        // Do something
    }

Random stuff

  • Numbers can be in scientific notation (ie, 1e10)
  • Each phase has a maximum of 3000 ticks across ALL bots or 1000ms of execution time
  • Bot that take longer than 15 ms to execute their scripts will get punished by getting ignore for a lot of time (broken scrips would only get 3-4 turns total)
  • Chips affect ALL defender bots
  • Setting a cloaked bot on fire will not turn off the cloak, it will simply reveal the bot for as long as the fire lasts
  • Shielding an ally has a range of 5 and can target all friendly entities

Common functions

Movement

These variables are named ownX/ownY because they can't be named x/y.

teleportIfPossible = function(ownX, ownY) {
    if (canTeleport(ownX, ownY)) {
        teleport(ownX, ownY);
    }
}
moveToIfPossible = function(ownX, ownY) {
    if (canMoveTo(ownX, ownY)) { // This will return false if ownX and ownY is not in sense range
        moveTo(ownX, ownY);
    }
}

Since arenaWidth and arenaHeight are static, these are better stored in init(). Also, the isAttacker is unnecessary and I need to rework this function. This also might get broken in future versions of BotLand.

moveTowardsCpu = function() {
    if (isAttacker) {
        destinationX = arenaWidth - 1;
        destinationY = floor(arenaHeight / 2);
        moveTo(destinationX, destinationY);
    } else {
        move();
    }
}

Distance

calculateDistance = function(sourceX, sourceY, targetX, targetY) {
    xDiff = abs(sourceX - targetX);
    yDiff = abs(sourceY - targetY);

    return xDiff + yDiff;
}
isInSenseRange = function(targetX, targetY) {
    senseRange = 5;
    if (areSensorsActivated()) {
        senseRange = 7;
    }

    return (calculateDistance(x, y, targetX, targetY) <= senseRange)
}

Zapping

isEntityInZappingDistance = function(entity) {
    entityX = getX(entity);
    entityY = getY(entity);
    distance = getDistanceTo(entity);
    if (distance === 1) {
        return true;
    } else if (distance === 2 && !(entityX === x || entityY === y)) {
        return true;
    }
    return false;
}

Healing

healSelfOrAlly = function() {
    healSelf();
    healOrPersueFriendlyBot();
}

healSelf = function() {
    if (willRepair() && life < healthToStopRepairing) {
        repair();
    }
}

healOrPersueFriendlyBot = function() {
    myBotsInRange = findEntities(IS_OWNED_BY_ME, BOT, false);
    repairTarget = filterEntities(myBotsInRange, [
        SORT_BY_DISTANCE,
        SORT_BY_LIFE
    ], [
        SORT_ASCENDING,
        SORT_ASCENDING
    ]);
    if (exists(repairTarget) && getLife(repairTarget) < healthToStopRepairing) {
        if (willRepair(repairTarget)) {
            repair(repairTarget);
        } else {
            pursue(repairTarget);
        }
    }
}

Figuring out if the bot took any damage in the last turn

The lastTurnHp = life; needs to be before any terminator to avoid not recalculating the number in the next turn.

init = function() {
    lastTurnHp = life;
}

update = function () {
    tookDamage = didTakeDamage();

    if (tookDamage) {
        if (canReflect()) {
            reflect();
        }
    }
}

didTakeDamage = function() {
    tookDamage = false
    if (life < lastTurnHp) {
        tookDamage = true
    }

    lastTurnHp = life;

    return tookDamage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment