-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from shibisuriya/chore/scripted-bot-cleanup
Chore/scripted bot cleanup
- Loading branch information
Showing
6 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 23 additions & 18 deletions
41
packages/game-client/src/bots/scripted-bots/bots/headHunter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
import { astar } from '../algorithms/astar'; | ||
import { findDirectionUsingNeckAndHead } from '../../../helpers'; | ||
import { findDirectionUsingNeckAndHead, excludeSelf } from '../../../helpers'; | ||
|
||
const headHunter = ({ move, updateAnnotations, gameData }) => { | ||
// const start = { x: 1, y: 1 }; | ||
// const end = { x: 10, y: 10 }; | ||
// const obstacles = [ | ||
// { x: 3, y: 2 }, | ||
// { x: 3, y: 3 }, | ||
// { x: 3, y: 4 }, | ||
// ]; | ||
const two = gameData.snakes[2]; // bot | ||
const botHead = two.getHead(); | ||
const four = gameData.snakes[4]; | ||
const targetHead = four.getHead(); | ||
const annotations = astar(botHead, targetHead, two.getBody().concat(four.getBody())); | ||
const headHunter = ({ move, updateAnnotations, gameData, self }) => { | ||
// This bot is sucidal, it tries chases down the player and tries to have a head to head collison and | ||
// killing the player... | ||
// Not that the variable `gameData` will contain data of all the snakes including the current snake (self)... | ||
|
||
const opponents = excludeSelf({ myId: self.snakeId, snakes: gameData.snakes }); | ||
const player = opponents['player']; // The user who plays the game will have the snakeId 'player'... | ||
|
||
const getObstacles = () => { | ||
const cells = self.getBody().concat(player.getBody()); | ||
for (const [snakeId, snake] of Object.entries(opponents)) { | ||
if (snakeId !== self.snakeId && snakeId !== 'player') { | ||
cells.push(...snake.getCells()); | ||
} | ||
} | ||
return cells; | ||
}; | ||
|
||
// The object of the bots is to kill the player... | ||
const path = astar(self.getHead(), player.getHead(), getObstacles()); | ||
// updateAnnotations(annotations); | ||
|
||
const [_, cellToMoveTo] = annotations; | ||
const moveDir = findDirectionUsingNeckAndHead(two.getHead(), cellToMoveTo); | ||
const [_, cellToMoveTo] = path; | ||
const moveDir = findDirectionUsingNeckAndHead(self.getHead(), cellToMoveTo); | ||
move(moveDir); | ||
console.log('Cell to move to -> ', cellToMoveTo, ' Bot head -> ', two.getHead()); | ||
console.log('Shibi headhunterbot', Date.now(), ' ', gameData); | ||
}; | ||
|
||
export { headHunter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters