Skip to content

Instantly share code, notes, and snippets.

@kspalaiologos
Created April 9, 2022 16:10
Show Gist options
  • Save kspalaiologos/46cee39205fbd0d1aaba041f1ef996ff to your computer and use it in GitHub Desktop.
Save kspalaiologos/46cee39205fbd0d1aaba041f1ef996ff to your computer and use it in GitHub Desktop.
KoTH round 2 bots
/* Bot 1 (umnikos) */
#define bot query_player1_move
#define bot_name player1_name
char * bot_name = "Homing missile v2";
int bot(board(b), int player) {
int me, them;
if (player == 'X') {
me = '*';
them = '@';
} else {
me = '@';
them = '*';
}
int myi,myj,opi,opj;
for (int i=0; i<16; i++) {
for (int j=0; j<32; j++) {
if (b[i][j] == them) {
opi = i;
opj = j;
}
if (b[i][j] == me) {
myi = i;
myj = j;
}
}
}
int di = opi - myi;
int dj = opj - myj;
static int t = -1;
t++;
if (t < 11*3) {
if (me == '*') {
return "DDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUUU"[t];
} else {
return "UUUUUUUUUUULLLLLLLLLLLDDDDDDDDDDD"[t];
}
}
if (abs(di)+abs(dj) == 2) {
return 'A';
}
if (abs(di) > abs(dj)) {
if (di > 0) {
return 'D';
} else {
return 'U';
}
} else {
if (dj > 0) {
return 'R';
} else {
return 'L';
}
}
}
#undef bot
#undef bot_name
/* Bot 2 (IFcoltransG) */
#define bot query_player2_move
#define bot_name player2_name
#define i_m (player == 'X' ? '*' : '@')
#define u_r (player == 'X' ? '@' : '*')
#define dist(a, b) (abs(a) + abs(b))
#define dir(a, b) (abs(a) <= abs(b) ? "UD"[b > 0] : "LR"[a > 0])
int bot(int board[16][32], char player) {
int x, y;
int z, t;
int rx, ry;
for (int i = 16; i-->0; ) {
for (int j = 32; j-->0;) {
if (board[i][j] == i_m) {
x = j; y = i;
}
if (board[i][j] == u_r) {
z = j; t = i;
}
}
}
// vector to the mirror of wherever the opponent is
rx = (32 - z - 1) - x;
ry = (16 - t - 1) - y;
if (dist(rx, ry) == 0) {
// right where we want to be
return 'a';
}
return dir(rx, ry);
}
char * bot_name = "a";
#undef i_m
#undef u_r
#undef dist
#undef dir
#undef bot
#undef bot_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment