create game runner

This commit is contained in:
Evan
2025-01-02 13:25:36 -08:00
parent 8a4644637a
commit 8443095d89
10 changed files with 100 additions and 32 deletions
+2 -3
View File
@@ -32,7 +32,7 @@ export class Executor {
// private random = new PseudoRandom(999)
private random: PseudoRandom = null
constructor(private gs: Game, private gameID: GameID, private workerClient: WorkerClient) {
constructor(private gs: Game, private gameID: GameID) {
// Add one to avoid id collisions with bots.
this.random = new PseudoRandom(simpleHash(gameID) + 1)
}
@@ -94,7 +94,7 @@ export class Executor {
case UnitType.Battleship:
return new BattleshipExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.Port:
return new PortExecution(intent.player, new Cell(intent.x, intent.y), this.workerClient)
return new PortExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.MissileSilo:
return new MissileSiloExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.DefensePost:
@@ -118,7 +118,6 @@ export class Executor {
for (const nation of this.gs.nations()) {
execs.push(new FakeHumanExecution(
this.gameID,
this.workerClient,
new PlayerInfo(
nation.name,
PlayerType.FakeHuman,
+2 -2
View File
@@ -33,7 +33,7 @@ export class FakeHumanExecution implements Execution {
private lastEmojiSent = new Map<Player, Tick>()
constructor(gameID: GameID, private worker: WorkerClient, private playerInfo: PlayerInfo, private cell: Cell, private strength: number) {
constructor(gameID: GameID, private playerInfo: PlayerInfo, private cell: Cell, private strength: number) {
this.random = new PseudoRandom(simpleHash(playerInfo.id) + simpleHash(gameID))
}
@@ -265,7 +265,7 @@ export class FakeHumanExecution implements Execution {
const oceanTiles = Array.from(this.player.borderTiles()).filter(t => t.isOceanShore())
if (oceanTiles.length > 0) {
const buildTile = this.random.randElement(oceanTiles)
this.mg.addExecution(new PortExecution(this.player.id(), buildTile.cell(), this.worker))
this.mg.addExecution(new PortExecution(this.player.id(), buildTile.cell()))
}
return
}
+13 -6
View File
@@ -7,6 +7,7 @@ import { bfs, dist, manhattanDist } from "../Util";
import { TradeShipExecution } from "./TradeShipExecution";
import { ParallelAStar, WorkerClient } from "../worker/WorkerClient";
import { consolex } from "../Consolex";
import { MiniAStar } from "../pathfinding/MiniAStar";
export class PortExecution implements Execution {
@@ -15,12 +16,11 @@ export class PortExecution implements Execution {
private port: MutableUnit
private random: PseudoRandom
private portPaths = new Map<MutableUnit, Tile[]>()
private computingPaths = new Map<MutableUnit, ParallelAStar>()
private computingPaths = new Map<MutableUnit, MiniAStar>()
constructor(
private _owner: PlayerID,
private cell: Cell,
private worker: WorkerClient
) { }
@@ -84,9 +84,16 @@ export class PortExecution implements Execution {
}
continue
}
const asyncPF = this.worker.createParallelAStar(this.port.tile(), port.tile(), 25, [TerrainType.Ocean])
// consolex.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`)
this.computingPaths.set(port, asyncPF)
const pf = new MiniAStar(
this.mg.terrainMap(),
this.mg.terrainMiniMap(),
this.port.tile(), port.tile(),
sn => sn.terrainType() == TerrainType.Ocean,
10_000,
25
)
this.computingPaths.set(port, pf)
}
for (const port of this.portPaths.keys()) {
@@ -102,7 +109,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.mg, this.worker, 10)
const pf = PathFinder.Mini(this.mg, 10, (sn) => sn.terrainType() == TerrainType.Ocean)
this.mg.addExecution(new TradeShipExecution(this.player().id(), this.port, port, pf, path))
}
}