diff --git a/src/core/execution/BattleshipExecution.ts b/src/core/execution/BattleshipExecution.ts index fcd0d7443..a2fa7793a 100644 --- a/src/core/execution/BattleshipExecution.ts +++ b/src/core/execution/BattleshipExecution.ts @@ -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"; @@ -31,7 +31,7 @@ export class BattleshipExecution implements Execution { init(mg: MutableGame, ticks: number): void { - this.pathfinder = PathFinder.Serial(mg, 5000, t => t.isWater()) + this.pathfinder = PathFinder.Mini(mg, 5000, t => t.terrainType() == TerrainType.Ocean) this._owner = mg.player(this.playerID) this.mg = mg this.patrolCenterTile = mg.tile(this.cell) diff --git a/src/core/execution/DestroyerExecution.ts b/src/core/execution/DestroyerExecution.ts index cd2605e13..371bbc00d 100644 --- a/src/core/execution/DestroyerExecution.ts +++ b/src/core/execution/DestroyerExecution.ts @@ -29,7 +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.pathfinder = PathFinder.Mini(mg, 5000, t => t.terrainType() == TerrainType.Ocean) this._owner = mg.player(this.playerID) this.mg = mg this.patrolCenterTile = mg.tile(this.cell) diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 8e819350b..9e095ffaa 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -26,7 +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.pathFinder = PathFinder.Mini(mg, 10_000, () => true) this.player = mg.player(this.senderID) this.dst = this.mg.tile(this.cell) } diff --git a/src/core/execution/ShellExecution.ts b/src/core/execution/ShellExecution.ts index 0be6cf368..a22923f9a 100644 --- a/src/core/execution/ShellExecution.ts +++ b/src/core/execution/ShellExecution.ts @@ -13,7 +13,7 @@ export class ShellExecution implements Execution { } init(mg: MutableGame, ticks: number): void { - this.pathFinder = PathFinder.Serial(mg, 2000, () => true, 10) + this.pathFinder = PathFinder.Mini(mg, 2000, () => true, 10) } tick(ticks: number): void { diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index 6c7c0ff40..bc0569d75 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -1,4 +1,4 @@ -import { Unit, Cell, Execution, MutableUnit, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent, UnitType } from "../game/Game"; +import { Unit, Cell, Execution, MutableUnit, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent, UnitType, TerrainType } from "../game/Game"; import { and, bfs, manhattanDistWrapped, sourceDstOceanShore, targetTransportTile } from "../Util"; import { AttackExecution } from "./AttackExecution"; import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay"; @@ -43,7 +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.pathFinder = PathFinder.Mini(mg, 10_000, t => t.terrainType() == TerrainType.Ocean, 2) this.attacker = mg.player(this.attackerID) diff --git a/src/core/pathfinding/MiniAStar.ts b/src/core/pathfinding/MiniAStar.ts index e71795869..a3695b219 100644 --- a/src/core/pathfinding/MiniAStar.ts +++ b/src/core/pathfinding/MiniAStar.ts @@ -42,8 +42,8 @@ export class MiniAStar implements AStar { function upscalePath(path: Cell[], scaleFactor: number = 2): Cell[] { // Scale up each point const scaledPath = path.map(point => (new Cell( - point.x * scaleFactor, - point.y * scaleFactor + point.x * scaleFactor, + point.y * scaleFactor ))); const smoothPath: Cell[] = []; diff --git a/src/core/pathfinding/PathFinding.ts b/src/core/pathfinding/PathFinding.ts index 4da1cb623..40ec4fda1 100644 --- a/src/core/pathfinding/PathFinding.ts +++ b/src/core/pathfinding/PathFinding.ts @@ -1,6 +1,6 @@ import { Cell, Game, Tile } from "../game/Game"; import { manhattanDist } from "../Util"; -import { AStar, PathFindResultType, TileResult } from "./AStar"; +import { AStar, PathFindResultType, SearchNode, TileResult } from "./AStar"; import { ParallelAStar, WorkerClient } from "../worker/WorkerClient"; import { SerialAStar } from "./SerialAStar"; import { MiniAStar } from "./MiniAStar"; @@ -19,7 +19,7 @@ export class PathFinder { ) { } - public static Mini(game: Game, iterations: number, canMove: (t: Tile) => boolean, maxTries: number = 20) { + public static Mini(game: Game, iterations: number, canMove: (s: SearchNode) => boolean, maxTries: number = 20) { return new PathFinder( game, (curr: Tile, dst: Tile) => {