mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 21:39:36 +00:00
added local build, improved spawnexec
This commit is contained in:
@@ -6,6 +6,7 @@ import {BotSpawner} from "./BotSpawner";
|
||||
import {BoatAttackExecution} from "./BoatAttackExecution";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {UpdateNameExecution} from "./UpdateNameExecution";
|
||||
import {FakeHumanExecution} from "./FakeHumanExecution";
|
||||
|
||||
|
||||
export class Executor {
|
||||
@@ -57,4 +58,9 @@ export class Executor {
|
||||
spawnBots(numBots: number): Execution[] {
|
||||
return new BotSpawner(this.gs).spawnBots(numBots).map(i => this.createExec(i))
|
||||
}
|
||||
|
||||
fakeHumanExecutions(numFakes: number): Execution[] {
|
||||
return [new FakeHumanExecution(null)]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game"
|
||||
import {PseudoRandom} from "../PseudoRandom"
|
||||
import {simpleHash} from "../Util";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
import {SpawnExecution} from "./SpawnExecution";
|
||||
|
||||
export class FakeHumanExecution implements Execution {
|
||||
|
||||
private active = true
|
||||
private random: PseudoRandom;
|
||||
private attackRate: number
|
||||
private mg: MutableGame
|
||||
private neighborsTerraNullius = true
|
||||
|
||||
|
||||
constructor(private bot: MutablePlayer) {
|
||||
this.random = new PseudoRandom(simpleHash(bot.id()))
|
||||
this.attackRate = this.random.nextInt(10, 50)
|
||||
}
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
this.mg = mg
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
|
||||
if (ticks < this.mg.config().numSpawnPhaseTurns()) {
|
||||
if(ticks % 10 == 0) {
|
||||
this.mg.addExecution(new SpawnExecution(
|
||||
null, null
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.bot.isAlive()) {
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
|
||||
if (ticks % this.attackRate != 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.neighborsTerraNullius) {
|
||||
for (const b of this.bot.borderTiles()) {
|
||||
for (const n of b.neighbors()) {
|
||||
if (n.owner() == this.mg.terraNullius() && n.isLand()) {
|
||||
this.sendAttack(this.mg.terraNullius())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
this.neighborsTerraNullius = false
|
||||
}
|
||||
|
||||
const border = Array.from(this.bot.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.bot)
|
||||
|
||||
if (border.length == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const toAttack = border[this.random.nextInt(0, border.length)]
|
||||
this.sendAttack(toAttack.owner())
|
||||
}
|
||||
|
||||
sendAttack(toAttack: Player | TerraNullius) {
|
||||
this.mg.addExecution(new AttackExecution(
|
||||
this.bot.troops() / 20,
|
||||
this.bot.id(),
|
||||
toAttack.isPlayer() ? toAttack.id() : null,
|
||||
null,
|
||||
null
|
||||
))
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return this.bot
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,9 @@ export class SpawnExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
if (!this.isActive()) {
|
||||
return
|
||||
}
|
||||
this.active = false
|
||||
|
||||
if (ticks >= this.mg.config().numSpawnPhaseTurns()) {
|
||||
this.active = false
|
||||
if (!this.mg.inSpawnPhase()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,8 +41,8 @@ export class SpawnExecution implements Execution {
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
this.mg.addExecution(new BotExecution(player))
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user