mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-07 11:09:34 +00:00
bot attacks terranullius first
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
* render player info efficiently DONE 8/11/2024
|
* render player info efficiently DONE 8/11/2024
|
||||||
* better troop addition logic DONE 8/11/2024
|
* better troop addition logic DONE 8/11/2024
|
||||||
* better expansion, add back directed expansion
|
* better expansion, add back directed expansion
|
||||||
|
* harder to expand on other players (defense)
|
||||||
* use pastel theme for territories
|
* use pastel theme for territories
|
||||||
* improve front page
|
* improve front page
|
||||||
* add username in front page
|
* add username in front page
|
||||||
|
|||||||
+11
-4
@@ -10,6 +10,7 @@ type CellString = string
|
|||||||
class TileImpl implements Tile {
|
class TileImpl implements Tile {
|
||||||
|
|
||||||
public _isBorder = false
|
public _isBorder = false
|
||||||
|
private _neighbors: Tile[] = null
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly gs: GameImpl,
|
private readonly gs: GameImpl,
|
||||||
@@ -32,7 +33,10 @@ class TileImpl implements Tile {
|
|||||||
terrain(): TerrainType {return this._terrain}
|
terrain(): TerrainType {return this._terrain}
|
||||||
|
|
||||||
neighbors(): Tile[] {
|
neighbors(): Tile[] {
|
||||||
return this.gs.neighbors(this)
|
if (this._neighbors == null) {
|
||||||
|
this._neighbors = this.gs.neighbors(this)
|
||||||
|
}
|
||||||
|
return this._neighbors
|
||||||
}
|
}
|
||||||
|
|
||||||
game(): Game {return this.gs}
|
game(): Game {return this.gs}
|
||||||
@@ -285,7 +289,6 @@ export class GameImpl implements MutableGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
neighbors(tile: Tile): Tile[] {
|
neighbors(tile: Tile): Tile[] {
|
||||||
this.assertIsOnMap(tile.cell())
|
|
||||||
const x = tile.cell().x
|
const x = tile.cell().x
|
||||||
const y = tile.cell().y
|
const y = tile.cell().y
|
||||||
const ns: TileImpl[] = []
|
const ns: TileImpl[] = []
|
||||||
@@ -338,7 +341,11 @@ export class GameImpl implements MutableGame {
|
|||||||
const tiles: Tile[] = []
|
const tiles: Tile[] = []
|
||||||
tiles.push(tile)
|
tiles.push(tile)
|
||||||
tile.neighbors().forEach(t => tiles.push(t))
|
tile.neighbors().forEach(t => tiles.push(t))
|
||||||
tiles.filter(t => t.hasOwner()).forEach(t => {
|
|
||||||
|
for (const t of tiles) {
|
||||||
|
if (!t.hasOwner()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (this.isBorder(t)) {
|
if (this.isBorder(t)) {
|
||||||
(t.owner() as PlayerImpl)._borderTiles.set(t.cell().toString(), t);
|
(t.owner() as PlayerImpl)._borderTiles.set(t.cell().toString(), t);
|
||||||
(t.owner() as PlayerImpl)._borderTileSet.add(t);
|
(t.owner() as PlayerImpl)._borderTileSet.add(t);
|
||||||
@@ -348,7 +355,7 @@ export class GameImpl implements MutableGame {
|
|||||||
(t.owner() as PlayerImpl)._borderTileSet.delete(t);
|
(t.owner() as PlayerImpl)._borderTileSet.delete(t);
|
||||||
(t as TileImpl)._isBorder = false
|
(t as TileImpl)._isBorder = false
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isBorder(tile: Tile): boolean {
|
isBorder(tile: Tile): boolean {
|
||||||
|
|||||||
@@ -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 {PseudoRandom} from "../PseudoRandom"
|
||||||
import {AttackExecution} from "./AttackExecution";
|
import {AttackExecution} from "./AttackExecution";
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ export class BotExecution implements Execution {
|
|||||||
private random: PseudoRandom;
|
private random: PseudoRandom;
|
||||||
private attackRate: number
|
private attackRate: number
|
||||||
private gs: MutableGame
|
private gs: MutableGame
|
||||||
|
private neighborsTerra = true
|
||||||
|
|
||||||
constructor(private bot: MutablePlayer) {
|
constructor(private bot: MutablePlayer) {
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ export class BotExecution implements Execution {
|
|||||||
|
|
||||||
init(gs: MutableGame, ticks: number) {
|
init(gs: MutableGame, ticks: number) {
|
||||||
this.gs = gs
|
this.gs = gs
|
||||||
|
// this.neighborsTerra = this.bot.neighbors().filter(n => n == this.gs.terraNullius()).length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(ticks: number) {
|
tick(ticks: number) {
|
||||||
@@ -27,22 +29,38 @@ export class BotExecution implements Execution {
|
|||||||
|
|
||||||
|
|
||||||
if (ticks % this.attackRate == 0) {
|
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()
|
const ns = this.bot.neighbors()
|
||||||
if (ns.length == 0) {
|
if (ns.length == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const toAttack = ns[this.random.nextInt(0, ns.length)]
|
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 {
|
owner(): MutablePlayer {
|
||||||
return this.bot
|
return this.bot
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user