Skip to content

Instantly share code, notes, and snippets.

@hatefulcrawdad
Last active August 29, 2015 13:57
Show Gist options
  • Save hatefulcrawdad/9657497 to your computer and use it in GitHub Desktop.
Save hatefulcrawdad/9657497 to your computer and use it in GitHub Desktop.
//
// The Setup
//
// When we hit a wall, turn the fuck around
function heTurnsTheFuckAround(warrior) {
warrior.pivot();
}
// When warrior sees a diamon, pick that shit up
function hePicksThatShitUp(warrior) {
warrior.collect();
}
// When warrior sees and enemy, attack
function heAttacksTheFucker(warrior) {
warrior.attack();
}
// When warrior has lost damage but the next space is clear, walk
function hesHurtButHeWalks(warrior) {
warrior.walk();
move(warrior);
}
// When warrior has low health, rest
function hesSafeAndRecharges(warrior) {
warrior.rest();
}
// If we can flee and have low health, do it
function heFleesAndRecharges(warrior) {
warrior.walk('backward');
move(warrior, 'backward');
}
// Check behind, pivot and collect
function heMakesSureNotToForgetAnything(warrior) {
if (warrior.seesNothingBehind) {
move(warrior, 'backward');
warrior.walk('backward');
}
else if (warrior.seesDiamondBehind) { warrior.collect('backward'); }
else {
warrior.hasWalkedBackwards = 1;
warrior.position = 0;
}
}
// When nothing is happening, walk
function heWalksWithBravado(warrior) {
warrior.walk();
move(warrior);
}
function move(warrior, value) {
value = 'backward' ? warrior.position-- : warrior.position++
}
jsWarrior.turn = function(warrior) {
warrior.lostDamage = (warrior.lastHealth > warrior.getHealth()); // Took damage between turns
warrior.seesEnemy = (warrior.check() == 'enemy'); // Enemy in the next space
warrior.seesNothing = (warrior.check() == 'empty'); // Next space is clear
warrior.seesNothingBehind = (warrior.check('backward') == "empty"); // Prev space is clear
warrior.seesDiamond = (warrior.check() == 'diamond'); // Next space has diamond
warrior.seesDiamondBehind = (warrior.check('backward') == "diamond"); // Prev space has diamond
warrior.hitsWall = (warrior.check() == 'wall'); // Next space is a wall
warrior.hasLowHealth = (warrior.getHealth() < 15); // Has low health
warrior.lastHealth = warrior.getHealth(); // Save health of the warrior
//
// The Story
//
if (warrior.hitsWall) { heTurnsTheFuckAround(warrior); }
else if (warrior.seesDiamond) { hePicksThatShitUp(warrior); }
else if (warrior.seesEnemy) { heAttacksTheFucker(warrior); }
else if (warrior.lostDamage && warrior.position <= 2) { hesHurtButHeWalks(warrior); }
else if (!warrior.lostDamage && warrior.getHealth(warrior) < 20) { hesSafeAndRecharges(warrior); }
else if (warrior.hasLowHealth) { heFleesAndRecharges(warrior); }
else if (!warrior.hasWalkedBackwards) { heMakesSureNotToForgetAnything(warrior); }
else { heWalksWithBravado(warrior); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment