Tweak stab move weight generation

This commit is contained in:
Sirz Benjie 2025-09-14 21:35:16 -05:00
parent 3e4f1d71cc
commit cc7c4cafc7
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
2 changed files with 23 additions and 7 deletions

View File

@ -303,6 +303,11 @@ function filterMovePool(pool: Map<MoveId, number>, isBoss: boolean, hasTrainer:
continue; continue;
} }
const move = allMoves[moveId]; const move = allMoves[moveId];
// Forbid unimplemented moves
if (move.name.endsWith(" (N)")) {
pool.delete(moveId);
continue;
}
// Bosses never get self ko moves or Pain Split // Bosses never get self ko moves or Pain Split
if (isBoss && (move.hasAttr("SacrificialAttr") || move.hasAttr("HpSplitAttr"))) { if (isBoss && (move.hasAttr("SacrificialAttr") || move.hasAttr("HpSplitAttr"))) {
pool.delete(moveId); pool.delete(moveId);
@ -553,6 +558,16 @@ function filterRemainingTrainerMovePool(pool: [id: MoveId, weight: number][], po
} }
} }
/**
* Fill in the remaining slots in the Pokémon's moveset from the provided pools
* @param pokemon - The Pokémon for which the moveset is being generated
* @param tmPool - The TM move pool
* @param eggMovePool - The egg move pool
* @param tmCount - A holder for the count of moves that have been added to the moveset from TMs
* @param eggMoveCount - A holder for the count of moves that have been added to the moveset from egg moves
* @param baseWeights - The base weights of all moves in the master pool
* @param remainingPool - The remaining move pool to select from
*/
function fillInRemainingMovesetSlots( function fillInRemainingMovesetSlots(
pokemon: Pokemon, pokemon: Pokemon,
tmPool: Map<MoveId, number>, tmPool: Map<MoveId, number>,
@ -566,6 +581,7 @@ function fillInRemainingMovesetSlots(
const eggCap = getMaxEggMoveCount(pokemon.level); const eggCap = getMaxEggMoveCount(pokemon.level);
const remainingPoolWeight = new NumberHolder(0); const remainingPoolWeight = new NumberHolder(0);
while (remainingPool.length > pokemon.moveset.length && pokemon.moveset.length < 4) { while (remainingPool.length > pokemon.moveset.length && pokemon.moveset.length < 4) {
const nonLevelMoveCount = tmCount.value + eggMoveCount.value;
remainingPool = filterPool( remainingPool = filterPool(
baseWeights, baseWeights,
(m: MoveId) => (m: MoveId) =>
@ -573,8 +589,8 @@ function fillInRemainingMovesetSlots(
mo => mo =>
m === mo.moveId || (allMoves[m]?.hasAttr("SacrificialAttr") && mo.getMove()?.hasAttr("SacrificialAttr")), // Only one self-KO move allowed m === mo.moveId || (allMoves[m]?.hasAttr("SacrificialAttr") && mo.getMove()?.hasAttr("SacrificialAttr")), // Only one self-KO move allowed
) )
&& (tmCount.value < tmCap || !tmPool.has(m)) && (nonLevelMoveCount < tmCap || !tmPool.has(m))
&& (eggMoveCount.value < eggCap || !eggMovePool.has(m)), && (nonLevelMoveCount < eggCap || !eggMovePool.has(m)),
remainingPoolWeight, remainingPoolWeight,
); );
if (pokemon.hasTrainer()) { if (pokemon.hasTrainer()) {
@ -662,14 +678,14 @@ export function generateMoveset(pokemon: Pokemon): void {
/** The higher this is, the greater the impact of weight. At `0` all moves are equal weight. */ /** The higher this is, the greater the impact of weight. At `0` all moves are equal weight. */
let weightMultiplier = BASE_WEIGHT_MULTIPLIER; let weightMultiplier = BASE_WEIGHT_MULTIPLIER;
if (pokemon.isBoss()) { if (isBoss) {
weightMultiplier += BOSS_EXTRA_WEIGHT_MULTIPLIER; weightMultiplier += BOSS_EXTRA_WEIGHT_MULTIPLIER;
} }
const baseWeights = new Map<MoveId, number>(movePool); const baseWeights = new Map<MoveId, number>(movePool);
for (const [moveId, weight] of baseWeights) { for (const [moveId, weight] of baseWeights) {
if (weight <= 0) { if (weight <= 0) {
movePool.delete(moveId); baseWeights.delete(moveId);
continue; continue;
} }
baseWeights.set(moveId, Math.ceil(Math.pow(weight, weightMultiplier) * 100)); baseWeights.set(moveId, Math.ceil(Math.pow(weight, weightMultiplier) * 100));
@ -681,7 +697,7 @@ export function generateMoveset(pokemon: Pokemon): void {
debugMoveWeights(pokemon, baseWeights, "Pre STAB Move"); debugMoveWeights(pokemon, baseWeights, "Pre STAB Move");
// Step 4: Force a STAB move if possible // Step 4: Force a STAB move if possible
forceStabMove(baseWeights, tmPool, eggMovePool, pokemon, tmCount, eggMoveCount, willTera); forceStabMove(movePool, tmPool, eggMovePool, pokemon, tmCount, eggMoveCount, willTera);
// Note: To force a secondary stab, call this a second time, and pass `false` for the last parameter // Note: To force a secondary stab, call this a second time, and pass `false` for the last parameter
// Would also tweak the function to not consider moves already in the moveset // Would also tweak the function to not consider moves already in the moveset
// e.g. forceStabMove(..., false); // e.g. forceStabMove(..., false);
@ -694,6 +710,6 @@ export function generateMoveset(pokemon: Pokemon): void {
tmCount, tmCount,
eggMoveCount, eggMoveCount,
baseWeights, baseWeights,
filterPool(baseWeights, (m: MoveId) => allMoves[m] != null), filterPool(baseWeights, (m: MoveId) => !pokemon.moveset.some(mo => m[0] === mo.moveId)),
); );
} }

View File

@ -99,7 +99,7 @@ export const EGG_MOVE_WEIGHT_MAX = 60;
*/ */
export const EGG_MOVE_TO_LEVEL_WEIGHT = 0.85; export const EGG_MOVE_TO_LEVEL_WEIGHT = 0.85;
/** The weight given to evolution moves */ /** The weight given to evolution moves */
export const EVOLUTION_MOVE_WEIGHT = 60; export const EVOLUTION_MOVE_WEIGHT = 70;
/** The weight given to relearn moves */ /** The weight given to relearn moves */
export const RELEARN_MOVE_WEIGHT = 60; export const RELEARN_MOVE_WEIGHT = 60;