Skip to content

Instantly share code, notes, and snippets.

@raphaelpierquin
Created March 29, 2017 16:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save raphaelpierquin/f5b6342c0cef71bb37e0d5848b72fff2 to your computer and use it in GitHub Desktop.
Une IA pour arriver sur l'ennemi en même temps que ses bulbes.
var chip = CHIP_ROCKY_BULB;
if (getWeapon()==null) setWeapon(WEAPON_DESTROYER);
var enemy = getNearestEnemy();
var bulbe = unDeMesBulbes();
if (jeSuisSuffisammentLoinDe(enemy) and bulbe != null) {
avanceVersSansTropTEloignerDe(enemy, bulbe);
} else {
moveToward(enemy);
}
summon(chip, aPorteDePuceVers(chip,enemy), fonce);
function fonce() {
moveToward(getNearestEnemy());
}
function jeSuisSuffisammentLoinDe(poireau) {
return getPathLength(getCell(), getCell(poireau)) > 10;
}
function unDeMesBulbes() {
for (var allie in getAliveAllies()) {
if (isSummon(allie) and getSummoner(allie)==getLeek()) return allie;
}
}
function avanceVersSansTropTEloignerDe(enemy, bulbe) {
debug("j'avance mais pas trop");
var ecartIdeal = 3;
var distanceEntreEnnemiEtMoi = getPathLength(getCell(enemy), getCell());
var distanceEntreEnnemiEtBulbe = getPathLength(getCell(enemy), getCell(bulbe));
var ecart = distanceEntreEnnemiEtMoi - distanceEntreEnnemiEtBulbe;
if (ecart > ecartIdeal)
moveTowardCell(getCell(enemy));
}
function aPorteDePuceVers(chip, enemy) {
var candidats = getCellsToUseChip(chip, getLeek());
var laPlusProche = pop(candidats);
var cible = getCell(enemy);
var plusPetiteDistance = getCellDistance(cible, laPlusProche);;
for (var cellule in candidats) {
var distance = getCellDistance(cible, cellule);
if (distance < plusPetiteDistance) {
plusPetiteDistance = distance;
laPlusProche = cellule;
}
}
return laPlusProche;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment