more efficient port calculation, npcs send fewer boats, fewer trade ships

This commit is contained in:
Evan
2024-11-22 14:42:48 -08:00
parent 45ff069d2c
commit 3f27f6e72c
4 changed files with 26 additions and 9 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
}
+7 -1
View File
@@ -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
}
+17 -6
View File
@@ -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))
}
}
}