mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:45 +00:00
use new pq library
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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<TileContainer> = new PriorityQueue<TileContainer>(1000, (a: TileContainer, b: TileContainer) => a.priority - b.priority);
|
||||
private toConquer: PriorityQueue<TileContainer> = new PriorityQueue<TileContainer>((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
|
||||
|
||||
@@ -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<Tile, Tile>();
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-6
@@ -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/**/*",
|
||||
|
||||
Reference in New Issue
Block a user