tiles now have lake or ocean method

This commit is contained in:
evanpelle
2024-08-23 17:53:55 -07:00
parent f52b62a354
commit 41d7c77d2d
14 changed files with 89 additions and 70 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
import {Cell} from "./Game";
import {Cell, Tile} from "./Game";
export function manhattanDist(c1: Cell, c2: Cell): number {
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
@@ -6,4 +6,20 @@ export function manhattanDist(c1: Cell, c2: Cell): number {
export function within(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
}
export function bfs(tile: Tile, dist: number): Set<Tile> {
const seen = new Set<Tile>
const q: Tile[] = []
q.push(tile)
while (q.length > 0) {
const curr = q.pop()
seen.add(curr)
for (const n of curr.neighbors()) {
if (!seen.has(n) && manhattanDist(tile.cell(), n.cell()) <= dist) {
q.push(n)
}
}
}
return seen
}