mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 23:04:36 +00:00
use mini a star for all pathfinding
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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[] = [];
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user