From be447a677498935d51ae053baac36b5e8800428b Mon Sep 17 00:00:00 2001 From: Scott Anderson <662325+scottanderson@users.noreply.github.com> Date: Tue, 26 Aug 2025 17:57:40 -0400 Subject: [PATCH] Nations send emoji when declining assistance requests (#1911) ## Description: Nations will now send emoji when declining assistance requests. ## 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 --- src/core/Util.ts | 6 ++-- src/core/execution/FakeHumanExecution.ts | 8 ++--- src/core/execution/utils/BotBehavior.ts | 38 +++++++++++++++++++----- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/core/Util.ts b/src/core/Util.ts index cb919dd72..a94637404 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -280,7 +280,7 @@ export function createRandomName( return randomName; } -export const emojiTable: string[][] = [ +export const emojiTable = [ ["😀", "😊", "🥰", "😇", "😎"], ["😞", "🥺", "😭", "😱", "😡"], ["😈", "🤡", "🖕", "🥱", "🤦‍♂️"], @@ -292,9 +292,9 @@ export const emojiTable: string[][] = [ ["⬅️", "🎯", "➡️", "🥈", "🥉"], ["↙️", "⬇️", "↘️", "❤️", "💔"], ["💰", "⚓", "⛵", "🏡", "🛡️"], -]; +] as const; // 2d to 1d array -export const flattenedEmojiTable: string[] = emojiTable.flat(); +export const flattenedEmojiTable = emojiTable.flat(); /** * JSON.stringify replacer function that converts bigint values to strings. diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 209fe6f61..7e79a9bf3 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,3 +1,4 @@ +import { BotBehavior, EMOJI_HECKLE } from "./utils/BotBehavior"; import { Cell, Difficulty, @@ -15,8 +16,7 @@ import { UnitType, } from "../game/Game"; import { TileRef, euclDistFN, manhattanDistFN } from "../game/GameMap"; -import { calculateBoundingBox, flattenedEmojiTable, simpleHash } from "../Util"; -import { BotBehavior } from "./utils/BotBehavior"; +import { calculateBoundingBox, simpleHash } from "../Util"; import { ConstructionExecution } from "./ConstructionExecution"; import { EmojiExecution } from "./EmojiExecution"; import { GameID } from "../Schemas"; @@ -43,7 +43,6 @@ export class FakeHumanExecution implements Execution { private readonly lastEmojiSent = new Map(); private readonly lastNukeSent: [Tick, TileRef][] = []; private readonly embargoMalusApplied = new Set(); - private readonly heckleEmoji: number[]; constructor( gameID: GameID, @@ -57,7 +56,6 @@ export class FakeHumanExecution implements Execution { this.triggerRatio = this.random.nextInt(60, 90) / 100; this.reserveRatio = this.random.nextInt(30, 60) / 100; this.expandRatio = this.random.nextInt(15, 25) / 100; - this.heckleEmoji = ["🤡", "😡"].map((e) => flattenedEmojiTable.indexOf(e)); } init(mg: Game) { @@ -281,7 +279,7 @@ export class FakeHumanExecution implements Execution { new EmojiExecution( this.player, enemy.id(), - this.random.randElement(this.heckleEmoji), + this.random.randElement(EMOJI_HECKLE), ), ); } diff --git a/src/core/execution/utils/BotBehavior.ts b/src/core/execution/utils/BotBehavior.ts index 76497968c..b93903aed 100644 --- a/src/core/execution/utils/BotBehavior.ts +++ b/src/core/execution/utils/BotBehavior.ts @@ -13,12 +13,34 @@ import { EmojiExecution } from "../EmojiExecution"; import { PseudoRandom } from "../../PseudoRandom"; import { flattenedEmojiTable } from "../../Util"; +const emojiId = (e: typeof flattenedEmojiTable[number]) => flattenedEmojiTable.indexOf(e); +const EMOJI_ASSIST_ACCEPT = ([ + "👍", + "⛵", + "🤝", + "🎯", +] as const).map(emojiId); +const EMOJI_RELATION_TOO_LOW = ([ + "🥱", + "🤦‍♂️", +] as const).map(emojiId); +const EMOJI_TARGET_ME = ([ + "🥺", + "💀", +] as const).map(emojiId); +const EMOJI_TARGET_ALLY = ([ + "🕊️", + "👎", +] as const).map(emojiId); +export const EMOJI_HECKLE = ([ + "🤡", + "😡", +] as const).map(emojiId); + export class BotBehavior { private enemy: Player | null = null; private enemyUpdated: Tick | undefined; - private readonly assistAcceptEmoji = flattenedEmojiTable.indexOf("👍"); - constructor( private readonly random: PseudoRandom, private readonly game: Game, @@ -111,26 +133,26 @@ export class BotBehavior { } assistAllies() { - outer: for (const ally of this.player.allies()) { + for (const ally of this.player.allies()) { if (ally.targets().length === 0) continue; if (this.player.relation(ally) < Relation.Friendly) { - // this.emoji(ally, "🤦"); + this.emoji(ally, this.random.randElement(EMOJI_RELATION_TOO_LOW)); continue; } for (const target of ally.targets()) { if (target === this.player) { - // this.emoji(ally, "💀"); + this.emoji(ally, this.random.randElement(EMOJI_TARGET_ME)); continue; } if (this.player.isAlliedWith(target)) { - // this.emoji(ally, "👎"); + this.emoji(ally, this.random.randElement(EMOJI_TARGET_ALLY)); continue; } // All checks passed, assist them this.player.updateRelation(ally, -20); this.setNewEnemy(target); - this.emoji(ally, this.assistAcceptEmoji); - break outer; + this.emoji(ally, this.random.randElement(EMOJI_ASSIST_ACCEPT)); + return; } } }