bot attacks terranullius first

This commit is contained in:
evanpelle
2024-08-11 17:57:24 -07:00
parent 14e7cb2ac9
commit fab17bd48a
3 changed files with 38 additions and 12 deletions
+26 -8
View File
@@ -1,4 +1,4 @@
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, PlayerInfo} from "../Game"
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game"
import {PseudoRandom} from "../PseudoRandom"
import {AttackExecution} from "./AttackExecution";
@@ -8,6 +8,7 @@ export class BotExecution implements Execution {
private random: PseudoRandom;
private attackRate: number
private gs: MutableGame
private neighborsTerra = true
constructor(private bot: MutablePlayer) {
@@ -17,6 +18,7 @@ export class BotExecution implements Execution {
init(gs: MutableGame, ticks: number) {
this.gs = gs
// this.neighborsTerra = this.bot.neighbors().filter(n => n == this.gs.terraNullius()).length > 0
}
tick(ticks: number) {
@@ -27,22 +29,38 @@ export class BotExecution implements Execution {
if (ticks % this.attackRate == 0) {
if (this.neighborsTerra) {
for (const b of this.bot.borderTiles()) {
for (const n of b.neighbors()) {
if (n.owner() == this.gs.terraNullius()) {
this.sendAttack(this.gs.terraNullius())
return
}
}
}
this.neighborsTerra = false
}
const ns = this.bot.neighbors()
if (ns.length == 0) {
return
}
const toAttack = ns[this.random.nextInt(0, ns.length)]
this.sendAttack(toAttack)
this.gs.addExecution(new AttackExecution(
this.bot.troops() / 100,
this.bot.id(),
toAttack.isPlayer() ? toAttack.id() : null,
null
))
}
}
sendAttack(toAttack: Player | TerraNullius) {
this.gs.addExecution(new AttackExecution(
this.bot.troops() / 20,
this.bot.id(),
toAttack.isPlayer() ? toAttack.id() : null,
null
))
}
owner(): MutablePlayer {
return this.bot
}