chooseMove(direction: 'up'|'down'|'right'|'left'): indicates in which direction the bot should move.
If this function is not called during a round, the bot instantly loses. If it is called multiple times
during a round, only the last call is taken into account.
getSelfPosition(): { x, y }: returns the coordinates of your botgetOpponentPosition(): { x, y }: returns the coordinates of the opponent botgetCellContent(x, y): null|'outside'|'self'|'opponent': returns the content of the cell at (x, y):
null: empty cell'outside': the coordinates are outside the grid'self': your bot trail, or your bot itself'opponent': the opponent bot trail, or the opponent bot itselfgetRoundNumber(): number: indicates the current round number (the first round is the round number 1).isFirstRound(): number: indicates if this is the first round.getSelfPreviousMoves(): string[]: returns the list of your previous moves, ordered from the first round to the last. Each element of the array is one of "up", "right", "down", "left".getOpponentPreviousMoves(): string[]: returns the list of the opponent's previous moves, ordered from the first round to the last. Each element of the array is one of "up", "right", "down", "left".SELF_START_X = 3: your starting X coordinate.SELF_START_Y = 8: your starting Y coordinate.OPPONENT_START_X = 12: opponent starting X coordinate.OPPONENT_START_Y = 8: opponent starting Y coordinate.GRID_WIDTH = 16: the grid width.GRID_HEIGHT = 16: the grid height.This bot goes down until it reaches something, and then goes right.
if (isFirstRound()) {
// First round, initialize persistent variables
hasTurned = false;
}
// Check if we have reached something
if (!hasTurned) {
let { x, y } = getSelfPosition();
if (getCellContent(x, y - 1) !== null) {
// The bottom cell is not empty
hasTurned = true;
}
}
if (hasTurned) {
chooseMove("right");
} else {
chooseMove("down");
}