From 5431aff30c4754f2b123d49b35cde93433d3e524 Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 23 Nov 2024 21:53:26 -0800 Subject: [PATCH] NPCs less agressive, trade ship less gold, NPCs recapture after nuke --- TODO.txt | 1 + src/core/configuration/DefaultConfig.ts | 4 +- src/core/execution/FakeHumanExecution.ts | 47 ++++++++++++------------ src/core/execution/TradeShipExecution.ts | 5 +++ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/TODO.txt b/TODO.txt index c291f578a..3e4235018 100644 --- a/TODO.txt +++ b/TODO.txt @@ -192,6 +192,7 @@ * BUG: fix matchmaking DONE 11/22/2024 * destroyer can capture trade ships DONE 11/22/2024 * have bots recapture after nuclear blast +* * NPC has relations * make NPC difficult scale better (not just start troops) * add battleship diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index acfcb8060..6462fac33 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -12,7 +12,7 @@ export class DefaultConfig implements Config { } tradeShipGold(src: Unit, dst: Unit): Gold { const dist = manhattanDist(src.tile().cell(), dst.tile().cell()) - return 10000 + 50 * dist + return 10000 + 5 * dist } unitInfo(type: UnitType): UnitInfo { switch (type) { @@ -207,7 +207,7 @@ export class DefaultConfig implements Config { } goldAdditionRate(player: Player): number { - return Math.sqrt(player.workers() * player.numTilesOwned()) / 900 + return Math.sqrt(player.workers() * player.numTilesOwned()) / 600 } troopAdjustmentRate(player: Player): number { diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index e65cf7220..0cfd4f0c8 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -12,15 +12,12 @@ export class FakeHumanExecution implements Execution { private active = true private random: PseudoRandom; - private attackRate: number private mg: MutableGame - private neighborsTerraNullius = true private player: MutablePlayer = null private enemy: Player | null = null private rejected: Set = new Set - private isTraitor = false private relations = new Map() @@ -30,8 +27,8 @@ export class FakeHumanExecution implements Execution { init(mg: MutableGame, ticks: number) { this.mg = mg - if (this.random.chance(5)) { - this.isTraitor = true + if (this.random.chance(10)) { + // this.isTraitor = true } } @@ -81,19 +78,7 @@ export class FakeHumanExecution implements Execution { this.handleUnits() - if (this.neighborsTerraNullius) { - for (const b of this.player.borderTiles()) { - for (const n of b.neighbors()) { - if (n.owner() == this.mg.terraNullius() && n.isLand()) { - this.sendAttack(this.mg.terraNullius()) - return - } - } - } - this.neighborsTerraNullius = false - } - - const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player) + const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.isLand() && t.owner() != this.player) if (enemyborder.length == 0) { if (this.random.chance(5)) { @@ -106,9 +91,15 @@ export class FakeHumanExecution implements Execution { return } - const enemies = enemyborder.map(t => t.owner()).filter(o => o.isPlayer()).map(o => o as Player).sort((a, b) => a.troops() - b.troops()) + const enemiesWithTN = enemyborder.map(t => t.owner()) + if (enemiesWithTN.filter(o => !o.isPlayer()).length > 0) { + this.sendAttack(this.mg.terraNullius()) + return + } - if (this.random.chance(10)) { + const enemies = enemiesWithTN.filter(o => o.isPlayer()).map(o => o as Player).sort((a, b) => a.troops() - b.troops()) + + if (this.random.chance(20)) { const toAlly = this.random.randElement(enemies) if (!this.player.isAlliedWith(toAlly) && !this.player.recentOrPendingAllianceRequestWith(toAlly)) { this.player.createAllianceRequest(toAlly) @@ -117,13 +108,21 @@ export class FakeHumanExecution implements Execution { } if (this.random.chance(2)) { - if (!this.player.isAlliedWith(enemies[0]) || (this.random.chance(50) && this.isTraitor)) { - this.sendAttack(enemies[0]) + const weakest = enemies[0] + if (!this.player.isAlliedWith(weakest)) { + if (weakest.info().playerType != PlayerType.Human || weakest.isTraitor()) { + this.sendAttack(weakest) + } } } else { const toAttack = this.random.randElement(enemies) - if (!this.player.isAlliedWith(toAttack) || (this.random.chance(100) && this.isTraitor)) { - this.sendAttack(toAttack) + if (!this.player.isAlliedWith(toAttack)) { + if (toAttack.info().playerType != PlayerType.Human || toAttack.isTraitor()) { + this.sendAttack(toAttack) + } else if (this.random.chance(4)) { + // Less likely to attack players who are not traitors. + this.sendAttack(toAttack) + } } } } diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index ffe9d87f5..6b0ae03b5 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -82,6 +82,11 @@ export class TradeShipExecution implements Execution { } return } + if(!this.dstPort.isActive() || !this.tradeShip.owner().isAlliedWith(this.dstPort.owner())) { + this.tradeShip.delete() + this.active = false + return + } if (this.index >= this.path.length) {