make hard & impossible more difficult

This commit is contained in:
Evan
2024-12-30 13:21:46 -08:00
parent f4c98318b6
commit e9d9fe1d98
3 changed files with 53 additions and 27 deletions
+13
View File
@@ -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()
}
+6 -9
View File
@@ -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
// }
+34 -18
View File
@@ -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