add difficulties

This commit is contained in:
Evan
2024-10-23 21:08:24 -07:00
parent c08645a7fe
commit 56d4b924fa
15 changed files with 154 additions and 88 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent} from "../game/Game";
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent, Difficulty} from "../game/Game";
import {AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn} from "../Schemas";
import {AttackExecution} from "./AttackExecution";
import {SpawnExecution} from "./SpawnExecution";
@@ -26,7 +26,7 @@ export class Executor {
// private random = new PseudoRandom(999)
private random: PseudoRandom = null
constructor(private gs: Game, private gameID: GameID) {
constructor(private gs: Game, private difficulty: Difficulty, private gameID: GameID) {
// Add one to avoid id collisions with bots.
this.random = new PseudoRandom(simpleHash(gameID) + 1)
}
@@ -98,7 +98,7 @@ export class Executor {
this.random.nextID()
),
nation.cell,
nation.strength
nation.strength * this.difficulty
))
}
return execs
+14 -7
View File
@@ -1,12 +1,14 @@
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../game/Game"
import {PseudoRandom} from "../PseudoRandom"
import {and, bfs, dist, simpleHash} from "../Util";
import {AttackExecution} from "./AttackExecution";
import {BoatAttackExecution} from "./BoatAttackExecution";
import {SpawnExecution} from "./SpawnExecution";
import { Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile } from "../game/Game"
import { PseudoRandom } from "../PseudoRandom"
import { and, bfs, dist, simpleHash } from "../Util";
import { AttackExecution } from "./AttackExecution";
import { BoatAttackExecution } from "./BoatAttackExecution";
import { SpawnExecution } from "./SpawnExecution";
export class FakeHumanExecution implements Execution {
private firstMove = true
private active = true
private random: PseudoRandom;
private attackRate: number
@@ -56,6 +58,11 @@ export class FakeHumanExecution implements Execution {
this.player.setTroops(this.player.troops() * this.strength)
}
}
if (this.firstMove) {
this.firstMove = false
this.sendAttack(this.mg.terraNullius())
return
}
if (this.player.troops() < this.mg.config().maxTroops(this.player) / 4) {
return
@@ -132,7 +139,7 @@ export class FakeHumanExecution implements Execution {
handleAllianceRequests() {
for (const req of this.player.incomingAllianceRequests()) {
if (req.requestor().numTilesOwned() > this.player.numTilesOwned() * 2) {
if (req.requestor().numTilesOwned() > this.player.numTilesOwned() * 2) {
req.accept()
continue
}