From 864199a8e0653cb2418c564ee83ea433df9c4f96 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Mon, 15 Sep 2025 23:33:07 -0500 Subject: [PATCH] Fix minimum move count threshold and utilize baseWeights --- src/ai/ai-moveset-gen.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ai/ai-moveset-gen.ts b/src/ai/ai-moveset-gen.ts index f392ca46d3f..fcfc93150b2 100644 --- a/src/ai/ai-moveset-gen.ts +++ b/src/ai/ai-moveset-gen.ts @@ -510,11 +510,7 @@ function forceStabMove( const chosenPool = stabMovePool.length > 0 || !forceAnyDamageIfNoStab ? stabMovePool - : filterPool( - pool, - m => allMoves[m[0]].category !== MoveCategory.STATUS && !STAB_BLACKLIST.has(m[0]), - totalWeight, - ); + : filterPool(pool, m => allMoves[m].category !== MoveCategory.STATUS && !STAB_BLACKLIST.has(m), totalWeight); if (chosenPool.length > 0) { let rand = randSeedInt(totalWeight.value); @@ -589,7 +585,7 @@ function fillInRemainingMovesetSlots( const tmCap = getMaxTmCount(pokemon.level); const eggCap = getMaxEggMoveCount(pokemon.level); const remainingPoolWeight = new NumberHolder(0); - while (remainingPool.length > pokemon.moveset.length && pokemon.moveset.length < 4) { + while (pokemon.moveset.length < 4) { const nonLevelMoveCount = tmCount.value + eggMoveCount.value; remainingPool = filterPool( baseWeights, @@ -605,6 +601,11 @@ function fillInRemainingMovesetSlots( if (pokemon.hasTrainer()) { filterRemainingTrainerMovePool(remainingPool, pokemon); } + // Ensure loop cannot run infinitely if there are no allowed moves left to + // fill the remaining slots + if (remainingPool.length === 0) { + return; + } const totalWeight = remainingPool.reduce((v, m) => v + m[1], 0); let rand = randSeedInt(totalWeight); let index = 0; @@ -719,7 +720,7 @@ export function generateMoveset(pokemon: Pokemon): void { tmCount, eggMoveCount, baseWeights, - filterPool(baseWeights, (m: MoveId) => !pokemon.moveset.some(mo => m[0] === mo.moveId)), + filterPool(baseWeights, (m: MoveId) => !pokemon.moveset.some(mo => m === mo.moveId)), ); }