From 3f27f6e72c7185ac2ae4373b64ba1169c0ea73c6 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 22 Nov 2024 14:42:48 -0800 Subject: [PATCH] more efficient port calculation, npcs send fewer boats, fewer trade ships --- TODO.txt | 2 +- src/core/configuration/DevConfig.ts | 2 +- src/core/execution/FakeHumanExecution.ts | 8 +++++++- src/core/execution/PortExecution.ts | 23 +++++++++++++++++------ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index 988623570..f13fdcf64 100644 --- a/TODO.txt +++ b/TODO.txt @@ -189,7 +189,7 @@ * fix pathfinding bug DONE 11/20/2024 * make two nukes: atom & hydrogen DONE 11/20/2024 * NPC builds ports DONE 11/20/2024 -* BUG: fix matchmaking +* BUG: fix matchmaking DONE 11/22/2024 * destroyer can capture trade ships * make NPC difficult scale better (not just start troops) * add battleship diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index f850f741a..f35865ab2 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -4,7 +4,7 @@ import { DefaultConfig } from "./DefaultConfig"; export const devConfig = new class extends DefaultConfig { unitInfo(type: UnitType): UnitInfo { const info = super.unitInfo(type) - info.cost = 0 + info.cost = 100 return info } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 96a2d85d7..e65cf7220 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -95,7 +95,13 @@ export class FakeHumanExecution implements Execution { const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player) - if (enemyborder.length == 0 || this.random.chance(5)) { + if (enemyborder.length == 0) { + if (this.random.chance(5)) { + this.sendBoat() + } + return + } + if (this.random.chance(10)) { this.sendBoat() return } diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index 1bfb8b98e..c2063c393 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -49,23 +49,32 @@ export class PortExecution implements Execution { const alliedPorts = this.player().alliances().map(a => a.other(this.player())).flatMap(p => p.units(UnitType.Port)) const alliedPortsSet = new Set(alliedPorts) + const allyConnections = new Set(Array.from(this.portPaths.keys()).map(p => p.owner())) + allyConnections + + for (const port of alliedPorts) { + if (allyConnections.has(port.owner())) { + continue + } + allyConnections.add(port.owner()) if (this.computingPaths.has(port)) { const aStar = this.computingPaths.get(port) switch (aStar.compute()) { case PathFindResultType.Completed: this.portPaths.set(port, aStar.reconstructPath()) this.computingPaths.delete(port) + break case PathFindResultType.Pending: break case PathFindResultType.PathNotFound: console.warn(`path not found to port`) + break } continue - } else if (!this.portPaths.has(port)) { - this.computingPaths.set(port, new AStar(this.port.tile(), port.tile(), t => t.isWater(), 2000, 100)) - continue } + // console.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`) + this.computingPaths.set(port, new AStar(this.port.tile(), port.tile(), t => t.isWater(), 4000, 100)) } for (const port of this.portPaths.keys()) { @@ -75,11 +84,13 @@ export class PortExecution implements Execution { } } - if (alliedPorts.length > 0 && this.random.chance(50)) { - const port = this.random.randElement(alliedPorts) + const portConnections = Array.from(this.portPaths.keys()) + + if (portConnections.length > 0 && this.random.chance(500 * this.player().units(UnitType.Port).length)) { + const port = this.random.randElement(portConnections) const path = this.portPaths.get(port) if (path != null) { - this.mg.addExecution(new TradeShipExecution(this._owner, this.port, port, path)) + this.mg.addExecution(new TradeShipExecution(this.player().id(), this.port, port, path)) } } }