From e9d9fe1d981bfd271af24d7fe01f0daa811181c4 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 30 Dec 2024 13:21:46 -0800 Subject: [PATCH] make hard & impossible more difficult --- src/core/configuration/DefaultConfig.ts | 13 ++++++ src/core/configuration/DevConfig.ts | 15 +++---- src/core/execution/FakeHumanExecution.ts | 52 ++++++++++++++++-------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 3bd6cc976..dd61637d2 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -288,6 +288,19 @@ export class DefaultConfig implements Config { if (player.type() == PlayerType.Bot) { toAdd *= .7 } + let difficultyMultiplier = 1 + switch (this._gameConfig.difficulty) { + case Difficulty.Easy: + case Difficulty.Medium: + difficultyMultiplier = 1 + case Difficulty.Hard: + difficultyMultiplier = 1.2 + case Difficulty.Impossible: + difficultyMultiplier = 1.5 + } + if (player.type() == PlayerType.FakeHuman) { + toAdd *= difficultyMultiplier + } return Math.min(player.population() + toAdd, max) - player.population() } diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index f7e40f486..0b71918a7 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -23,16 +23,13 @@ export class DevConfig extends DefaultConfig { // return 100 } - unitInfo(type: UnitType): UnitInfo { - const info = super.unitInfo(type) - const oldCost = info.cost - info.cost = (p: Player) => oldCost(p) / 10000 - return info - } + // unitInfo(type: UnitType): UnitInfo { + // const info = super.unitInfo(type) + // const oldCost = info.cost + // info.cost = (p: Player) => oldCost(p) / 10000 + // return info + // } - percentageTilesOwnedToWin(): number { - return 95 - } // tradeShipSpawnRate(): number { // return 10 // } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index b8eae57bd..812b0e683 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,4 +1,4 @@ -import { AllianceRequest, Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, Tile, UnitType } from "../game/Game" +import { AllianceRequest, Cell, Difficulty, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, Tile, UnitType } from "../game/Game" import { PseudoRandom } from "../PseudoRandom" import { and, bfs, calculateBoundingBox, dist, euclDist, manhattanDist, simpleHash } from "../Util"; import { AttackExecution } from "./AttackExecution"; @@ -118,26 +118,42 @@ export class FakeHumanExecution implements Execution { } } - if (this.random.chance(2)) { - 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)) { - 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) - } - } + // 50-50 attack weakest player vs random player + const toAttack = this.random.chance(2) ? enemies[0] : this.random.randElement(enemies) + if (this.shouldAttack(toAttack)) { + this.sendAttack(toAttack) } } + private shouldAttack(other: Player): boolean { + if (this.player.isAlliedWith(other)) { + if (this.shouldDiscourageAttack(other)) { + return this.random.chance(100) + } + return this.random.chance(20) + } else { + if (this.shouldDiscourageAttack(other)) { + return this.random.chance(4) + } + return true + } + } + + shouldDiscourageAttack(other: Player) { + if (other.isTraitor) { + return false + } + const difficulty = this.mg.config().gameConfig().difficulty + if (difficulty == Difficulty.Hard || difficulty == Difficulty.Impossible) { + return false + } + if (other.type() != PlayerType.Human) { + return false + } + // Only discourage attacks on Humans who are not traitors on easy or medium difficulty. + return true + } + handleEnemies() { if (this.mg.ticks() - this.lastEnemyUpdateTick > 100) { this.enemy = null