mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-06 10:54:21 +00:00
fake humans retaliate against humans
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import {Player, PlayerInfo} from "../Game";
|
|
||||||
import {DefaultConfig} from "./DefaultConfig";
|
import {DefaultConfig} from "./DefaultConfig";
|
||||||
|
|
||||||
export const devConfig = new class extends DefaultConfig {
|
export const devConfig = new class extends DefaultConfig {
|
||||||
@@ -16,9 +15,13 @@ export const devConfig = new class extends DefaultConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
numBots(): number {
|
numBots(): number {
|
||||||
return 500
|
return 400
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// numFakeHumans(gameID: GameID): number {
|
||||||
|
// return 10
|
||||||
|
// }
|
||||||
|
|
||||||
// startTroops(playerInfo: PlayerInfo): number {
|
// startTroops(playerInfo: PlayerInfo): number {
|
||||||
// if (playerInfo.isBot) {
|
// if (playerInfo.isBot) {
|
||||||
// return 5000
|
// return 5000
|
||||||
|
|||||||
@@ -28,11 +28,15 @@ export class AttackExecution implements Execution {
|
|||||||
constructor(
|
constructor(
|
||||||
private troops: number,
|
private troops: number,
|
||||||
private _ownerID: PlayerID,
|
private _ownerID: PlayerID,
|
||||||
private targetID: PlayerID | null,
|
private _targetID: PlayerID | null,
|
||||||
private sourceCell: Cell | null,
|
private sourceCell: Cell | null,
|
||||||
private targetCell: Cell | null,
|
private targetCell: Cell | null,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
public targetID(): PlayerID {
|
||||||
|
return this._targetID
|
||||||
|
}
|
||||||
|
|
||||||
activeDuringSpawnPhase(): boolean {
|
activeDuringSpawnPhase(): boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -45,7 +49,7 @@ export class AttackExecution implements Execution {
|
|||||||
this.targetCell = null
|
this.targetCell = null
|
||||||
|
|
||||||
this._owner = mg.player(this._ownerID)
|
this._owner = mg.player(this._ownerID)
|
||||||
this.target = this.targetID == null ? mg.terraNullius() : mg.player(this.targetID)
|
this.target = this._targetID == null ? mg.terraNullius() : mg.player(this._targetID)
|
||||||
this.troops = Math.min(this._owner.troops(), this.troops)
|
this.troops = Math.min(this._owner.troops(), this.troops)
|
||||||
this._owner.setTroops(this._owner.troops() - this.troops)
|
this._owner.setTroops(this._owner.troops() - this.troops)
|
||||||
this.mg = mg
|
this.mg = mg
|
||||||
@@ -54,7 +58,7 @@ export class AttackExecution implements Execution {
|
|||||||
if (exec.isActive() && exec instanceof AttackExecution && exec != this) {
|
if (exec.isActive() && exec instanceof AttackExecution && exec != this) {
|
||||||
const otherAttack = exec as AttackExecution
|
const otherAttack = exec as AttackExecution
|
||||||
// Target has opposing attack, cancel them out
|
// Target has opposing attack, cancel them out
|
||||||
if (this.target.isPlayer() && otherAttack.targetID == this._ownerID && this.targetID == otherAttack._ownerID) {
|
if (this.target.isPlayer() && otherAttack._targetID == this._ownerID && this._targetID == otherAttack._ownerID) {
|
||||||
if (otherAttack.troops > this.troops) {
|
if (otherAttack.troops > this.troops) {
|
||||||
otherAttack.troops -= this.troops
|
otherAttack.troops -= this.troops
|
||||||
// otherAttack.calculateToConquer()
|
// otherAttack.calculateToConquer()
|
||||||
@@ -66,7 +70,7 @@ export class AttackExecution implements Execution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Existing attack on same target, add troops
|
// Existing attack on same target, add troops
|
||||||
if (otherAttack._owner == this._owner && otherAttack.targetID == this.targetID && this.sourceCell == otherAttack.sourceCell) {
|
if (otherAttack._owner == this._owner && otherAttack._targetID == this._targetID && this.sourceCell == otherAttack.sourceCell) {
|
||||||
otherAttack.troops += this.troops
|
otherAttack.troops += this.troops
|
||||||
otherAttack.refreshToConquer()
|
otherAttack.refreshToConquer()
|
||||||
this.active = false
|
this.active = false
|
||||||
|
|||||||
@@ -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 {PseudoRandom} from "../PseudoRandom"
|
||||||
import {and, bfs, dist, simpleHash} from "../Util";
|
import {and, bfs, dist, simpleHash} from "../Util";
|
||||||
import {AttackExecution} from "./AttackExecution";
|
import {AttackExecution} from "./AttackExecution";
|
||||||
@@ -14,6 +14,8 @@ export class FakeHumanExecution implements Execution {
|
|||||||
private neighborsTerraNullius = true
|
private neighborsTerraNullius = true
|
||||||
private player: Player = null
|
private player: Player = null
|
||||||
|
|
||||||
|
private enemy: Player | null = null
|
||||||
|
|
||||||
|
|
||||||
constructor(private playerInfo: PlayerInfo) {
|
constructor(private playerInfo: PlayerInfo) {
|
||||||
this.random = new PseudoRandom(simpleHash(playerInfo.id))
|
this.random = new PseudoRandom(simpleHash(playerInfo.id))
|
||||||
@@ -49,6 +51,27 @@ export class FakeHumanExecution implements Execution {
|
|||||||
return
|
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) {
|
if (this.neighborsTerraNullius) {
|
||||||
for (const b of this.player.borderTiles()) {
|
for (const b of this.player.borderTiles()) {
|
||||||
for (const n of b.neighbors()) {
|
for (const n of b.neighbors()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user