mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-29 03:44:40 +00:00
bot attacks terranullius first
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user