diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index b29be40d1..34efdc2dd 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -1,4 +1,3 @@ -import {Player, PlayerInfo} from "../Game"; import {DefaultConfig} from "./DefaultConfig"; export const devConfig = new class extends DefaultConfig { @@ -16,9 +15,13 @@ export const devConfig = new class extends DefaultConfig { } numBots(): number { - return 500 + return 400 } + // numFakeHumans(gameID: GameID): number { + // return 10 + // } + // startTroops(playerInfo: PlayerInfo): number { // if (playerInfo.isBot) { // return 5000 diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index ea26fc8cc..bffd97574 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -28,11 +28,15 @@ export class AttackExecution implements Execution { constructor( private troops: number, private _ownerID: PlayerID, - private targetID: PlayerID | null, + private _targetID: PlayerID | null, private sourceCell: Cell | null, private targetCell: Cell | null, ) { } + public targetID(): PlayerID { + return this._targetID + } + activeDuringSpawnPhase(): boolean { return false } @@ -45,7 +49,7 @@ export class AttackExecution implements Execution { this.targetCell = null this._owner = mg.player(this._ownerID) - this.target = this.targetID == null ? mg.terraNullius() : mg.player(this.targetID) + this.target = this._targetID == null ? mg.terraNullius() : mg.player(this._targetID) this.troops = Math.min(this._owner.troops(), this.troops) this._owner.setTroops(this._owner.troops() - this.troops) this.mg = mg @@ -54,7 +58,7 @@ export class AttackExecution implements Execution { if (exec.isActive() && exec instanceof AttackExecution && exec != this) { const otherAttack = exec as AttackExecution // Target has opposing attack, cancel them out - if (this.target.isPlayer() && otherAttack.targetID == this._ownerID && this.targetID == otherAttack._ownerID) { + if (this.target.isPlayer() && otherAttack._targetID == this._ownerID && this._targetID == otherAttack._ownerID) { if (otherAttack.troops > this.troops) { otherAttack.troops -= this.troops // otherAttack.calculateToConquer() @@ -66,7 +70,7 @@ export class AttackExecution implements Execution { } } // Existing attack on same target, add troops - if (otherAttack._owner == this._owner && otherAttack.targetID == this.targetID && this.sourceCell == otherAttack.sourceCell) { + if (otherAttack._owner == this._owner && otherAttack._targetID == this._targetID && this.sourceCell == otherAttack.sourceCell) { otherAttack.troops += this.troops otherAttack.refreshToConquer() this.active = false diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index d8e1f5262..61ab4d352 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,4 +1,4 @@ -import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerrainType, TerraNullius, Tile} from "../Game" +import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../Game" import {PseudoRandom} from "../PseudoRandom" import {and, bfs, dist, simpleHash} from "../Util"; import {AttackExecution} from "./AttackExecution"; @@ -14,6 +14,8 @@ export class FakeHumanExecution implements Execution { private neighborsTerraNullius = true private player: Player = null + private enemy: Player | null = null + constructor(private playerInfo: PlayerInfo) { this.random = new PseudoRandom(simpleHash(playerInfo.id)) @@ -49,6 +51,27 @@ export class FakeHumanExecution implements Execution { return } + if (ticks % 100 == 0) { + this.enemy = null + } + + if (this.enemy == null) { + this.enemy = this.mg.executions() + .filter(e => e instanceof AttackExecution) + .map(e => e as AttackExecution) + .filter(e => e.targetID() == this.player.id()) + .map(e => e.owner()) + .find(enemy => enemy && enemy.type() == PlayerType.Human) + } + + if (this.enemy) { + if (this.player.sharesBorderWith(this.enemy)) { + this.sendAttack(this.enemy) + } + return + } + + if (this.neighborsTerraNullius) { for (const b of this.player.borderTiles()) { for (const n of b.neighbors()) {