@firestone-hs/simulate-bgs-battle 1.1.738 → 1.1.739
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cards/cards-data.js +63 -38
- package/dist/cards/cards-data.js.map +1 -1
- package/dist/cards/impl/trinket/soul-fermenter.js +1 -1
- package/dist/cards/impl/trinket/soul-fermenter.js.map +1 -1
- package/dist/input-sanitation.js +12 -9
- package/dist/input-sanitation.js.map +1 -1
- package/dist/simulate-bgs-battle.d.ts +1 -0
- package/dist/simulate-bgs-battle.js +114 -21
- package/dist/simulate-bgs-battle.js.map +1 -1
- package/dist/simulation/after-attack.d.ts +1 -1
- package/dist/simulation/after-attack.js +21 -21
- package/dist/simulation/after-attack.js.map +1 -1
- package/dist/simulation/attack.d.ts +1 -0
- package/dist/simulation/attack.js +1 -1
- package/dist/simulation/attack.js.map +1 -1
- package/dist/simulation/auras.js +24 -6
- package/dist/simulation/auras.js.map +1 -1
- package/dist/simulation/combat-profile.d.ts +13 -0
- package/dist/simulation/combat-profile.js +37 -0
- package/dist/simulation/combat-profile.js.map +1 -0
- package/dist/simulation/death-effects.js +3 -0
- package/dist/simulation/death-effects.js.map +1 -1
- package/dist/simulation/internal-game-state.d.ts +1 -0
- package/dist/simulation/internal-game-state.js.map +1 -1
- package/dist/simulation/simulator.js +16 -5
- package/dist/simulation/simulator.js.map +1 -1
- package/dist/simulation/spectator/spectator.d.ts +1 -0
- package/dist/simulation/spectator/spectator.js +22 -6
- package/dist/simulation/spectator/spectator.js.map +1 -1
- package/dist/simulation/start-of-combat/soc-action-processor.js +10 -0
- package/dist/simulation/start-of-combat/soc-action-processor.js.map +1 -1
- package/dist/utils.js +12 -18
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simulateBattle = exports.simulateSingleCombat = exports.assignCards = exports.applyOnAttackEffects = exports.doFullAttack = exports.triggerBattlecry = exports.hasRally = exports.triggerRally = exports.withRng = exports.random = exports.getActiveRng = exports.defaultRng = exports.createSeededRng = exports.isValidDeathrattleEnchantment = void 0;
|
|
3
|
+
exports.simulateBattle = exports.simulateSingleCombat = exports.assignCards = exports.ensureCardsLoaded = exports.applyOnAttackEffects = exports.doFullAttack = exports.triggerBattlecry = exports.hasRally = exports.triggerRally = exports.withRng = exports.random = exports.getActiveRng = exports.defaultRng = exports.createSeededRng = exports.isValidDeathrattleEnchantment = void 0;
|
|
4
4
|
const reference_data_1 = require("@firestone-hs/reference-data");
|
|
5
5
|
const cards_data_1 = require("./cards/cards-data");
|
|
6
6
|
const debug_state_1 = require("./debug-state");
|
|
@@ -10,6 +10,8 @@ const rng_1 = require("./services/rng");
|
|
|
10
10
|
const shared_state_1 = require("./simulation/shared-state");
|
|
11
11
|
const simulator_1 = require("./simulation/simulator");
|
|
12
12
|
const spectator_1 = require("./simulation/spectator/spectator");
|
|
13
|
+
const combat_profile_1 = require("./simulation/combat-profile");
|
|
14
|
+
const utils_1 = require("./services/utils");
|
|
13
15
|
var deathrattle_utils_1 = require("./simulation/deathrattle-utils");
|
|
14
16
|
Object.defineProperty(exports, "isValidDeathrattleEnchantment", { enumerable: true, get: function () { return deathrattle_utils_1.isValidDeathrattleEnchantment; } });
|
|
15
17
|
var rng_2 = require("./services/rng");
|
|
@@ -29,28 +31,106 @@ Object.defineProperty(exports, "doFullAttack", { enumerable: true, get: function
|
|
|
29
31
|
var on_attack_1 = require("./simulation/on-attack");
|
|
30
32
|
Object.defineProperty(exports, "applyOnAttackEffects", { enumerable: true, get: function () { return on_attack_1.applyOnAttackEffects; } });
|
|
31
33
|
const MAX_SAMPLE_RESIMS = 500;
|
|
34
|
+
const CARDS_LOAD_ATTEMPTS = 3;
|
|
32
35
|
let globalCards = new reference_data_1.AllCardsService();
|
|
36
|
+
let cardsInitPromise = null;
|
|
37
|
+
const verifiedCardDbs = new WeakSet();
|
|
38
|
+
const hasLoadedCards = (cards) => {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if (!cards) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (verifiedCardDbs.has(cards)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const probe = (_a = cards.getCard) === null || _a === void 0 ? void 0 : _a.call(cards, 'CS2_122');
|
|
47
|
+
if (probe === null || probe === void 0 ? void 0 : probe.id) {
|
|
48
|
+
verifiedCardDbs.add(cards);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const loaded = !!((_c = (_b = cards.getCards) === null || _b === void 0 ? void 0 : _b.call(cards)) === null || _c === void 0 ? void 0 : _c.length);
|
|
52
|
+
if (loaded) {
|
|
53
|
+
verifiedCardDbs.add(cards);
|
|
54
|
+
}
|
|
55
|
+
return loaded;
|
|
56
|
+
};
|
|
57
|
+
const loadCardsWithRetry = async (cards) => {
|
|
58
|
+
for (let attempt = 1; attempt <= CARDS_LOAD_ATTEMPTS; attempt++) {
|
|
59
|
+
try {
|
|
60
|
+
await cards.initializeCardsDb();
|
|
61
|
+
if (hasLoadedCards(cards)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
console.warn('[simulate-bgs-battle] cards still empty after initializeCardsDb', attempt);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.warn('[simulate-bgs-battle] cards load attempt failed', attempt, e);
|
|
68
|
+
}
|
|
69
|
+
if (attempt < CARDS_LOAD_ATTEMPTS) {
|
|
70
|
+
await (0, utils_1.sleep)(250 * attempt);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
const ensureCardsLoaded = async (cards = globalCards) => {
|
|
76
|
+
if (hasLoadedCards(cards)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (!cardsInitPromise) {
|
|
80
|
+
cardsInitPromise = loadCardsWithRetry(cards).then((ok) => {
|
|
81
|
+
if (!ok) {
|
|
82
|
+
cardsInitPromise = null;
|
|
83
|
+
}
|
|
84
|
+
return ok;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return cardsInitPromise;
|
|
88
|
+
};
|
|
89
|
+
exports.ensureCardsLoaded = ensureCardsLoaded;
|
|
33
90
|
const assignCards = (cards) => {
|
|
34
91
|
globalCards = cards;
|
|
92
|
+
cardsInitPromise = hasLoadedCards(cards) ? Promise.resolve(true) : null;
|
|
35
93
|
};
|
|
36
94
|
exports.assignCards = assignCards;
|
|
37
95
|
const simulateSingleCombat = (battleInput, cards, cardsData, options = {}) => {
|
|
38
|
-
var _a, _b
|
|
39
|
-
|
|
96
|
+
var _a, _b;
|
|
97
|
+
const profile = (0, combat_profile_1.combatProfileEnabled)();
|
|
98
|
+
const getCardsT0 = profile ? performance.now() : 0;
|
|
99
|
+
if (!hasLoadedCards(cards)) {
|
|
40
100
|
console.error('[simulate-bgs-battle] reference cards are empty, cannot simulate combat', cards);
|
|
41
101
|
return null;
|
|
42
102
|
}
|
|
43
|
-
|
|
44
|
-
|
|
103
|
+
if (profile) {
|
|
104
|
+
(0, combat_profile_1.combatProfileAdd)('getCardsMs', performance.now() - getCardsT0);
|
|
105
|
+
}
|
|
106
|
+
const rng = (_a = options.rng) !== null && _a !== void 0 ? _a : (options.seed !== undefined ? (0, rng_1.createSeededRng)(options.seed) : rng_1.defaultRng);
|
|
107
|
+
const includeSpectator = (_b = options.includeSpectator) !== null && _b !== void 0 ? _b : false;
|
|
45
108
|
applyDebugStateFromInput(battleInput);
|
|
46
109
|
try {
|
|
110
|
+
const buildT0 = profile ? performance.now() : 0;
|
|
47
111
|
const inputReady = (0, input_sanitation_1.buildFinalInput)(battleInput, cards, cardsData);
|
|
48
|
-
|
|
49
|
-
|
|
112
|
+
if (profile) {
|
|
113
|
+
(0, combat_profile_1.combatProfileAdd)('buildFinalInputMs', performance.now() - buildT0);
|
|
114
|
+
}
|
|
115
|
+
const cloneTemplate = () => {
|
|
116
|
+
const cloneT0 = profile ? performance.now() : 0;
|
|
117
|
+
const cloned = (0, input_clone_1.cloneInput3)(inputReady);
|
|
118
|
+
if (profile) {
|
|
119
|
+
(0, combat_profile_1.combatProfileAdd)('cloneMs', performance.now() - cloneT0);
|
|
120
|
+
}
|
|
121
|
+
return cloned;
|
|
122
|
+
};
|
|
123
|
+
const spectator = includeSpectator ? new spectator_1.Spectator(true) : spectator_1.noopSpectator;
|
|
50
124
|
if (includeSpectator) {
|
|
51
125
|
spectator.startRecording();
|
|
52
126
|
}
|
|
53
|
-
|
|
127
|
+
const runT0 = profile ? performance.now() : 0;
|
|
128
|
+
const result = (0, rng_1.withRng)(rng, () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, rng));
|
|
129
|
+
if (profile) {
|
|
130
|
+
(0, combat_profile_1.combatProfileAdd)('runBattleMs', performance.now() - runT0);
|
|
131
|
+
(0, combat_profile_1.combatProfileTickFight)();
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
54
134
|
}
|
|
55
135
|
finally {
|
|
56
136
|
clearDebugStateFromInput(battleInput);
|
|
@@ -61,11 +141,23 @@ exports.default = async (event) => {
|
|
|
61
141
|
var _a, _b, _c, _d, _e, _f;
|
|
62
142
|
if (!((_a = event.body) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
63
143
|
console.warn('missing event body', event);
|
|
64
|
-
return
|
|
144
|
+
return {
|
|
145
|
+
statusCode: 400,
|
|
146
|
+
isBase64Encoded: false,
|
|
147
|
+
body: null,
|
|
148
|
+
};
|
|
65
149
|
}
|
|
66
150
|
const battleInput = JSON.parse(event.body);
|
|
67
151
|
const cards = globalCards;
|
|
68
|
-
await
|
|
152
|
+
const cardsLoaded = await (0, exports.ensureCardsLoaded)(cards);
|
|
153
|
+
if (!cardsLoaded) {
|
|
154
|
+
console.error('[simulate-bgs-battle] failed to load reference cards after retries');
|
|
155
|
+
return {
|
|
156
|
+
statusCode: 503,
|
|
157
|
+
isBase64Encoded: false,
|
|
158
|
+
body: JSON.stringify({ error: 'cards_unavailable' }),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
69
161
|
const cardsData = new cards_data_1.CardsData(cards, false);
|
|
70
162
|
cardsData.inititialize((_c = (_b = battleInput.gameState) === null || _b === void 0 ? void 0 : _b.validTribes) !== null && _c !== void 0 ? _c : (_d = battleInput.options) === null || _d === void 0 ? void 0 : _d.validTribes, (_f = (_e = battleInput.gameState) === null || _e === void 0 ? void 0 : _e.anomalies) !== null && _f !== void 0 ? _f : []);
|
|
71
163
|
const battleIterator = (0, exports.simulateBattle)(battleInput, cards, cardsData);
|
|
@@ -82,18 +174,18 @@ exports.default = async (event) => {
|
|
|
82
174
|
return response;
|
|
83
175
|
};
|
|
84
176
|
const simulateBattle = function* (battleInput, cards, cardsData) {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
86
|
-
if (!(
|
|
177
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
178
|
+
if (!hasLoadedCards(cards)) {
|
|
87
179
|
console.error('[simulate-bgs-battle] reference cards are empty, cannot simulate battle', cards);
|
|
88
180
|
return null;
|
|
89
181
|
}
|
|
90
182
|
const start = Date.now();
|
|
91
|
-
const maxAcceptableDuration = ((
|
|
92
|
-
const hideMaxSimulationDurationWarning = (
|
|
93
|
-
const numberOfSimulations = ((
|
|
94
|
-
const intermediateSteps = (
|
|
95
|
-
const damageConfidence = (
|
|
96
|
-
const includeOutcomeSamples = (
|
|
183
|
+
const maxAcceptableDuration = ((_a = battleInput.options) === null || _a === void 0 ? void 0 : _a.maxAcceptableDuration) || 8000;
|
|
184
|
+
const hideMaxSimulationDurationWarning = (_c = (_b = battleInput.options) === null || _b === void 0 ? void 0 : _b.hideMaxSimulationDurationWarning) !== null && _c !== void 0 ? _c : false;
|
|
185
|
+
const numberOfSimulations = ((_d = battleInput.options) === null || _d === void 0 ? void 0 : _d.numberOfSimulations) || 8000;
|
|
186
|
+
const intermediateSteps = (_f = (_e = battleInput.options) === null || _e === void 0 ? void 0 : _e.intermediateResults) !== null && _f !== void 0 ? _f : 200;
|
|
187
|
+
const damageConfidence = (_h = (_g = battleInput.options) === null || _g === void 0 ? void 0 : _g.damageConfidence) !== null && _h !== void 0 ? _h : 0.9;
|
|
188
|
+
const includeOutcomeSamples = (_k = (_j = battleInput.options) === null || _j === void 0 ? void 0 : _j.includeOutcomeSamples) !== null && _k !== void 0 ? _k : true;
|
|
97
189
|
const simulationResult = {
|
|
98
190
|
wonLethal: 0,
|
|
99
191
|
won: 0,
|
|
@@ -120,7 +212,7 @@ const simulateBattle = function* (battleInput, cards, cardsData) {
|
|
|
120
212
|
const cloneTemplate = (0, input_clone_1.buildTemplateCloner)((0, input_clone_1.cloneInput3)(inputReady));
|
|
121
213
|
const runOne = () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, rng_1.defaultRng);
|
|
122
214
|
try {
|
|
123
|
-
!((
|
|
215
|
+
!((_l = battleInput.options) === null || _l === void 0 ? void 0 : _l.skipInfoLogs) && console.time('simulation');
|
|
124
216
|
const outcomes = {};
|
|
125
217
|
for (let i = 0; i < numberOfSimulations; i++) {
|
|
126
218
|
const battleResult = runOne();
|
|
@@ -139,7 +231,7 @@ const simulateBattle = function* (battleInput, cards, cardsData) {
|
|
|
139
231
|
simulationResult.lost++;
|
|
140
232
|
simulationResult.damageLost += battleResult.damageDealt;
|
|
141
233
|
simulationResult.damageLosts.push(battleResult.damageDealt);
|
|
142
|
-
outcomes[battleResult.damageDealt] = ((
|
|
234
|
+
outcomes[battleResult.damageDealt] = ((_m = outcomes[battleResult.damageDealt]) !== null && _m !== void 0 ? _m : 0) + 1;
|
|
143
235
|
if (battleInput.playerBoard.player.hpLeft &&
|
|
144
236
|
battleResult.damageDealt >= battleInput.playerBoard.player.hpLeft) {
|
|
145
237
|
simulationResult.lostLethal++;
|
|
@@ -158,7 +250,7 @@ const simulateBattle = function* (battleInput, cards, cardsData) {
|
|
|
158
250
|
}
|
|
159
251
|
}
|
|
160
252
|
updateSimulationResult(simulationResult, inputReady, damageConfidence);
|
|
161
|
-
!((
|
|
253
|
+
!((_o = battleInput.options) === null || _o === void 0 ? void 0 : _o.skipInfoLogs) && console.timeEnd('simulation');
|
|
162
254
|
if (includeOutcomeSamples) {
|
|
163
255
|
const neededOutcomes = [];
|
|
164
256
|
simulationResult.won > 0 && neededOutcomes.push('won');
|
|
@@ -218,6 +310,7 @@ const runSingleBattle = (cloneTemplate, cards, cardsData, spectator, rng) => {
|
|
|
218
310
|
numberOfPlayersAlive: input.gameState.numberOfPlayersAlive,
|
|
219
311
|
applyDamageCap: ((_a = input.options) === null || _a === void 0 ? void 0 : _a.applyDamageCap) === true,
|
|
220
312
|
applyIceBlock: ((_b = input.options) === null || _b === void 0 ? void 0 : _b.applyIceBlock) === true,
|
|
313
|
+
isDuos: !!input.playerTeammateBoard || !!input.opponentTeammateBoard,
|
|
221
314
|
validTribes: input.gameState.validTribes,
|
|
222
315
|
anomalies: input.gameState.anomalies,
|
|
223
316
|
gameState: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulate-bgs-battle.js","sourceRoot":"","sources":["../src/simulate-bgs-battle.ts"],"names":[],"mappings":";;;AACA,iEAA+D;AAE/D,mDAA+C;AAC/C,+CAA2C;AAC3C,+CAAiE;AACjE,yDAAqD;AACrD,wCAA2E;AAI3E,4DAAwD;AACxD,sDAAmD;AACnD,gEAA6D;AAE7D,oEAA+E;AAAtE,kIAAA,6BAA6B,OAAA;AACtC,sCAA4F;AAAnF,sGAAA,eAAe,OAAA;AAAE,iGAAA,UAAU,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,6FAAA,MAAM,OAAA;AAAE,8FAAA,OAAO,OAAA;AAGnE,2CAAiD;AAAxC,qGAAA,YAAY,OAAA;AACrB,yDAAkD;AAAzC,0GAAA,QAAQ,OAAA;AAIjB,wDAA4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AAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAG5D,MAAM,UAAU,GAAG,CAAC,GAAa,EAAE,CAAS,EAAE,EAAE;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAE7D,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;AAC3C,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,UAAkB,EAAU,EAAE;IAChG,IAAI,YAAY,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,EAAE;QAC7C,OAAO,IAAI,CAAC;KACZ;IACD,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,UAAU,EAAE;QACxD,OAAO,IAAI,CAAC;KACZ;IACD,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService } from '@firestone-hs/reference-data';\r\nimport { BgsBattleInfo } from './bgs-battle-info';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { debugState } from './debug-state';\r\nimport { buildTemplateCloner, cloneInput3 } from './input-clone';\r\nimport { buildFinalInput } from './input-sanitation';\r\nimport { createSeededRng, defaultRng, Rng, withRng } from './services/rng';\r\nimport { SimulationResult } from './simulation-result';\r\nimport { SingleSimulationResult } from './single-simulation-result';\r\nimport { FullGameState } from './simulation/internal-game-state';\r\nimport { SharedState } from './simulation/shared-state';\r\nimport { Simulator } from './simulation/simulator';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\n\r\nexport { isValidDeathrattleEnchantment } from './simulation/deathrattle-utils';\r\nexport { createSeededRng, defaultRng, getActiveRng, random, withRng } from './services/rng';\r\nexport type { Rng } from './services/rng';\r\n/** Tavern Activate / Hand of Deios-style Rally triggers (requires a combat FullGameState). */\r\nexport { triggerRally } from './mechanics/rally';\r\nexport { hasRally } from './cards/card.interface';\r\nexport type { RallyCard } from './cards/card.interface';\r\nexport type { OnAttackInput } from './simulation/on-attack';\r\n/** Tavern / Hand of Deios-style Battlecry re-triggers. */\r\nexport { triggerBattlecry } from './simulation/battlecries';\r\n/** Full attack resolution (on-attack, damage, after-attack, deaths) for tavern attacks e.g. Fishbait. */\r\nexport { doFullAttack } from './simulation/attack';\r\nexport { applyOnAttackEffects } from './simulation/on-attack';\r\n\r\n// Cap for the post-hoc outcome sample capture phase: rare outcomes (e.g. a 0.1% tie\r\n// chance) might never show up again when re-simulating, so we stop hunting after this\r\n// many extra battles\r\nconst MAX_SAMPLE_RESIMS = 500;\r\n\r\nlet globalCards = new AllCardsService();\r\n\r\nexport const assignCards = (cards: AllCardsService) => {\r\n\tglobalCards = cards;\r\n};\r\n\r\nexport interface SimulateSingleCombatOptions {\r\n\t/** If set, creates a Mulberry32 RNG from this seed. Ignored when `rng` is provided. */\r\n\treadonly seed?: number;\r\n\t/** Explicit RNG instance. Takes precedence over `seed`. */\r\n\treadonly rng?: Rng;\r\n\t/** When true, records spectator actions (slower). Default false. */\r\n\treadonly includeSpectator?: boolean;\r\n}\r\n\r\n/**\r\n * Run exactly one combat with a deterministic (or default) RNG.\r\n * Intended for the full-game / self-play env — not for Firestone win% Monte Carlo.\r\n */\r\nexport const simulateSingleCombat = (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\toptions: SimulateSingleCombatOptions = {},\r\n): SingleSimulationResult => {\r\n\tif (!cards?.getCards()?.length) {\r\n\t\tconsole.error('[simulate-bgs-battle] reference cards are empty, cannot simulate combat', cards);\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst rng = options.rng ?? (options.seed !== undefined ? createSeededRng(options.seed) : defaultRng);\r\n\tconst includeSpectator = options.includeSpectator ?? false;\r\n\r\n\tapplyDebugStateFromInput(battleInput);\r\n\ttry {\r\n\t\tconst inputReady = buildFinalInput(battleInput, cards, cardsData);\r\n\t\tconst cloneTemplate = buildTemplateCloner(cloneInput3(inputReady));\r\n\t\tconst spectator = new Spectator(includeSpectator);\r\n\t\tif (includeSpectator) {\r\n\t\t\tspectator.startRecording();\r\n\t\t}\r\n\t\treturn withRng(rng, () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, rng));\r\n\t} finally {\r\n\t\tclearDebugStateFromInput(battleInput);\r\n\t}\r\n};\r\n\r\n// This example demonstrates a NodeJS 8.10 async handler[1], however of course you could use\r\n// the more traditional callback-style handler.\r\n// [1]: https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/\r\nexport default async (event): Promise<any> => {\r\n\tif (!event.body?.length) {\r\n\t\tconsole.warn('missing event body', event);\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst battleInput: BgsBattleInfo = JSON.parse(event.body);\r\n\tconst cards = globalCards;\r\n\tawait cards.initializeCardsDb();\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(\r\n\t\tbattleInput.gameState?.validTribes ?? battleInput.options?.validTribes,\r\n\t\tbattleInput.gameState?.anomalies ?? [],\r\n\t);\r\n\tconst battleIterator = simulateBattle(battleInput, cards, cardsData);\r\n\r\n\t// Iterate through all intermediate results to reach the final result\r\n\tlet result = battleIterator.next();\r\n\twhile (!result.done) {\r\n\t\tresult = battleIterator.next();\r\n\t}\r\n\r\n\tconst simulationResult = result.value;\r\n\t// console.debug('simulationResult', simulationResult);\r\n\r\n\tconst response = {\r\n\t\tstatusCode: 200,\r\n\t\tisBase64Encoded: false,\r\n\t\tbody: JSON.stringify(simulationResult),\r\n\t};\r\n\treturn response;\r\n};\r\n\r\nexport const simulateBattle = function* (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n): Generator<SimulationResult, SimulationResult, void> {\r\n\tif (!cards?.getCards()?.length) {\r\n\t\tconsole.error('[simulate-bgs-battle] reference cards are empty, cannot simulate battle', cards);\r\n\t\treturn null;\r\n\t}\r\n\t// !battleInput.options?.skipInfoLogs && console.time('full-sim');\r\n\tconst start = Date.now();\r\n\tconst maxAcceptableDuration = battleInput.options?.maxAcceptableDuration || 8000;\r\n\tconst hideMaxSimulationDurationWarning = battleInput.options?.hideMaxSimulationDurationWarning ?? false;\r\n\tconst numberOfSimulations = battleInput.options?.numberOfSimulations || 8000;\r\n\tconst intermediateSteps = battleInput.options?.intermediateResults ?? 200;\r\n\tconst damageConfidence = battleInput.options?.damageConfidence ?? 0.9;\r\n\tconst includeOutcomeSamples = battleInput.options?.includeOutcomeSamples ?? true;\r\n\tconst simulationResult: SimulationResult = {\r\n\t\twonLethal: 0,\r\n\t\twon: 0,\r\n\t\ttied: 0,\r\n\t\tlost: 0,\r\n\t\tlostLethal: 0,\r\n\t\tdamageWons: [],\r\n\t\tdamageWon: 0,\r\n\t\tdamageWonRange: null,\r\n\t\tdamageLosts: [],\r\n\t\tdamageLost: 0,\r\n\t\tdamageLostRange: null,\r\n\t\twonLethalPercent: undefined,\r\n\t\twonPercent: undefined,\r\n\t\ttiedPercent: undefined,\r\n\t\tlostPercent: undefined,\r\n\t\tlostLethalPercent: undefined,\r\n\t\taverageDamageWon: undefined,\r\n\t\taverageDamageLost: undefined,\r\n\t};\r\n\r\n\tconst spectator = new Spectator(includeOutcomeSamples);\r\n\tconst inputReady = buildFinalInput(battleInput, cards, cardsData);\r\n\r\n\tapplyDebugStateFromInput(battleInput);\r\n\r\n\t// cloneInput3 normalizes the input (sorted secrets, reset pendingAttackBuffs, etc.).\r\n\t// The compiled cloner re-materializes that normalized shape as an object literal, which is\r\n\t// faster than JSON.parse of a template string (~0.02ms vs ~0.12ms per clone on a 7v7\r\n\t// board), which was itself faster than generic recursive cloners (~0.19-0.23ms) and\r\n\t// structuredClone (~0.46ms)\r\n\tconst cloneTemplate = buildTemplateCloner(cloneInput3(inputReady));\r\n\r\n\tconst runOne = () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, defaultRng);\r\n\r\n\ttry {\r\n\t\t!battleInput.options?.skipInfoLogs && console.time('simulation');\r\n\t\tconst outcomes = {};\r\n\t\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\t\tconst battleResult = runOne();\r\n\t\t\tif (!battleResult) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (battleResult.result === 'won') {\r\n\t\t\t\tsimulationResult.won++;\r\n\t\t\t\tsimulationResult.damageWon += battleResult.damageDealt;\r\n\t\t\t\tsimulationResult.damageWons.push(battleResult.damageDealt);\r\n\t\t\t\tif (battleResult.damageDealt >= battleInput.opponentBoard.player.hpLeft) {\r\n\t\t\t\t\tsimulationResult.wonLethal++;\r\n\t\t\t\t}\r\n\t\t\t} else if (battleResult.result === 'lost') {\r\n\t\t\t\tsimulationResult.lost++;\r\n\t\t\t\tsimulationResult.damageLost += battleResult.damageDealt;\r\n\t\t\t\tsimulationResult.damageLosts.push(battleResult.damageDealt);\r\n\t\t\t\toutcomes[battleResult.damageDealt] = (outcomes[battleResult.damageDealt] ?? 0) + 1;\r\n\t\t\t\tif (\r\n\t\t\t\t\tbattleInput.playerBoard.player.hpLeft &&\r\n\t\t\t\t\tbattleResult.damageDealt >= battleInput.playerBoard.player.hpLeft\r\n\t\t\t\t) {\r\n\t\t\t\t\tsimulationResult.lostLethal++;\r\n\t\t\t\t}\r\n\t\t\t} else if (battleResult.result === 'tied') {\r\n\t\t\t\tsimulationResult.tied++;\r\n\t\t\t}\r\n\r\n\t\t\tif (Date.now() - start > maxAcceptableDuration && !hideMaxSimulationDurationWarning) {\r\n\t\t\t\t// Can happen in case of inifinite boards, or a bug. Don't hog the user's computer in that case\r\n\t\t\t\tconsole.warn('Stopping simulation after', i, 'iterations and ', Date.now() - start, 'ms');\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// Yield intermediate result every 200 iterations\r\n\t\t\tif (!!intermediateSteps && i > 0 && i % intermediateSteps === 0) {\r\n\t\t\t\tupdateSimulationResult(simulationResult, inputReady, damageConfidence);\r\n\t\t\t\tyield simulationResult;\r\n\t\t\t}\r\n\t\t}\r\n\t\tupdateSimulationResult(simulationResult, inputReady, damageConfidence);\r\n\t\t!battleInput.options?.skipInfoLogs && console.timeEnd('simulation');\r\n\r\n\t\t// Capture outcome samples post-hoc: re-run a few battles with action recording turned\r\n\t\t// on, until each outcome that actually occurred has a sample. This is much cheaper\r\n\t\t// than recording during the main loop, where almost all recorded actions get discarded.\r\n\t\t// This phase intentionally ignores maxAcceptableDuration: when the main loop was cut\r\n\t\t// short by the time budget, we would otherwise end up with no samples at all.\r\n\t\tif (includeOutcomeSamples) {\r\n\t\t\tconst neededOutcomes: ('won' | 'lost' | 'tied')[] = [];\r\n\t\t\tsimulationResult.won > 0 && neededOutcomes.push('won');\r\n\t\t\tsimulationResult.lost > 0 && neededOutcomes.push('lost');\r\n\t\t\tsimulationResult.tied > 0 && neededOutcomes.push('tied');\r\n\t\t\tconst missingOutcomes = new Set(neededOutcomes);\r\n\t\t\tif (missingOutcomes.size > 0) {\r\n\t\t\t\tspectator.startRecording();\r\n\t\t\t\tfor (let i = 0; i < MAX_SAMPLE_RESIMS && missingOutcomes.size > 0; i++) {\r\n\t\t\t\t\tconst battleResult = runOne();\r\n\t\t\t\t\tif (!battleResult?.result) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tspectator.commitBattleResult(battleResult.result);\r\n\t\t\t\t\tif (spectator.hasSampleFor(battleResult.result)) {\r\n\t\t\t\t\t\tmissingOutcomes.delete(battleResult.result);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tspectator.stopRecording();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tspectator.prune();\r\n\t\tsimulationResult.outcomeSamples = spectator.buildOutcomeSamples(battleInput.gameState);\r\n\t\t// Avoid sending this verbose data\r\n\r\n\t\tsimulationResult.damageWons = [];\r\n\t\tsimulationResult.damageLosts = [];\r\n\t\t// !battleInput.options?.skipInfoLogs && console.timeEnd('full-sim');\r\n\t\treturn simulationResult;\r\n\t} finally {\r\n\t\tclearDebugStateFromInput(battleInput);\r\n\t}\r\n};\r\n\r\ntype CloneTemplate = () => BgsBattleInfo;\r\n\r\nconst runSingleBattle = (\r\n\tcloneTemplate: CloneTemplate,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tspectator: Spectator,\r\n\trng: Rng,\r\n): SingleSimulationResult => {\r\n\tconst input: BgsBattleInfo = cloneTemplate();\r\n\t// The \"initial\" states are only read by a handful of cards (and mutated by some, like\r\n\t// San'layn Scribe), so we only pay for the second clone when they are actually accessed\r\n\tlet playerInitialState = null;\r\n\tlet opponentInitialState = null;\r\n\tconst buildInitialStates = () => {\r\n\t\tconst inputClone: BgsBattleInfo = cloneTemplate();\r\n\t\tplayerInitialState = {\r\n\t\t\tplayer: inputClone.playerBoard.player,\r\n\t\t\tboard: inputClone.playerBoard.board,\r\n\t\t\tteammate: inputClone.playerTeammateBoard,\r\n\t\t};\r\n\t\topponentInitialState = {\r\n\t\t\tplayer: inputClone.opponentBoard.player,\r\n\t\t\tboard: inputClone.opponentBoard.board,\r\n\t\t\tteammate: inputClone.opponentTeammateBoard,\r\n\t\t};\r\n\t};\r\n\tconst gameState: FullGameState = {\r\n\t\tallCards: cards,\r\n\t\tcardsData: cardsData,\r\n\t\tspectator: spectator,\r\n\t\tsharedState: new SharedState(rng),\r\n\t\tcurrentTurn: input.gameState.currentTurn,\r\n\t\tnumberOfPlayersAlive: input.gameState.numberOfPlayersAlive,\r\n\t\tapplyDamageCap: input.options?.applyDamageCap === true,\r\n\t\tapplyIceBlock: input.options?.applyIceBlock === true,\r\n\t\tvalidTribes: input.gameState.validTribes,\r\n\t\tanomalies: input.gameState.anomalies,\r\n\t\tgameState: {\r\n\t\t\tplayer: {\r\n\t\t\t\tplayer: input.playerBoard.player,\r\n\t\t\t\tboard: input.playerBoard.board,\r\n\t\t\t\tteammate: input.playerTeammateBoard,\r\n\t\t\t},\r\n\t\t\topponent: {\r\n\t\t\t\tplayer: input.opponentBoard.player,\r\n\t\t\t\tboard: input.opponentBoard.board,\r\n\t\t\t\tteammate: input.opponentTeammateBoard,\r\n\t\t\t},\r\n\t\t\tget playerInitial() {\r\n\t\t\t\tif (!playerInitialState) {\r\n\t\t\t\t\tbuildInitialStates();\r\n\t\t\t\t}\r\n\t\t\t\treturn playerInitialState;\r\n\t\t\t},\r\n\t\t\tget opponentInitial() {\r\n\t\t\t\tif (!opponentInitialState) {\r\n\t\t\t\t\tbuildInitialStates();\r\n\t\t\t\t}\r\n\t\t\t\treturn opponentInitialState;\r\n\t\t\t},\r\n\t\t},\r\n\t};\r\n\tconst simulator = new Simulator(gameState);\r\n\treturn simulator.simulateSingleBattle(gameState.gameState.player, gameState.gameState.opponent);\r\n};\r\n\r\nconst applyDebugStateFromInput = (battleInput: BgsBattleInfo) => {\r\n\tif (!battleInput.debugState) {\r\n\t\treturn;\r\n\t}\r\n\tdebugState.active = true;\r\n\tdebugState.forcedCurrentAttacker = battleInput.debugState.forcedCurrentAttacker;\r\n\tdebugState.forcedFaceOffBase = battleInput.debugState.forcedFaceOffBase.map((f) => ({\r\n\t\tattacker: { ...f.attacker },\r\n\t\tdefender: { ...f.defender },\r\n\t}));\r\n\tconst rawPicks = battleInput.debugState.forcedRandomPicks ?? [];\r\n\tdebugState.forcedRandomPicksBase = rawPicks.map((p) => ({\r\n\t\tsource: { ...p.source },\r\n\t\ttarget: { ...p.target },\r\n\t\t...(p.chosenCardId && { chosenCardId: p.chosenCardId }),\r\n\t}));\r\n};\r\n\r\nconst clearDebugStateFromInput = (battleInput: BgsBattleInfo) => {\r\n\tif (battleInput.debugState) {\r\n\t\tdebugState.active = false;\r\n\t}\r\n};\r\n\r\nconst updateSimulationResult = (simulationResult: SimulationResult, input: BgsBattleInfo, damageConfidence: number) => {\r\n\tconst totalMatches = simulationResult.won + simulationResult.tied + simulationResult.lost;\r\n\tsimulationResult.wonPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.won)) / totalMatches) / 10,\r\n\t\tsimulationResult.won,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.wonLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.wonLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lost)) / totalMatches) / 10,\r\n\t\tsimulationResult.lost,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.lostLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.tiedPercent = checkRounding(\r\n\t\tMath.max(0, 100 - simulationResult.lostPercent - simulationResult.wonPercent),\r\n\t\tsimulationResult.tied,\r\n\t\ttotalMatches,\r\n\t);\r\n\r\n\t// simulationResult.wonLethalPercent = Math.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10;\r\n\t// simulationResult.lostLethalPercent = Math.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10;\r\n\tconst totalDamageWon = simulationResult.damageWons.reduce((a, b) => a + b, 0);\r\n\tconst totalDamageLost = simulationResult.damageLosts.reduce((a, b) => a + b, 0);\r\n\tconst damageWonRange = calculateDamageRange(simulationResult.damageWons, damageConfidence);\r\n\tconst damageLostRange = calculateDamageRange(simulationResult.damageLosts, damageConfidence);\r\n\tsimulationResult.averageDamageWon = simulationResult.won ? totalDamageWon / simulationResult.won : 0;\r\n\tsimulationResult.averageDamageLost = simulationResult.lost ? totalDamageLost / simulationResult.lost : 0;\r\n\tsimulationResult.damageWonRange = simulationResult.won ? damageWonRange : null;\r\n\tsimulationResult.damageLostRange = simulationResult.lost ? damageLostRange : null;\r\n\r\n\tif (\r\n\t\tsimulationResult.averageDamageWon > 0 &&\r\n\t\tsimulationResult.averageDamageWon < input.playerBoard.player.tavernTier\r\n\t) {\r\n\t\tconsole.warn('average damage won issue');\r\n\t}\r\n\tif (\r\n\t\tsimulationResult.averageDamageLost > 0 &&\r\n\t\tsimulationResult.averageDamageLost < input.opponentBoard.player.tavernTier\r\n\t) {\r\n\t\tconsole.warn('average damage lost issue');\r\n\t}\r\n};\r\n\r\nconst calculateDamageRange = (damageArray: number[], damageConfidence: number): { min: number; max: number } => {\r\n\tif (damageArray.length === 0) {\r\n\t\treturn { min: 0, max: 0 };\r\n\t}\r\n\r\n\t// Sort the array\r\n\tconst sortedDamage = [...damageArray].sort((a, b) => a - b);\r\n\r\n\t// Calculate the 10th and 90th percentiles\r\n\tconst percentile = (arr: number[], p: number) => {\r\n\t\tconst index = Math.floor(p * arr.length);\r\n\t\treturn arr[index];\r\n\t};\r\n\r\n\tconst minDamage = percentile(sortedDamage, 1 - damageConfidence);\r\n\tconst maxDamage = percentile(sortedDamage, damageConfidence);\r\n\r\n\treturn { min: minDamage, max: maxDamage };\r\n};\r\n\r\nconst checkRounding = (roundedValue: number, initialValue: number, totalValue: number): number => {\r\n\tif (roundedValue === 0 && initialValue !== 0) {\r\n\t\treturn 0.01;\r\n\t}\r\n\tif (roundedValue === 100 && initialValue !== totalValue) {\r\n\t\treturn 99.9;\r\n\t}\r\n\treturn roundedValue;\r\n};\r\n\r\n// const cleanEnchantmentsForEntity = (\r\n// \tenchantments: { cardId: string; originEntityId?: number; timing: number }[],\r\n// \tentityIds: readonly number[],\r\n// ): { cardId: string; originEntityId?: number; timing: number }[] => {\r\n// \treturn enchantments.filter(\r\n// \t\t(enchant) =>\r\n// \t\t\tentityIds.indexOf(enchant.originEntityId) !== -1 ||\r\n// \t\t\tvalidEnchantments.indexOf(enchant.cardId as CardIds) !== -1,\r\n// \t);\r\n// };\r\n"]}
|
|
1
|
+
{"version":3,"file":"simulate-bgs-battle.js","sourceRoot":"","sources":["../src/simulate-bgs-battle.ts"],"names":[],"mappings":";;;AACA,iEAA+D;AAE/D,mDAA+C;AAC/C,+CAA2C;AAC3C,+CAAiE;AACjE,yDAAqD;AACrD,wCAA2E;AAI3E,4DAAwD;AACxD,sDAAmD;AACnD,gEAA4E;AAC5E,gEAIqC;AACrC,4CAAyC;AAEzC,oEAA+E;AAAtE,kIAAA,6BAA6B,OAAA;AACtC,sCAA4F;AAAnF,sGAAA,eAAe,OAAA;AAAE,iGAAA,UAAU,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,6FAAA,MAAM,OAAA;AAAE,8FAAA,OAAO,OAAA;AAGnE,2CAAiD;AAAxC,qGAAA,YAAY,OAAA;AACrB,yDAAkD;AAAzC,0GAAA,QAAQ,OAAA;AAIjB,wDAA4D;AAAnD,+GAAA,gBAAgB,OAAA;AAEzB,8CAAmD;AAA1C,sGAAA,YAAY,OAAA;AACrB,oDAA8D;AAArD,iHAAA,oBAAoB,OAAA;AAK7B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,IAAI,WAAW,GAAG,IAAI,gCAAe,EAAE,CAAC;AAExC,IAAI,gBAAgB,GAA4B,IAAI,CAAC;AAGrD,MAAM,eAAe,GAAG,IAAI,OAAO,EAAU,CAAC;AAE9C,MAAM,cAAc,GAAG,CAAC,KAAyC,EAAW,EAAE;;IAC7E,IAAI,CAAC,KAAK,EAAE;QACX,OAAO,KAAK,CAAC;KACb;IACD,IAAI,eAAe,CAAC,GAAG,CAAC,KAAe,CAAC,EAAE;QACzC,OAAO,IAAI,CA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port { AllCardsService } from '@firestone-hs/reference-data';\r\nimport { BgsBattleInfo } from './bgs-battle-info';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { debugState } from './debug-state';\r\nimport { buildTemplateCloner, cloneInput3 } from './input-clone';\r\nimport { buildFinalInput } from './input-sanitation';\r\nimport { createSeededRng, defaultRng, Rng, withRng } from './services/rng';\r\nimport { SimulationResult } from './simulation-result';\r\nimport { SingleSimulationResult } from './single-simulation-result';\r\nimport { FullGameState } from './simulation/internal-game-state';\r\nimport { SharedState } from './simulation/shared-state';\r\nimport { Simulator } from './simulation/simulator';\r\nimport { Spectator, noopSpectator } from './simulation/spectator/spectator';\r\nimport {\r\n\tcombatProfileAdd,\r\n\tcombatProfileEnabled,\r\n\tcombatProfileTickFight,\r\n} from './simulation/combat-profile';\r\nimport { sleep } from './services/utils';\r\n\r\nexport { isValidDeathrattleEnchantment } from './simulation/deathrattle-utils';\r\nexport { createSeededRng, defaultRng, getActiveRng, random, withRng } from './services/rng';\r\nexport type { Rng } from './services/rng';\r\n/** Tavern Activate / Hand of Deios-style Rally triggers (requires a combat FullGameState). */\r\nexport { triggerRally } from './mechanics/rally';\r\nexport { hasRally } from './cards/card.interface';\r\nexport type { RallyCard } from './cards/card.interface';\r\nexport type { OnAttackInput } from './simulation/on-attack';\r\n/** Tavern / Hand of Deios-style Battlecry re-triggers. */\r\nexport { triggerBattlecry } from './simulation/battlecries';\r\n/** Full attack resolution (on-attack, damage, after-attack, deaths) for tavern attacks e.g. Fishbait. */\r\nexport { doFullAttack } from './simulation/attack';\r\nexport { applyOnAttackEffects } from './simulation/on-attack';\r\n\r\n// Cap for the post-hoc outcome sample capture phase: rare outcomes (e.g. a 0.1% tie\r\n// chance) might never show up again when re-simulating, so we stop hunting after this\r\n// many extra battles\r\nconst MAX_SAMPLE_RESIMS = 500;\r\nconst CARDS_LOAD_ATTEMPTS = 3;\r\n\r\nlet globalCards = new AllCardsService();\r\n/** In-flight / completed cards init for this warm container (avoids re-fetch per invoke). */\r\nlet cardsInitPromise: Promise<boolean> | null = null;\r\n\r\n/** `getCards()` materializes the full DB (~14ms). Validate once per instance. */\r\nconst verifiedCardDbs = new WeakSet<object>();\r\n\r\nconst hasLoadedCards = (cards: AllCardsService | null | undefined): boolean => {\r\n\tif (!cards) {\r\n\t\treturn false;\r\n\t}\r\n\tif (verifiedCardDbs.has(cards as object)) {\r\n\t\treturn true;\r\n\t}\r\n\t// Prefer a single-card lookup. getCards() copies the whole DB (~14ms).\r\n\tconst probe = cards.getCard?.('CS2_122');\r\n\tif (probe?.id) {\r\n\t\tverifiedCardDbs.add(cards as object);\r\n\t\treturn true;\r\n\t}\r\n\tconst loaded = !!cards.getCards?.()?.length;\r\n\tif (loaded) {\r\n\t\tverifiedCardDbs.add(cards as object);\r\n\t}\r\n\treturn loaded;\r\n};\r\n\r\nconst loadCardsWithRetry = async (cards: AllCardsService): Promise<boolean> => {\r\n\tfor (let attempt = 1; attempt <= CARDS_LOAD_ATTEMPTS; attempt++) {\r\n\t\ttry {\r\n\t\t\tawait cards.initializeCardsDb();\r\n\t\t\tif (hasLoadedCards(cards)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tconsole.warn('[simulate-bgs-battle] cards still empty after initializeCardsDb', attempt);\r\n\t\t} catch (e) {\r\n\t\t\tconsole.warn('[simulate-bgs-battle] cards load attempt failed', attempt, e);\r\n\t\t}\r\n\t\tif (attempt < CARDS_LOAD_ATTEMPTS) {\r\n\t\t\tawait sleep(250 * attempt);\r\n\t\t}\r\n\t}\r\n\treturn false;\r\n};\r\n\r\n/**\r\n * Load reference cards once per warm container. Retries transient CDN/fetch failures.\r\n * Returns false when cards could not be loaded after retries.\r\n */\r\nexport const ensureCardsLoaded = async (cards: AllCardsService = globalCards): Promise<boolean> => {\r\n\tif (hasLoadedCards(cards)) {\r\n\t\treturn true;\r\n\t}\r\n\tif (!cardsInitPromise) {\r\n\t\tcardsInitPromise = loadCardsWithRetry(cards).then((ok) => {\r\n\t\t\tif (!ok) {\r\n\t\t\t\t// Allow the next invoke to retry after a hard failure.\r\n\t\t\t\tcardsInitPromise = null;\r\n\t\t\t}\r\n\t\t\treturn ok;\r\n\t\t});\r\n\t}\r\n\treturn cardsInitPromise;\r\n};\r\n\r\nexport const assignCards = (cards: AllCardsService) => {\r\n\tglobalCards = cards;\r\n\tcardsInitPromise = hasLoadedCards(cards) ? Promise.resolve(true) : null;\r\n};\r\n\r\nexport interface SimulateSingleCombatOptions {\r\n\t/** If set, creates a Mulberry32 RNG from this seed. Ignored when `rng` is provided. */\r\n\treadonly seed?: number;\r\n\t/** Explicit RNG instance. Takes precedence over `seed`. */\r\n\treadonly rng?: Rng;\r\n\t/** When true, records spectator actions (slower). Default false. */\r\n\treadonly includeSpectator?: boolean;\r\n}\r\n\r\n/**\r\n * Run exactly one combat with a deterministic (or default) RNG.\r\n * Intended for the full-game / self-play env — not for Firestone win% Monte Carlo.\r\n */\r\nexport const simulateSingleCombat = (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\toptions: SimulateSingleCombatOptions = {},\r\n): SingleSimulationResult => {\r\n\tconst profile = combatProfileEnabled();\r\n\tconst getCardsT0 = profile ? performance.now() : 0;\r\n\tif (!hasLoadedCards(cards)) {\r\n\t\tconsole.error('[simulate-bgs-battle] reference cards are empty, cannot simulate combat', cards);\r\n\t\treturn null;\r\n\t}\r\n\tif (profile) {\r\n\t\tcombatProfileAdd('getCardsMs', performance.now() - getCardsT0);\r\n\t}\r\n\r\n\tconst rng = options.rng ?? (options.seed !== undefined ? createSeededRng(options.seed) : defaultRng);\r\n\tconst includeSpectator = options.includeSpectator ?? false;\r\n\r\n\tapplyDebugStateFromInput(battleInput);\r\n\ttry {\r\n\t\tconst buildT0 = profile ? performance.now() : 0;\r\n\t\tconst inputReady = buildFinalInput(battleInput, cards, cardsData);\r\n\t\tif (profile) {\r\n\t\t\tcombatProfileAdd('buildFinalInputMs', performance.now() - buildT0);\r\n\t\t}\r\n\t\t// One fight: cloneInput3 per use (battle + optional initial-state snapshot).\r\n\t\t// Firestone Monte Carlo keeps buildTemplateCloner for 8000 sims.\r\n\t\tconst cloneTemplate = () => {\r\n\t\t\tconst cloneT0 = profile ? performance.now() : 0;\r\n\t\t\tconst cloned = cloneInput3(inputReady);\r\n\t\t\tif (profile) {\r\n\t\t\t\tcombatProfileAdd('cloneMs', performance.now() - cloneT0);\r\n\t\t\t}\r\n\t\t\treturn cloned;\r\n\t\t};\r\n\t\tconst spectator = includeSpectator ? new Spectator(true) : noopSpectator;\r\n\t\tif (includeSpectator) {\r\n\t\t\tspectator.startRecording();\r\n\t\t}\r\n\t\tconst runT0 = profile ? performance.now() : 0;\r\n\t\tconst result = withRng(rng, () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, rng));\r\n\t\tif (profile) {\r\n\t\t\tcombatProfileAdd('runBattleMs', performance.now() - runT0);\r\n\t\t\tcombatProfileTickFight();\r\n\t\t}\r\n\t\treturn result;\r\n\t} finally {\r\n\t\tclearDebugStateFromInput(battleInput);\r\n\t}\r\n};\r\n\r\n// This example demonstrates a NodeJS 8.10 async handler[1], however of course you could use\r\n// the more traditional callback-style handler.\r\n// [1]: https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/\r\nexport default async (event): Promise<any> => {\r\n\tif (!event.body?.length) {\r\n\t\tconsole.warn('missing event body', event);\r\n\t\treturn {\r\n\t\t\tstatusCode: 400,\r\n\t\t\tisBase64Encoded: false,\r\n\t\t\tbody: null,\r\n\t\t};\r\n\t}\r\n\r\n\tconst battleInput: BgsBattleInfo = JSON.parse(event.body);\r\n\tconst cards = globalCards;\r\n\tconst cardsLoaded = await ensureCardsLoaded(cards);\r\n\tif (!cardsLoaded) {\r\n\t\tconsole.error('[simulate-bgs-battle] failed to load reference cards after retries');\r\n\t\treturn {\r\n\t\t\tstatusCode: 503,\r\n\t\t\tisBase64Encoded: false,\r\n\t\t\tbody: JSON.stringify({ error: 'cards_unavailable' }),\r\n\t\t};\r\n\t}\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(\r\n\t\tbattleInput.gameState?.validTribes ?? battleInput.options?.validTribes,\r\n\t\tbattleInput.gameState?.anomalies ?? [],\r\n\t);\r\n\tconst battleIterator = simulateBattle(battleInput, cards, cardsData);\r\n\r\n\t// Iterate through all intermediate results to reach the final result\r\n\tlet result = battleIterator.next();\r\n\twhile (!result.done) {\r\n\t\tresult = battleIterator.next();\r\n\t}\r\n\r\n\tconst simulationResult = result.value;\r\n\t// console.debug('simulationResult', simulationResult);\r\n\r\n\tconst response = {\r\n\t\tstatusCode: 200,\r\n\t\tisBase64Encoded: false,\r\n\t\tbody: JSON.stringify(simulationResult),\r\n\t};\r\n\treturn response;\r\n};\r\n\r\nexport const simulateBattle = function* (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n): Generator<SimulationResult, SimulationResult, void> {\r\n\tif (!hasLoadedCards(cards)) {\r\n\t\tconsole.error('[simulate-bgs-battle] reference cards are empty, cannot simulate battle', cards);\r\n\t\treturn null;\r\n\t}\r\n\t// !battleInput.options?.skipInfoLogs && console.time('full-sim');\r\n\tconst start = Date.now();\r\n\tconst maxAcceptableDuration = battleInput.options?.maxAcceptableDuration || 8000;\r\n\tconst hideMaxSimulationDurationWarning = battleInput.options?.hideMaxSimulationDurationWarning ?? false;\r\n\tconst numberOfSimulations = battleInput.options?.numberOfSimulations || 8000;\r\n\tconst intermediateSteps = battleInput.options?.intermediateResults ?? 200;\r\n\tconst damageConfidence = battleInput.options?.damageConfidence ?? 0.9;\r\n\tconst includeOutcomeSamples = battleInput.options?.includeOutcomeSamples ?? true;\r\n\tconst simulationResult: SimulationResult = {\r\n\t\twonLethal: 0,\r\n\t\twon: 0,\r\n\t\ttied: 0,\r\n\t\tlost: 0,\r\n\t\tlostLethal: 0,\r\n\t\tdamageWons: [],\r\n\t\tdamageWon: 0,\r\n\t\tdamageWonRange: null,\r\n\t\tdamageLosts: [],\r\n\t\tdamageLost: 0,\r\n\t\tdamageLostRange: null,\r\n\t\twonLethalPercent: undefined,\r\n\t\twonPercent: undefined,\r\n\t\ttiedPercent: undefined,\r\n\t\tlostPercent: undefined,\r\n\t\tlostLethalPercent: undefined,\r\n\t\taverageDamageWon: undefined,\r\n\t\taverageDamageLost: undefined,\r\n\t};\r\n\r\n\tconst spectator = new Spectator(includeOutcomeSamples);\r\n\tconst inputReady = buildFinalInput(battleInput, cards, cardsData);\r\n\r\n\tapplyDebugStateFromInput(battleInput);\r\n\r\n\t// cloneInput3 normalizes the input (sorted secrets, reset pendingAttackBuffs, etc.).\r\n\t// The compiled cloner re-materializes that normalized shape as an object literal, which is\r\n\t// faster than JSON.parse of a template string (~0.02ms vs ~0.12ms per clone on a 7v7\r\n\t// board), which was itself faster than generic recursive cloners (~0.19-0.23ms) and\r\n\t// structuredClone (~0.46ms)\r\n\tconst cloneTemplate = buildTemplateCloner(cloneInput3(inputReady));\r\n\r\n\tconst runOne = () => runSingleBattle(cloneTemplate, cards, cardsData, spectator, defaultRng);\r\n\r\n\ttry {\r\n\t\t!battleInput.options?.skipInfoLogs && console.time('simulation');\r\n\t\tconst outcomes = {};\r\n\t\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\t\tconst battleResult = runOne();\r\n\t\t\tif (!battleResult) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (battleResult.result === 'won') {\r\n\t\t\t\tsimulationResult.won++;\r\n\t\t\t\tsimulationResult.damageWon += battleResult.damageDealt;\r\n\t\t\t\tsimulationResult.damageWons.push(battleResult.damageDealt);\r\n\t\t\t\tif (battleResult.damageDealt >= battleInput.opponentBoard.player.hpLeft) {\r\n\t\t\t\t\tsimulationResult.wonLethal++;\r\n\t\t\t\t}\r\n\t\t\t} else if (battleResult.result === 'lost') {\r\n\t\t\t\tsimulationResult.lost++;\r\n\t\t\t\tsimulationResult.damageLost += battleResult.damageDealt;\r\n\t\t\t\tsimulationResult.damageLosts.push(battleResult.damageDealt);\r\n\t\t\t\toutcomes[battleResult.damageDealt] = (outcomes[battleResult.damageDealt] ?? 0) + 1;\r\n\t\t\t\tif (\r\n\t\t\t\t\tbattleInput.playerBoard.player.hpLeft &&\r\n\t\t\t\t\tbattleResult.damageDealt >= battleInput.playerBoard.player.hpLeft\r\n\t\t\t\t) {\r\n\t\t\t\t\tsimulationResult.lostLethal++;\r\n\t\t\t\t}\r\n\t\t\t} else if (battleResult.result === 'tied') {\r\n\t\t\t\tsimulationResult.tied++;\r\n\t\t\t}\r\n\r\n\t\t\tif (Date.now() - start > maxAcceptableDuration && !hideMaxSimulationDurationWarning) {\r\n\t\t\t\t// Can happen in case of inifinite boards, or a bug. Don't hog the user's computer in that case\r\n\t\t\t\tconsole.warn('Stopping simulation after', i, 'iterations and ', Date.now() - start, 'ms');\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// Yield intermediate result every 200 iterations\r\n\t\t\tif (!!intermediateSteps && i > 0 && i % intermediateSteps === 0) {\r\n\t\t\t\tupdateSimulationResult(simulationResult, inputReady, damageConfidence);\r\n\t\t\t\tyield simulationResult;\r\n\t\t\t}\r\n\t\t}\r\n\t\tupdateSimulationResult(simulationResult, inputReady, damageConfidence);\r\n\t\t!battleInput.options?.skipInfoLogs && console.timeEnd('simulation');\r\n\r\n\t\t// Capture outcome samples post-hoc: re-run a few battles with action recording turned\r\n\t\t// on, until each outcome that actually occurred has a sample. This is much cheaper\r\n\t\t// than recording during the main loop, where almost all recorded actions get discarded.\r\n\t\t// This phase intentionally ignores maxAcceptableDuration: when the main loop was cut\r\n\t\t// short by the time budget, we would otherwise end up with no samples at all.\r\n\t\tif (includeOutcomeSamples) {\r\n\t\t\tconst neededOutcomes: ('won' | 'lost' | 'tied')[] = [];\r\n\t\t\tsimulationResult.won > 0 && neededOutcomes.push('won');\r\n\t\t\tsimulationResult.lost > 0 && neededOutcomes.push('lost');\r\n\t\t\tsimulationResult.tied > 0 && neededOutcomes.push('tied');\r\n\t\t\tconst missingOutcomes = new Set(neededOutcomes);\r\n\t\t\tif (missingOutcomes.size > 0) {\r\n\t\t\t\tspectator.startRecording();\r\n\t\t\t\tfor (let i = 0; i < MAX_SAMPLE_RESIMS && missingOutcomes.size > 0; i++) {\r\n\t\t\t\t\tconst battleResult = runOne();\r\n\t\t\t\t\tif (!battleResult?.result) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tspectator.commitBattleResult(battleResult.result);\r\n\t\t\t\t\tif (spectator.hasSampleFor(battleResult.result)) {\r\n\t\t\t\t\t\tmissingOutcomes.delete(battleResult.result);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tspectator.stopRecording();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tspectator.prune();\r\n\t\tsimulationResult.outcomeSamples = spectator.buildOutcomeSamples(battleInput.gameState);\r\n\t\t// Avoid sending this verbose data\r\n\r\n\t\tsimulationResult.damageWons = [];\r\n\t\tsimulationResult.damageLosts = [];\r\n\t\t// !battleInput.options?.skipInfoLogs && console.timeEnd('full-sim');\r\n\t\treturn simulationResult;\r\n\t} finally {\r\n\t\tclearDebugStateFromInput(battleInput);\r\n\t}\r\n};\r\n\r\ntype CloneTemplate = () => BgsBattleInfo;\r\n\r\nconst runSingleBattle = (\r\n\tcloneTemplate: CloneTemplate,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tspectator: Spectator,\r\n\trng: Rng,\r\n): SingleSimulationResult => {\r\n\tconst input: BgsBattleInfo = cloneTemplate();\r\n\t// The \"initial\" states are only read by a handful of cards (and mutated by some, like\r\n\t// San'layn Scribe), so we only pay for the second clone when they are actually accessed\r\n\tlet playerInitialState = null;\r\n\tlet opponentInitialState = null;\r\n\tconst buildInitialStates = () => {\r\n\t\tconst inputClone: BgsBattleInfo = cloneTemplate();\r\n\t\tplayerInitialState = {\r\n\t\t\tplayer: inputClone.playerBoard.player,\r\n\t\t\tboard: inputClone.playerBoard.board,\r\n\t\t\tteammate: inputClone.playerTeammateBoard,\r\n\t\t};\r\n\t\topponentInitialState = {\r\n\t\t\tplayer: inputClone.opponentBoard.player,\r\n\t\t\tboard: inputClone.opponentBoard.board,\r\n\t\t\tteammate: inputClone.opponentTeammateBoard,\r\n\t\t};\r\n\t};\r\n\tconst gameState: FullGameState = {\r\n\t\tallCards: cards,\r\n\t\tcardsData: cardsData,\r\n\t\tspectator: spectator,\r\n\t\tsharedState: new SharedState(rng),\r\n\t\tcurrentTurn: input.gameState.currentTurn,\r\n\t\tnumberOfPlayersAlive: input.gameState.numberOfPlayersAlive,\r\n\t\tapplyDamageCap: input.options?.applyDamageCap === true,\r\n\t\tapplyIceBlock: input.options?.applyIceBlock === true,\r\n\t\tisDuos: !!input.playerTeammateBoard || !!input.opponentTeammateBoard,\r\n\t\tvalidTribes: input.gameState.validTribes,\r\n\t\tanomalies: input.gameState.anomalies,\r\n\t\tgameState: {\r\n\t\t\tplayer: {\r\n\t\t\t\tplayer: input.playerBoard.player,\r\n\t\t\t\tboard: input.playerBoard.board,\r\n\t\t\t\tteammate: input.playerTeammateBoard,\r\n\t\t\t},\r\n\t\t\topponent: {\r\n\t\t\t\tplayer: input.opponentBoard.player,\r\n\t\t\t\tboard: input.opponentBoard.board,\r\n\t\t\t\tteammate: input.opponentTeammateBoard,\r\n\t\t\t},\r\n\t\t\tget playerInitial() {\r\n\t\t\t\tif (!playerInitialState) {\r\n\t\t\t\t\tbuildInitialStates();\r\n\t\t\t\t}\r\n\t\t\t\treturn playerInitialState;\r\n\t\t\t},\r\n\t\t\tget opponentInitial() {\r\n\t\t\t\tif (!opponentInitialState) {\r\n\t\t\t\t\tbuildInitialStates();\r\n\t\t\t\t}\r\n\t\t\t\treturn opponentInitialState;\r\n\t\t\t},\r\n\t\t},\r\n\t};\r\n\tconst simulator = new Simulator(gameState);\r\n\treturn simulator.simulateSingleBattle(gameState.gameState.player, gameState.gameState.opponent);\r\n};\r\n\r\nconst applyDebugStateFromInput = (battleInput: BgsBattleInfo) => {\r\n\tif (!battleInput.debugState) {\r\n\t\treturn;\r\n\t}\r\n\tdebugState.active = true;\r\n\tdebugState.forcedCurrentAttacker = battleInput.debugState.forcedCurrentAttacker;\r\n\tdebugState.forcedFaceOffBase = battleInput.debugState.forcedFaceOffBase.map((f) => ({\r\n\t\tattacker: { ...f.attacker },\r\n\t\tdefender: { ...f.defender },\r\n\t}));\r\n\tconst rawPicks = battleInput.debugState.forcedRandomPicks ?? [];\r\n\tdebugState.forcedRandomPicksBase = rawPicks.map((p) => ({\r\n\t\tsource: { ...p.source },\r\n\t\ttarget: { ...p.target },\r\n\t\t...(p.chosenCardId && { chosenCardId: p.chosenCardId }),\r\n\t}));\r\n};\r\n\r\nconst clearDebugStateFromInput = (battleInput: BgsBattleInfo) => {\r\n\tif (battleInput.debugState) {\r\n\t\tdebugState.active = false;\r\n\t}\r\n};\r\n\r\nconst updateSimulationResult = (simulationResult: SimulationResult, input: BgsBattleInfo, damageConfidence: number) => {\r\n\tconst totalMatches = simulationResult.won + simulationResult.tied + simulationResult.lost;\r\n\tsimulationResult.wonPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.won)) / totalMatches) / 10,\r\n\t\tsimulationResult.won,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.wonLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.wonLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lost)) / totalMatches) / 10,\r\n\t\tsimulationResult.lost,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.lostLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.tiedPercent = checkRounding(\r\n\t\tMath.max(0, 100 - simulationResult.lostPercent - simulationResult.wonPercent),\r\n\t\tsimulationResult.tied,\r\n\t\ttotalMatches,\r\n\t);\r\n\r\n\t// simulationResult.wonLethalPercent = Math.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10;\r\n\t// simulationResult.lostLethalPercent = Math.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10;\r\n\tconst totalDamageWon = simulationResult.damageWons.reduce((a, b) => a + b, 0);\r\n\tconst totalDamageLost = simulationResult.damageLosts.reduce((a, b) => a + b, 0);\r\n\tconst damageWonRange = calculateDamageRange(simulationResult.damageWons, damageConfidence);\r\n\tconst damageLostRange = calculateDamageRange(simulationResult.damageLosts, damageConfidence);\r\n\tsimulationResult.averageDamageWon = simulationResult.won ? totalDamageWon / simulationResult.won : 0;\r\n\tsimulationResult.averageDamageLost = simulationResult.lost ? totalDamageLost / simulationResult.lost : 0;\r\n\tsimulationResult.damageWonRange = simulationResult.won ? damageWonRange : null;\r\n\tsimulationResult.damageLostRange = simulationResult.lost ? damageLostRange : null;\r\n\r\n\tif (\r\n\t\tsimulationResult.averageDamageWon > 0 &&\r\n\t\tsimulationResult.averageDamageWon < input.playerBoard.player.tavernTier\r\n\t) {\r\n\t\tconsole.warn('average damage won issue');\r\n\t}\r\n\tif (\r\n\t\tsimulationResult.averageDamageLost > 0 &&\r\n\t\tsimulationResult.averageDamageLost < input.opponentBoard.player.tavernTier\r\n\t) {\r\n\t\tconsole.warn('average damage lost issue');\r\n\t}\r\n};\r\n\r\nconst calculateDamageRange = (damageArray: number[], damageConfidence: number): { min: number; max: number } => {\r\n\tif (damageArray.length === 0) {\r\n\t\treturn { min: 0, max: 0 };\r\n\t}\r\n\r\n\t// Sort the array\r\n\tconst sortedDamage = [...damageArray].sort((a, b) => a - b);\r\n\r\n\t// Calculate the 10th and 90th percentiles\r\n\tconst percentile = (arr: number[], p: number) => {\r\n\t\tconst index = Math.floor(p * arr.length);\r\n\t\treturn arr[index];\r\n\t};\r\n\r\n\tconst minDamage = percentile(sortedDamage, 1 - damageConfidence);\r\n\tconst maxDamage = percentile(sortedDamage, damageConfidence);\r\n\r\n\treturn { min: minDamage, max: maxDamage };\r\n};\r\n\r\nconst checkRounding = (roundedValue: number, initialValue: number, totalValue: number): number => {\r\n\tif (roundedValue === 0 && initialValue !== 0) {\r\n\t\treturn 0.01;\r\n\t}\r\n\tif (roundedValue === 100 && initialValue !== totalValue) {\r\n\t\treturn 99.9;\r\n\t}\r\n\treturn roundedValue;\r\n};\r\n\r\n// const cleanEnchantmentsForEntity = (\r\n// \tenchantments: { cardId: string; originEntityId?: number; timing: number }[],\r\n// \tentityIds: readonly number[],\r\n// ): { cardId: string; originEntityId?: number; timing: number }[] => {\r\n// \treturn enchantments.filter(\r\n// \t\t(enchant) =>\r\n// \t\t\tentityIds.indexOf(enchant.originEntityId) !== -1 ||\r\n// \t\t\tvalidEnchantments.indexOf(enchant.cardId as CardIds) !== -1,\r\n// \t);\r\n// };\r\n"]}
|
|
@@ -2,7 +2,7 @@ import { BgsPlayerEntity } from '../bgs-player-entity';
|
|
|
2
2
|
import { BoardEntity } from '../board-entity';
|
|
3
3
|
import { FullGameState } from './internal-game-state';
|
|
4
4
|
export declare const applyAfterAttackEffects: (attackingEntity: BoardEntity, attackingBoard: BoardEntity[], attackingBoardHero: BgsPlayerEntity, defendingEntity: BoardEntity, defendingBoard: BoardEntity[], defendingBoardHero: BgsPlayerEntity, damageDoneByAttacker: number, damageDoneByDefender: number, gameState: FullGameState) => void;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const applyAfterAttackTrinkets: (attackingEntity: BoardEntity, attackingBoard: BoardEntity[], attackingBoardHero: BgsPlayerEntity, defendingEntity: BoardEntity, defendingBoard: BoardEntity[], defendingBoardHero: BgsPlayerEntity, damageDoneByAttacker: number, damageDoneByDefender: number, gameState: FullGameState) => void;
|
|
6
6
|
export interface OnAfterAttackInput {
|
|
7
7
|
attacker: BoardEntity;
|
|
8
8
|
attackingHero: BgsPlayerEntity;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.applyAfterAttackTrinkets = exports.applyAfterAttackEffects = void 0;
|
|
4
4
|
const card_interface_1 = require("../cards/card.interface");
|
|
5
5
|
const _card_mappings_1 = require("../cards/impl/_card-mappings");
|
|
6
6
|
const stealth_1 = require("../keywords/stealth");
|
|
@@ -10,6 +10,24 @@ const stats_1 = require("./stats");
|
|
|
10
10
|
const applyAfterAttackEffects = (attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState) => {
|
|
11
11
|
var _a, _b;
|
|
12
12
|
(0, stealth_1.updateStealth)(attackingEntity, false, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);
|
|
13
|
+
for (const minion of attackingBoard) {
|
|
14
|
+
if (minion === attackingEntity) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const afterAttackImpl = _card_mappings_1.cardMappings[minion.cardId];
|
|
18
|
+
if ((0, card_interface_1.hasAfterAnotherMinionAttacks)(afterAttackImpl)) {
|
|
19
|
+
afterAttackImpl.afterAnotherMinionAttacks(minion, {
|
|
20
|
+
attacker: attackingEntity,
|
|
21
|
+
attackingBoard: attackingBoard,
|
|
22
|
+
attackingHero: attackingBoardHero,
|
|
23
|
+
defendingEntity: defendingEntity,
|
|
24
|
+
defendingBoard: defendingBoard,
|
|
25
|
+
defendingHero: defendingBoardHero,
|
|
26
|
+
gameState: gameState,
|
|
27
|
+
playerIsFriendly: attackingBoardHero.friendly,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
13
31
|
if (attackingEntity.cardId === "BG26_RLK_117" ||
|
|
14
32
|
attackingEntity.cardId === "BG26_RLK_117_G") {
|
|
15
33
|
attackingEntity.definitelyDead = true;
|
|
@@ -34,7 +52,7 @@ const applyAfterAttackEffects = (attackingEntity, attackingBoard, attackingBoard
|
|
|
34
52
|
(0, pending_effects_1.resolvePendingEffects)(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);
|
|
35
53
|
};
|
|
36
54
|
exports.applyAfterAttackEffects = applyAfterAttackEffects;
|
|
37
|
-
const
|
|
55
|
+
const applyAfterAttackTrinkets = (attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState) => {
|
|
38
56
|
var _a;
|
|
39
57
|
const trinkets = (_a = attackingBoardHero.trinkets) !== null && _a !== void 0 ? _a : [];
|
|
40
58
|
for (const trinket of trinkets) {
|
|
@@ -52,26 +70,8 @@ const applyAfterAttackTrinketsAndBoard = (attackingEntity, attackingBoard, attac
|
|
|
52
70
|
});
|
|
53
71
|
}
|
|
54
72
|
}
|
|
55
|
-
for (const minion of attackingBoard) {
|
|
56
|
-
if (minion === attackingEntity) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const afterAttackImpl = _card_mappings_1.cardMappings[minion.cardId];
|
|
60
|
-
if ((0, card_interface_1.hasAfterAnotherMinionAttacks)(afterAttackImpl)) {
|
|
61
|
-
afterAttackImpl.afterAnotherMinionAttacks(minion, {
|
|
62
|
-
attacker: attackingEntity,
|
|
63
|
-
attackingBoard: attackingBoard,
|
|
64
|
-
attackingHero: attackingBoardHero,
|
|
65
|
-
defendingEntity: defendingEntity,
|
|
66
|
-
defendingBoard: defendingBoard,
|
|
67
|
-
defendingHero: defendingBoardHero,
|
|
68
|
-
gameState: gameState,
|
|
69
|
-
playerIsFriendly: attackingBoardHero.friendly,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
73
|
};
|
|
74
|
-
exports.
|
|
74
|
+
exports.applyAfterAttackTrinkets = applyAfterAttackTrinkets;
|
|
75
75
|
const applyOnAttackQuest = (attackingEntity, attackingBoard, attackingBoardHero, gameState) => {
|
|
76
76
|
var _a;
|
|
77
77
|
const quests = (_a = attackingBoardHero.questEntities) !== null && _a !== void 0 ? _a : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"after-attack.js","sourceRoot":"","sources":["../../src/simulation/after-attack.ts"],"names":[],"mappings":";;;AAEA,4DAAuE;AACvE,iEAA4D;AAC5D,iDAAoD;AAGpD,uDAA0D;AAC1D,mCAAiD;AACjD,mCAAsC;AAE/B,MAAM,uBAAuB,GAAG,CACtC,eAA4B,EAC5B,cAA6B,EAC7B,kBAAmC,EACnC,eAA4B,EAC5B,cAA6B,EAC7B,kBAAmC,EACnC,oBAA4B,EAC5B,oBAA4B,EAC5B,SAAwB,EACjB,EAAE;;IAGT,IAAA,uBAAa,EAAC,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,CAAC,CAAC;IAEzG,IACC,eAAe,CAAC,MAAM,mBAA6C;QACnE,eAAe,CAAC,MAAM,qBAA+C,EACpE;QACD,eAAe,CAAC,cAAc,GAAG,IAAI,CAAC;KACtC;SAEI,IAAI,MAAA,eAAe,CAAC,eAAe,0CAAE,QAAQ,gBAA0C,EAAE;QAC7F,eAAe,CAAC,cAAc,GAAG,IAAI,CAAC;KACtC;IAED,cAAc;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,CAAC,eAAe,0CAAE,QAAQ,cAAkC,CAAA,EAAA,CAAC;SAC5E,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACd,IAAA,mBAAW,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEJ,IAAI,eAAe,GAAG,IAAI,CAAC;IAC3B,IACC,CAA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B,EAAE,kBAAkB,CAAC,QAAQ;aAC7C,CAAC,CAAC;SACH;KACD;AACF,CAAC,CAAC;AA3BW,QAAA,wBAAwB,4BA2BnC;AAEF,MAAM,kBAAkB,GAAG,CAC1B,eAA4B,EAC5B,cAA6B,EAC7B,kBAAmC,EACnC,SAAwB,EACvB,EAAE;;IACH,MAAM,MAAM,GAAG,MAAA,kBAAkB,CAAC,aAAa,mCAAI,EAAE,CAAC;IACtD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC3B,QAAQ,KAAK,CAAC,MAAM,EAAE;YACrB;gBACC,IAAA,8BAAsB,EAAC,kBAAkB,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;gBAC7E,MAAM;SACP;KACD;AACF,CAAC,CAAC","sourcesContent":["import { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { hasAfterAnotherMinionAttacks } from '../cards/card.interface';\r\nimport { cardMappings } from '../cards/impl/_card-mappings';\r\nimport { updateStealth } from '../keywords/stealth';\r\nimport { CardIds } from '../services/card-ids';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { resolvePendingEffects } from './pending-effects';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { modifyStats } from './stats';\r\n\r\nexport const applyAfterAttackEffects = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageDoneByAttacker: number,\r\n\tdamageDoneByDefender: number,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// https://replays.firestoneapp.com/?reviewId=9c3ba0f2-d049-4f79-8ec2-7b20ec8d0f68&turn=11&action=5\r\n\t// It looks like Stealth is removed only once the damage is dealt?\r\n\tupdateStealth(attackingEntity, false, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);\r\n\r\n\tfor (const minion of attackingBoard) {\r\n\t\tif (minion === attackingEntity) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tconst afterAttackImpl = cardMappings[minion.cardId];\r\n\t\tif (hasAfterAnotherMinionAttacks(afterAttackImpl)) {\r\n\t\t\tafterAttackImpl.afterAnotherMinionAttacks(minion, {\r\n\t\t\t\tattacker: attackingEntity,\r\n\t\t\t\tattackingBoard: attackingBoard,\r\n\t\t\t\tattackingHero: attackingBoardHero,\r\n\t\t\t\tdefendingEntity: defendingEntity,\r\n\t\t\t\tdefendingBoard: defendingBoard,\r\n\t\t\t\tdefendingHero: defendingBoardHero,\r\n\t\t\t\tgameState: gameState,\r\n\t\t\t\tplayerIsFriendly: attackingBoardHero.friendly,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117 ||\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117_G\r\n\t) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\t// Putricide-only\r\n\telse if (attackingEntity.additionalCards?.includes(CardIds.IncorporealCorporal_BG26_RLK_117)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\r\n\tattackingBoard\r\n\t\t.filter((e) => e.additionalCards?.includes(CardIds.FesterootHulk_BG_GIL_655))\r\n\t\t.forEach((e) => {\r\n\t\t\tmodifyStats(e, e, 1, 0, attackingBoard, attackingBoardHero, gameState);\r\n\t\t});\r\n\r\n\tlet secretTriggered = null;\r\n\tif (\r\n\t\t(secretTriggered = defendingBoardHero.secrets?.find(\r\n\t\t\t(secret) => !secret.triggered && secret?.cardId === CardIds.Reckoning_TB_Bacon_Secrets_14,\r\n\t\t)) != null\r\n\t) {\r\n\t\t// console.log('triggering secret?', damageDoneByAttacker, stringifySimpleCard(attackingEntity, allCards));\r\n\t\tif (damageDoneByAttacker >= 3 && !(attackingEntity.health <= 0 || attackingEntity.definitelyDead)) {\r\n\t\t\tsecretTriggered.triggered = true;\r\n\t\t\tattackingEntity.definitelyDead = true;\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tsecretTriggered,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tapplyOnAttackQuest(attackingEntity, attackingBoard, attackingBoardHero, gameState);\r\n\r\n\tresolvePendingEffects(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);\r\n};\r\n\r\nexport const applyAfterAttackTrinkets = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageDoneByAttacker: number,\r\n\tdamageDoneByDefender: number,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst trinkets = attackingBoardHero.trinkets ?? [];\r\n\tfor (const trinket of trinkets) {\r\n\t\tconst afterAttackImpl = cardMappings[trinket.cardId];\r\n\t\tif (hasAfterAnotherMinionAttacks(afterAttackImpl)) {\r\n\t\t\tafterAttackImpl.afterAnotherMinionAttacks(trinket, {\r\n\t\t\t\tattacker: attackingEntity,\r\n\t\t\t\tattackingBoard: attackingBoard,\r\n\t\t\t\tattackingHero: attackingBoardHero,\r\n\t\t\t\tdefendingEntity: defendingEntity,\r\n\t\t\t\tdefendingBoard: defendingBoard,\r\n\t\t\t\tdefendingHero: defendingBoardHero,\r\n\t\t\t\tgameState: gameState,\r\n\t\t\t\tplayerIsFriendly: attackingBoardHero.friendly,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst applyOnAttackQuest = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst quests = attackingBoardHero.questEntities ?? [];\r\n\tfor (const quest of quests) {\r\n\t\tswitch (quest.CardId) {\r\n\t\t\tcase CardIds.CrackTheCase:\r\n\t\t\t\tonQuestProgressUpdated(attackingBoardHero, quest, attackingBoard, gameState);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport interface OnAfterAttackInput {\r\n\tattacker: BoardEntity;\r\n\tattackingHero: BgsPlayerEntity;\r\n\tattackingBoard: BoardEntity[];\r\n\tdefendingEntity: BoardEntity;\r\n\tdefendingBoard: BoardEntity[];\r\n\tdefendingHero: BgsPlayerEntity;\r\n\tgameState: FullGameState;\r\n\tplayerIsFriendly: boolean;\r\n}\r\n"]}
|
|
@@ -35,6 +35,7 @@ export interface OnAfterDeathInput {
|
|
|
35
35
|
export interface OnAfterFriendlyMinionDeathInput {
|
|
36
36
|
readonly deadEntity: BoardEntity;
|
|
37
37
|
readonly board: BoardEntity[];
|
|
38
|
+
readonly boardBeforeProcs: BoardEntity[];
|
|
38
39
|
readonly hero: BgsPlayerEntity;
|
|
39
40
|
readonly otherBoard: BoardEntity[];
|
|
40
41
|
readonly otherHero: BgsPlayerEntity;
|
|
@@ -71,7 +71,7 @@ const doFullAttack = (attackingEntity, attackingBoard, attackingBoardHero, defen
|
|
|
71
71
|
const damageDoneByDefender = damageDoneByDefender1 + damageDoneByDefender2;
|
|
72
72
|
(0, after_attack_1.applyAfterAttackEffects)(attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState);
|
|
73
73
|
(0, exports.processMinionDeath)(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState, (options === null || options === void 0 ? void 0 : options.skipSummonWhenSpace) || isAttackingImmediately);
|
|
74
|
-
(0, after_attack_1.
|
|
74
|
+
(0, after_attack_1.applyAfterAttackTrinkets)(attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState);
|
|
75
75
|
(0, stats_1.applyAfterStatsUpdate)(gameState);
|
|
76
76
|
attackingEntity.immuneWhenAttackCharges = Math.max(0, ((_a = attackingEntity.immuneWhenAttackCharges) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
77
77
|
};
|