Skip to content

Commit

Permalink
Add hazards
Browse files Browse the repository at this point in the history
  • Loading branch information
Petah committed Sep 4, 2020
1 parent 7d8a429 commit 7417873
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/weight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export function weight(data: BTData, x: number, y: number, blockHeads = true) {
}

function computeWeight(data: BTData, x: number, y: number, blockHeads = true) {
if (data.board.hazards) {
for (const hazard of data.board.hazards) {
if (hazard.x == x && hazard.y == y) {
return 5;
}
}
}

let result = 100;
for (const snake of data.board.snakes) {
const body = snake.body;
Expand Down
2 changes: 1 addition & 1 deletion src/types/BTData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface BTBoard {
width: number,
height: number,
food: BTXY[],
hazards: BTXY[],
hazards?: BTXY[],
snakes: BTSnake[],
}

Expand Down
8 changes: 8 additions & 0 deletions src/web/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export function loadGrid(moveJson) {
const col = getCol(food.x, food.y);
$('<div>').addClass('food').appendTo(col);
}
if (moveJson.body.board.hazards) {
for (const hazard of moveJson.body.board.hazards) {
const col = getCol(hazard.x, hazard.y);
col.css({
borderColor: '#ff0000',
});
}
}
for (const snake of moveJson.body.board.snakes) {
let color = '#e74c3c';
if (snake.id == moveJson.body.you.id) {
Expand Down

0 comments on commit 7417873

Please sign in to comment.