fake humans retaliate against humans

This commit is contained in:
evanpelle
2024-09-11 20:39:27 -07:00
parent 16fa019927
commit 18cf457c3a
3 changed files with 37 additions and 7 deletions
+5 -2
View File
@@ -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
+8 -4
View File
@@ -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
+24 -1
View File
@@ -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()) {