Skip to content

Commit 41deef9

Browse files
authored
Nations no longer send random boats to their bordering enemies 🚢 (#2526)
## Description: Nations no longer send random boats to their bordering enemies. Usually it looked a bit stupid when nations did that ("Why don't you attack your bordering enemy directly?") ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
1 parent c38c25a commit 41deef9

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

‎src/core/execution/FakeHumanExecution.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,36 +206,35 @@ export class FakeHumanExecution implements Execution {
206206
if (this.player === null || this.behavior === null) {
207207
throw new Error("not initialized");
208208
}
209+
209210
const enemyborder = Array.from(this.player.borderTiles())
210211
.flatMap((t) => this.mg.neighbors(t))
211212
.filter(
212213
(t) =>
213214
this.mg.isLand(t) && this.mg.ownerID(t) !== this.player?.smallID(),
214215
);
216+
const borderPlayers = enemyborder.map((t) =>
217+
this.mg.playerBySmallID(this.mg.ownerID(t)),
218+
);
219+
const borderingEnemies = borderPlayers
220+
.filter((o) => o.isPlayer())
221+
.sort((a, b) => a.troops() - b.troops());
215222

216-
let borderingEnemies: Player[] = [];
217223
if (enemyborder.length === 0) {
218224
if (this.random.chance(5)) {
219-
this.sendBoatRandomly();
225+
this.sendBoatRandomly(borderingEnemies);
220226
}
221227
} else {
222228
if (this.random.chance(10)) {
223-
this.sendBoatRandomly();
229+
this.sendBoatRandomly(borderingEnemies);
224230
return;
225231
}
226232

227-
const borderPlayers = enemyborder.map((t) =>
228-
this.mg.playerBySmallID(this.mg.ownerID(t)),
229-
);
230233
if (borderPlayers.some((o) => !o.isPlayer())) {
231234
this.behavior.sendAttack(this.mg.terraNullius());
232235
return;
233236
}
234237

235-
borderingEnemies = borderPlayers
236-
.filter((o) => o.isPlayer())
237-
.sort((a, b) => a.troops() - b.troops());
238-
239238
// 5% chance to send a random alliance request
240239
if (this.random.chance(20)) {
241240
const toAlly = this.random.randElement(borderingEnemies);
@@ -598,7 +597,7 @@ export class FakeHumanExecution implements Execution {
598597
return this.mg.unitInfo(type).cost(this.player);
599598
}
600599

601-
sendBoatRandomly() {
600+
sendBoatRandomly(borderingEnemies: Player[]) {
602601
if (this.player === null) throw new Error("not initialized");
603602
const oceanShore = Array.from(this.player.borderTiles()).filter((t) =>
604603
this.mg.isOceanShore(t),
@@ -610,10 +609,10 @@ export class FakeHumanExecution implements Execution {
610609
const src = this.random.randElement(oceanShore);
611610

612611
// First look for high-interest targets (unowned or bot-owned). Mainly relevant for earlygame
613-
let dst = this.randomBoatTarget(src, 150, true);
612+
let dst = this.randomBoatTarget(src, borderingEnemies, true);
614613
if (dst === null) {
615614
// None found? Then look for players
616-
dst = this.randomBoatTarget(src, 150, false);
615+
dst = this.randomBoatTarget(src, borderingEnemies, false);
617616
if (dst === null) {
618617
return;
619618
}
@@ -658,15 +657,15 @@ export class FakeHumanExecution implements Execution {
658657

659658
private randomBoatTarget(
660659
tile: TileRef,
661-
dist: number,
660+
borderingEnemies: Player[],
662661
highInterestOnly: boolean = false,
663662
): TileRef | null {
664663
if (this.player === null) throw new Error("not initialized");
665664
const x = this.mg.x(tile);
666665
const y = this.mg.y(tile);
667666
for (let i = 0; i < 500; i++) {
668-
const randX = this.random.nextInt(x - dist, x + dist);
669-
const randY = this.random.nextInt(y - dist, y + dist);
667+
const randX = this.random.nextInt(x - 150, x + 150);
668+
const randY = this.random.nextInt(y - 150, y + 150);
670669
if (!this.mg.isValidCoord(randX, randY)) {
671670
continue;
672671
}
@@ -678,6 +677,10 @@ export class FakeHumanExecution implements Execution {
678677
if (owner === this.player) {
679678
continue;
680679
}
680+
// Don't send boats to players with which we share a border, that usually looks stupid
681+
if (owner.isPlayer() && borderingEnemies.includes(owner)) {
682+
continue;
683+
}
681684
// Don't spam boats into players that are more than twice as large as us
682685
if (owner.isPlayer() && owner.troops() > this.player.troops() * 2) {
683686
continue;

0 commit comments

Comments
 (0)