-
-
Save alion02/6c22816fbba3757152e64136ce2ddf17 to your computer and use it in GitHub Desktop.
A slightly redesigned controller for https://codegolf.stackexchange.com/questions/171810/who-can-get-more-points-card-game-koth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function playGame(a, b) { | |
botSetup(a, b); | |
for (var i = 0; i < 500; i++) { | |
runBots(a, b); | |
} | |
console.log("Bot " + a.name + ": " + a.points); | |
console.log("Bot " + b.name + ": " + b.points); | |
} | |
function botSetup(...bots) { | |
for (var b, i = 0; i < 2; i++) { | |
b = bots[i]; | |
b.points = 0; | |
b.energy = 20; | |
b.storage = {}; | |
b.affectAdd = []; | |
b.affectAct = []; | |
b.shield = 0; | |
} | |
} | |
function runBots(botA, botB) { | |
var bot = [ | |
botA, | |
botB | |
]; | |
var res = [ | |
botA.run([botA.points, botB.points], [botA.energy, botB.energy], botA.storage).toLowerCase(), | |
botB.run([botB.points, botA.points], [botB.energy, botA.energy], botB.storage).toLowerCase() | |
]; | |
var mod = [ | |
0, | |
0 | |
]; | |
function process(i) { | |
if (res[i] == 'a' && bot[i].energy >= 0.1) { | |
bot[i].energy -= 0.1; | |
mod[i] += 5; | |
} else if (res[i] == 'r' && bot[i].energy >= 0.1) { | |
bot[i].energy -= 0.1; | |
mod[1 - i] -= 5; | |
} else if (res[i] == 'h' && bot[i].energy >= 1) { | |
bot[i].energy -= 1; | |
bot[i].affectAdd.push('h'); | |
} else if (res[i] == 'y' && bot[i].energy >= 1) { | |
bot[i].energy -= 1; | |
bot[1 - i].affectAdd.push('h'); | |
} else if (res[i] == 'd' && bot[i].energy >= 2) { | |
bot[i].energy -= 2; | |
bot[i].affectAdd.push('d'); | |
} else if (res[i] == 't' && bot[i].energy >= 2) { | |
bot[i].energy -= 2; | |
bot[1 - i].affectAdd.push('d'); | |
} else if (res[i] == 'n' && bot[i].energy >= 3) { | |
bot[i].energy -= 3; | |
bot[i].affectAdd.push('n'); | |
} else if (res[i] == 'o' && bot[i].energy >= 3) { | |
bot[i].energy -= 3; | |
bot[1 - i].affectAdd.push('n'); | |
} else if (res[i] == 's' && bot[i].energy >= 15) { | |
bot[i].energy -= 15; | |
bot[i].shield += 5; | |
} else if (res[i] == 'x') { | |
mod[1 - i] += 10; | |
bot[1 - i].energy = (bot[1 - i].energy >= 5) ? bot[1 - i].energy - 5 : 0; | |
} else if (res[i] == 'e' && bot[i].points >= 10) { | |
mod[i] -= 10; | |
bot[i].energy += 5; | |
} | |
} | |
process(0); | |
process(1); | |
function applyChanges(i) { | |
if (bot[i].affectAct.includes('h')) { | |
mod[i] *= 0.5; | |
} | |
if (bot[i].affectAct.includes('d')) { | |
mod[i] *= 2; | |
} | |
if (bot[i].affectAct.includes('n')) { | |
mod[i] *= -1; | |
} | |
if (bot[i].shield > 0) { | |
mod[i] = (mod[i] < 0) ? 0 : mod[i]; | |
bot[i].shield--; | |
} | |
bot[i].points += mod[i]; | |
bot[i].affectAct = bot[i].affectAdd; | |
bot[i].affectAdd = []; | |
} | |
applyChanges(0); | |
applyChanges(1); | |
} | |
/* A=Add 5 points to your score [Costs 0.1 energy] | |
R=Remove 5 points from opponent [Costs 0.1 energy] | |
H=Half your next score [Costs 1 energy] | |
Y=Half opponent's next score [Costs 1 energy] | |
D=Double your next score [Costs 2 energy] | |
T=Double opponent's next score [Costs 2 energy] | |
N=Negate your next score [Costs 3 energy] | |
O=Negate opponent's next score [Costs 3 energy] | |
S=Shield for 5 turns [Costs 15 energy] | |
X=Take five energy from opponent [Gives opponent 10 points] | |
E=Refill five energy [Takes 10 points] */ | |
playGame( | |
{ | |
name: "", | |
desc: "", | |
run: function() { | |
} | |
}, { | |
name: "", | |
desc: "", | |
run: function() { | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment