Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper-functions #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions public/ais/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,55 @@ export function makeAi(id) {
// Returns the AI-s chosen action. For legal actions see the list of possible actions.
// Use methods from ai-info-gate.js to get information about the game state.
function get_action() {
const board = getBoardInfo();
const actions = getActionsInfo();
const bombs = getBombsInfo();
const fire = getFiresInfo();
const players = getPlayersInfo();
const tileTypes = getTileTypesInfo();
// your code goes here
}

//Examples of functions that could be useful, feel free to change them to suit your own needs or make something
// entirely different:
function getAIPos(players) {
return players.find((p) => p.id === my_id);
}
function isOutsideBoard(x, y) {
return x < 0 || x > 14 || y < 0 || y > 14;
}
function isBombInRange(x, y) {
const bombs = getBombsInfo();
for (const bomb of bombs) {
// Check if the tile is in the same column as the bomb and within 3 tiles vertically
if (bomb.x === x && Math.abs(bomb.y - y) <= 3) {
return true;
} else if (bomb.y === y && Math.abs(bomb.x - x) <= 3) {
// Check if the tile is in the same row as the bomb and within 3 tiles horizontally
return true;
}
}
return false;
}
function isFireInRange(x, y) {
const fires = getFiresInfo();
for (const fire of fires) {
// Check if the tile is in the same column as the fire and within 2 tiles vertically
if (fire.x === x && Math.abs(fire.y - y) <= 2) {
return true;
} else if (fire.y === y && Math.abs(fire.x - x) <= 2) {
// Check if the tile is in the same row as the fire and within 2 tiles horizontally
return true;
}
}
return false;
}
function isPlayerNearby(x, y){
const players = getPlayersInfo();
for (const player of players){
const distance = Math.abs(player.x - x) + Math.abs(player.y - y);
if (distance <=2 && player.id !== my_id){ // Skip checking against self
return true;
}
}
}