KoTH: Wizard Battle
Golden
Uses the golden ratio, which, if my calculations are correct, is a Nash equilibrium solution to the two-player game. Attacks the most deadly if there is still more than one opponent.
"Golden": [
function(self, others, storage) {
var targ;
for (var i in others) {
if (targ == null || others[targ].wand < others[i].wand)
targ = i
}
return others[targ].uid;
},
function(storage) {
return 0.381966;
}
]
Try it online!
Bully
"Bully": [
function attack(self, others, storage) {
minWand = Math.min(...others.map(bot => bot.wand));
targets = others.filter(bot => bot.wand === minWand);
return targets[Math.random() * targets.length | 0].uid;
},
function wandChance(storage) {
return 0.0025;
}
]
Only targets the "weakest" bots, aka bots with the lowest wand success chance.
Test all current bots!
Climber
Always target the bot who, by our calculation, looks to have the highest score. Keeps a 1% wand for the 10 point payout if he wins.
"Climber": [
function(me, them, storage) {
storage.current = them.slice(0);
fromEntries = function(arr){
var obj = {};
for(var pair of arr) obj[pair[0]] = pair[1];
return obj
}
if(!storage.scores)
storage.scores = fromEntries(them.map(x => [x.uid, 0]));
var targ;
for (var i in them) {
if (targ == null || storage.scores[targ] < storage.scores[them[i].uid])
targ = them[i].uid;
}
return targ;
},
function(storage) {
if(storage.scores){
for(var bot of storage.current)
// divide the score by the number of bots that could have won
storage.scores[bot.uid] +=
Math.max(Math.pow(bot.wand, -1/2), 20) /
(storage.current.length + 1);
}
return 0.01;
}
]