mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 12:25:10 +00:00
tiles now have lake or ocean method
This commit is contained in:
+17
-1
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user