Skip to content

Instantly share code, notes, and snippets.

@Brilliand

Brilliand/bot.js

Created Oct 28, 2019
Embed
What would you like to do?
"CBC Goes With Everything" bot for Grid Game KotH
const turn = api.turn();
const opening = "EEESSSEEESSEEEEEEEEEESSSEEESSSENEEENSNSSSSEEEEEEEEESSSEEESSEEEESE";
if(turn < opening.length*5) {
switch (opening[turn%opening.length]) {
case 'W':
api.awayX();
break;
case 'N':
api.awayY();
break;
case 'E':
api.towardsX();
break;
case 'S':
api.towardsY();
break;
}
}
if (turn === opening.length*5) {
this.generator = (function* () {
yield* [[0, 30], [1, 30], [2, 30]];
for (let i = 0; i < 20; ++i) {
yield* [[3], [2, 2]];
}
while (true) {
for (let i = 0; i < 20; ++i) {
yield* [[3, 2], [2]];
}
for (let i = 0; i < 20; ++i) {
yield* [[3, 2], [0]];
}
for (let i = 0; i < 20; ++i) {
yield* [[2, 2], [1]];
}
for (let i = 0; i < 20; ++i) {
yield* [[2, 2], [3]];
}
for (let i = 0; i < 20; ++i) {
yield* [[1, 2], [0]];
}
for (let i = 0; i < 20; ++i) {
yield* [[1, 2], [2]];
}
for (let i = 0; i < 20; ++i) {
yield* [[0, 2], [3]];
}
for (let i = 0; i < 20; ++i) {
yield* [[0, 2], [1]];
}
}
})();
this.nextCall = turn;
}
if (turn === this.nextCall) {
const [dir, delay = 1] = this.generator.next().value;
[api.awayX, api.awayY, api.towardsX, api.towardsY][dir].bind(api)();
this.nextCall += delay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment