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
+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()) {