From c399cb59fb15e0e52539bc750707b03b581073ff Mon Sep 17 00:00:00 2001 From: evanpelle Date: Tue, 12 Nov 2024 16:32:48 -0800 Subject: [PATCH] perf improvement a star --- src/core/PathFinding.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/PathFinding.ts b/src/core/PathFinding.ts index 03cd9f70b..2b31c53db 100644 --- a/src/core/PathFinding.ts +++ b/src/core/PathFinding.ts @@ -41,7 +41,7 @@ export class AStar { for (const neighbor of this.current.neighborsWrapped()) { if (neighbor != this.dst && neighbor.isLand()) continue; // Skip non-water tiles - const tentativeGScore = this.gScore.get(this.current)! + 100 - neighbor.magnitude(); + const tentativeGScore = this.gScore.get(this.current)! + 9 - Math.max(1, Math.min(neighbor.magnitude(), 8)); if (!this.gScore.has(neighbor) || tentativeGScore < this.gScore.get(neighbor)!) { this.cameFrom.set(neighbor, this.current); @@ -88,7 +88,7 @@ export class PathFinder { this.dst = dst this.path = null this.aStar = new AStar(curr, dst) - if (this.aStar.compute(50000)) { + if (this.aStar.compute(5000)) { this.path = this.aStar.reconstructPath() } else { return null @@ -115,9 +115,6 @@ export class PathFinder { } else { tolerance = 0 } - if (manhattanDist(this.curr.cell(), curr.cell()) > tolerance) { - return true - } if (manhattanDist(this.dst.cell(), dst.cell()) > tolerance) { return true }