bots don't attack allies

This commit is contained in:
evanpelle
2024-09-17 21:01:57 -07:00
parent 0ef18a1602
commit 4bab6a5271
4 changed files with 11 additions and 0 deletions
+4
View File
@@ -64,7 +64,11 @@ export class BotExecution implements Execution {
const toAttack = border[this.random.nextInt(0, border.length)]
const owner = toAttack.owner()
if (owner.isPlayer()) {
if (this.bot.alliedWith(owner)) {
return
}
if (owner.type() == PlayerType.FakeHuman) {
if (!this.random.chance(2)) {
return
+1
View File
@@ -138,6 +138,7 @@ export interface Player {
incomingAllianceRequests(): AllianceRequest[]
outgoingAllianceRequests(): AllianceRequest[]
alliances(): Alliance[]
alliedWith(other: Player): boolean
toString(): string
}
+5
View File
@@ -120,6 +120,11 @@ export class PlayerImpl implements MutablePlayer {
return this.gs.alliances_.filter(a => a.requestor() == this || a.recipient() == this)
}
alliedWith(other: Player): boolean {
return this.alliances().find(a => a.recipient() == other || a.requestor() == other) != null
}
hash(): number {
return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());
}