Skip to content

Commit

Permalink
Merge pull request #51 from shibisuriya/chore/scripted-bot-cleanup
Browse files Browse the repository at this point in the history
fix: headHunter bot breaks when a path is not possible
  • Loading branch information
shibisuriya authored Jan 7, 2024
2 parents 953f026 + daa052a commit 2f71b6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ At regular intervals, a random type of food will spawn in map regions unoccupied

The snake's body grows by 1 cell if it consumes a frog.

#### The Shrink berries:
#### The Shrink berries (work in progress):

Eating a shrink berry decreases the snake's body length by 1 cell. It's important to note that if the snake's body is only 2 cells long, this food has no impact on the snake.

Expand Down Expand Up @@ -68,7 +68,7 @@ After adding the javascript file that exports a function which implements the bo

This bot is sucidal, it tries to run after the player's head and tries to have a head to head collision, hence killing itself and the player... This bot works effectively when there are multiple bots in the map, if the player and the head hunter bot are dead the game ends and the bots that are alive in the map win.

#### Smart head hunter (work in progress):
##### Smart head hunter (work in progress):

A head hunter bot that tries to eat food available in the map whenever possible instead of blinding running behind the player's head.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ const headHunter = ({ move, updateAnnotations, gameData, self }) => {
// updateAnnotations(annotations);

const [_, cellToMoveTo] = path;
const moveDir = findDirectionUsingNeckAndHead(self.getHead(), cellToMoveTo);
move(moveDir);

if (path.length > 0) {
const direction = findDirectionUsingNeckAndHead(self.getHead(), cellToMoveTo);
move(direction);
}
};

export { headHunter };

0 comments on commit 2f71b6c

Please sign in to comment.