AStar returns cell instead of path

This commit is contained in:
evanpelle
2024-12-03 14:35:09 -08:00
parent 330b6b93cb
commit 4edd66dc1f
12 changed files with 57 additions and 59 deletions
+2 -1
View File
@@ -14,7 +14,7 @@ export class BattleshipExecution implements Execution {
private battleship: MutableUnit = null
private mg: MutableGame = null
private pathfinder = PathFinder.Serial(5000, t => t.isWater())
private pathfinder: PathFinder
private patrolTile: Tile;
private patrolCenterTile: Tile
@@ -31,6 +31,7 @@ export class BattleshipExecution implements Execution {
init(mg: MutableGame, ticks: number): void {
this.pathfinder = PathFinder.Serial(mg, 5000, t => t.isWater())
this._owner = mg.player(this.playerID)
this.mg = mg
this.patrolCenterTile = mg.tile(this.cell)
+3 -2
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, TerrainType, Tile, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
@@ -14,7 +14,7 @@ export class DestroyerExecution implements Execution {
private mg: MutableGame = null
private target: MutableUnit = null
private pathfinder = PathFinder.Serial(5000, t => t.isWater())
private pathfinder: PathFinder
private patrolTile: Tile;
private patrolCenterTile: Tile
@@ -29,6 +29,7 @@ export class DestroyerExecution implements Execution {
init(mg: MutableGame, ticks: number): void {
this.pathfinder = PathFinder.Serial(mg, 5000, t => t.terrainType() == TerrainType.Ocean)
this._owner = mg.player(this.playerID)
this.mg = mg
this.patrolCenterTile = mg.tile(this.cell)
+2 -1
View File
@@ -16,7 +16,7 @@ export class NukeExecution implements Execution {
private nuke: MutableUnit
private dst: Tile
private pathFinder: PathFinder = PathFinder.Serial(10_000, () => true)
private pathFinder: PathFinder
constructor(
private type: UnitType.AtomBomb | UnitType.HydrogenBomb,
private senderID: PlayerID,
@@ -26,6 +26,7 @@ export class NukeExecution implements Execution {
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.pathFinder = PathFinder.Serial(mg, 10_000, () => true)
this.player = mg.player(this.senderID)
this.dst = this.mg.tile(this.cell)
}
+2 -2
View File
@@ -72,7 +72,7 @@ export class PortExecution implements Execution {
const aStar = this.computingPaths.get(port)
switch (aStar.compute()) {
case PathFindResultType.Completed:
this.portPaths.set(port, aStar.reconstructPath().map(sn => sn as Tile))
this.portPaths.set(port, aStar.reconstructPath().map(cell => this.mg.tile(cell)))
this.computingPaths.delete(port)
break
case PathFindResultType.Pending:
@@ -101,7 +101,7 @@ export class PortExecution implements Execution {
const port = this.random.randElement(portConnections)
const path = this.portPaths.get(port)
if (path != null) {
const pf = PathFinder.Parallel(this.worker, 30)
const pf = PathFinder.Parallel(this.mg, this.worker, 30)
this.mg.addExecution(new TradeShipExecution(this.player().id(), this.port, port, pf, path))
}
}
+2 -1
View File
@@ -5,7 +5,7 @@ import { PathFindResultType } from "../pathfinding/AStar";
export class ShellExecution implements Execution {
private active = true
private pathFinder = PathFinder.Serial(2000, () => true, 10)
private pathFinder: PathFinder
private shell: MutableUnit
constructor(private spawn: Tile, private _owner: MutablePlayer, private target: MutableUnit) {
@@ -13,6 +13,7 @@ export class ShellExecution implements Execution {
}
init(mg: MutableGame, ticks: number): void {
this.pathFinder = PathFinder.Serial(mg, 2000, () => true, 10)
}
tick(ticks: number): void {
+2 -1
View File
@@ -27,7 +27,7 @@ export class TransportShipExecution implements Execution {
private boat: MutableUnit
private pathFinder: PathFinder = PathFinder.Serial(10_000, t => t.isWater(), 2)
private pathFinder: PathFinder
constructor(
private attackerID: PlayerID,
@@ -43,6 +43,7 @@ export class TransportShipExecution implements Execution {
init(mg: MutableGame, ticks: number) {
this.lastMove = ticks
this.mg = mg
this.pathFinder = PathFinder.Serial(mg, 10_000, t => t.isWater(), 2)
this.attacker = mg.player(this.attackerID)