From 09cd7e36487642ebe85359b743b0c70331b0a2a5 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 28 Aug 2024 17:51:24 -0700 Subject: [PATCH] use new pq library --- src/client/graphics/NameRenderer.ts | 1 - src/core/execution/AttackExecution.ts | 8 ++++---- src/core/execution/BoatAttackExecution.ts | 11 +++++------ src/core/execution/ExecutionManager.ts | 1 - tsconfig.json | 7 +------ 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/client/graphics/NameRenderer.ts b/src/client/graphics/NameRenderer.ts index 271aaf145..f19a3c4fd 100644 --- a/src/client/graphics/NameRenderer.ts +++ b/src/client/graphics/NameRenderer.ts @@ -1,4 +1,3 @@ -import PriorityQueue from "priority-queue-typescript" import {Cell, Game, Player} from "../../core/Game" import {PseudoRandom} from "../../core/PseudoRandom" import {Theme} from "../../core/configuration/Config" diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 72262eac5..167b10ad4 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -1,4 +1,4 @@ -import PriorityQueue from "priority-queue-typescript"; +import {PriorityQueue} from "@datastructures-js/priority-queue"; import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, TerraNullius, Tile} from "../Game"; import {PseudoRandom} from "../PseudoRandom"; import {manhattanDist} from "../Util"; @@ -6,7 +6,7 @@ import {Config, PlayerConfig} from "../configuration/Config"; export class AttackExecution implements Execution { private active: boolean = true; - private toConquer: PriorityQueue = new PriorityQueue(1000, (a: TileContainer, b: TileContainer) => a.priority - b.priority); + private toConquer: PriorityQueue = new PriorityQueue((a: TileContainer, b: TileContainer) => a.priority - b.priority); private random = new PseudoRandom(123) private _owner: MutablePlayer @@ -103,7 +103,7 @@ export class AttackExecution implements Execution { return } - const toConquerContainer = this.toConquer.poll() + const toConquerContainer = this.toConquer.dequeue() const tileToConquer: Tile = toConquerContainer.tile const onBorder = tileToConquer.neighbors().filter(t => t.owner() == this._owner).length > 0 if (tileToConquer.owner() != this.target || !onBorder) { @@ -164,7 +164,7 @@ export class AttackExecution implements Execution { if (numOwnedByMe > 2) { numOwnedByMe = 1000 } - this.toConquer.add(new TileContainer(neighbor, dist + -numOwnedByMe)) + this.toConquer.enqueue(new TileContainer(neighbor, dist + -numOwnedByMe)) } } this.borderTiles = newBorder diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index 20b2aaf92..3464d3bad 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -1,4 +1,4 @@ -import PriorityQueue from "priority-queue-typescript"; +import {PriorityQueue} from "@datastructures-js/priority-queue"; import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent} from "../Game"; import {manhattanDist} from "../Util"; import {AttackExecution} from "./AttackExecution"; @@ -146,7 +146,6 @@ export class AStar { constructor(private src: Tile, private dst: Tile) { this.openSet = new PriorityQueue<{tile: Tile, fScore: number}>( - 500, (a, b) => a.fScore - b.fScore ); this.cameFrom = new Map(); @@ -155,15 +154,15 @@ export class AStar { this.completed = false; this.gScore.set(src, 0); - this.openSet.add({tile: src, fScore: this.heuristic(src, dst)}); + this.openSet.enqueue({tile: src, fScore: this.heuristic(src, dst)}); } compute(iterations: number): boolean { if (this.completed) return true; - while (!this.openSet.empty()) { + while (!this.openSet.size()) { iterations-- - this.current = this.openSet.poll()!.tile; + this.current = this.openSet.dequeue()!.tile; if (iterations <= 0) { return false } @@ -183,7 +182,7 @@ export class AStar { this.gScore.set(neighbor, tentativeGScore); const fScore = tentativeGScore + this.heuristic(neighbor, this.dst); - this.openSet.add({tile: neighbor, fScore: fScore}); + this.openSet.enqueue({tile: neighbor, fScore: fScore}); } } } diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index 732f44410..0dfb32ceb 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -1,4 +1,3 @@ -import PriorityQueue from "priority-queue-typescript"; import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile} from "../Game"; import {AttackIntent, BoatAttackIntentSchema, Intent, Turn} from "../Schemas"; import {AttackExecution} from "./AttackExecution"; diff --git a/tsconfig.json b/tsconfig.json index 40254babe..b340c5af2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,12 +6,7 @@ "moduleResolution": "node", "sourceMap": true, "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "paths": { - "priority-queue-typescript": [ - "./node_modules/priority-queue-typescript/src/priority-queue/PriorityQueue.js" - ] - } + "esModuleInterop": true }, "include": [ "src/**/*",