[Dev] Improve logging in EnemyPokemon#getNextMove (#6803)

This commit is contained in:
NightKev 2025-11-29 16:58:34 -06:00 committed by GitHub
parent a2b4727d63
commit 477b8de7d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6585,11 +6585,10 @@ export class EnemyPokemon extends Pokemon {
*/ */
const moveScores = movePool.map(() => 0); const moveScores = movePool.map(() => 0);
const moveTargets = Object.fromEntries(movePool.map(m => [m.moveId, this.getNextTargets(m.moveId)])); const moveTargets = Object.fromEntries(movePool.map(m => [m.moveId, this.getNextTargets(m.moveId)]));
for (const m in movePool) { movePool.forEach((pokemonMove, moveIndex) => {
const pokemonMove = movePool[m];
const move = pokemonMove.getMove(); const move = pokemonMove.getMove();
let moveScore = moveScores[m]; let moveScore = moveScores[moveIndex];
const targetScores: number[] = []; const targetScores: number[] = [];
for (const mt of moveTargets[move.id]) { for (const mt of moveTargets[move.id]) {
@ -6611,10 +6610,7 @@ export class EnemyPokemon extends Pokemon {
console.error(`Move ${move.name} returned score of NaN`); console.error(`Move ${move.name} returned score of NaN`);
targetScore = 0; targetScore = 0;
} }
/** // If this move is unimplemented, or the move is known to fail when used, set its target score to -20
* If this move is unimplemented, or the move is known to fail when used, set its
* target score to -20
*/
if ( if (
(move.name.endsWith(" (N)") || !move.applyConditions(this, target, -1)) (move.name.endsWith(" (N)") || !move.applyConditions(this, target, -1))
&& ![MoveId.SUCKER_PUNCH, MoveId.UPPER_HAND, MoveId.THUNDERCLAP].includes(move.id) && ![MoveId.SUCKER_PUNCH, MoveId.UPPER_HAND, MoveId.THUNDERCLAP].includes(move.id)
@ -6645,7 +6641,7 @@ export class EnemyPokemon extends Pokemon {
targetScore /= 1.5; targetScore /= 1.5;
} }
} }
/** If a move has a base benefit score of 0, its benefit score is assumed to be unimplemented at this point */ // If a move has a base benefit score of 0, its benefit score is assumed to be unimplemented at this point
if (!targetScore) { if (!targetScore) {
targetScore = -20; targetScore = -20;
} }
@ -6656,10 +6652,8 @@ export class EnemyPokemon extends Pokemon {
moveScore += Math.max(...targetScores); moveScore += Math.max(...targetScores);
// could make smarter by checking opponent def/spdef // could make smarter by checking opponent def/spdef
moveScores[m] = moveScore; moveScores[moveIndex] = moveScore;
} });
console.log(moveScores);
// Sort the move pool in decreasing order of move score // Sort the move pool in decreasing order of move score
const sortedMovePool = movePool.slice(0); const sortedMovePool = movePool.slice(0);
@ -6668,37 +6662,42 @@ export class EnemyPokemon extends Pokemon {
const scoreB = moveScores[movePool.indexOf(b)]; const scoreB = moveScores[movePool.indexOf(b)];
return scoreA < scoreB ? 1 : scoreA > scoreB ? -1 : 0; return scoreA < scoreB ? 1 : scoreA > scoreB ? -1 : 0;
}); });
let r = 0; let chosenMoveIndex = 0;
if (this.aiType === AiType.SMART_RANDOM) { if (this.aiType === AiType.SMART_RANDOM) {
// Has a 5/8 chance to select the best move, and a 3/8 chance to advance to the next best move (and repeat this roll) // Has a 5/8 chance to select the best move, and a 3/8 chance to advance to the next best move (and repeat this roll)
while (r < sortedMovePool.length - 1 && globalScene.randBattleSeedInt(8) >= 5) { while (chosenMoveIndex < sortedMovePool.length - 1 && globalScene.randBattleSeedInt(8) >= 5) {
r++; chosenMoveIndex++;
} }
} else if (this.aiType === AiType.SMART) { } else if (this.aiType === AiType.SMART) {
// The chance to advance to the next best move increases when the compared moves' scores are closer to each other. // The chance to advance to the next best move increases when the compared moves' scores are closer to each other.
while ( while (
r < sortedMovePool.length - 1 chosenMoveIndex < sortedMovePool.length - 1
&& moveScores[movePool.indexOf(sortedMovePool[r + 1])] / moveScores[movePool.indexOf(sortedMovePool[r])] && moveScores[movePool.indexOf(sortedMovePool[chosenMoveIndex + 1])]
/ moveScores[movePool.indexOf(sortedMovePool[chosenMoveIndex])]
>= 0 >= 0
&& globalScene.randBattleSeedInt(100) && globalScene.randBattleSeedInt(100)
< Math.round( < Math.round(
(moveScores[movePool.indexOf(sortedMovePool[r + 1])] (moveScores[movePool.indexOf(sortedMovePool[chosenMoveIndex + 1])]
/ moveScores[movePool.indexOf(sortedMovePool[r])]) / moveScores[movePool.indexOf(sortedMovePool[chosenMoveIndex])])
* 50, * 50,
) )
) { ) {
r++; chosenMoveIndex++;
} }
} }
console.log(
movePool.map(m => m.getName()), const chosenMove = sortedMovePool[chosenMoveIndex];
moveScores,
r, // biome-ignore format: For some reason this gets broken into multiple lines
sortedMovePool.map(m => m.getName()), console.log("Move Pool:", movePool.map((m) => m.getName()));
); console.log("Move Scores:", moveScores);
// biome-ignore format: For some reason this gets broken into multiple lines
console.log("Sorted Move Pool:", sortedMovePool.map((m) => m.getName()));
console.log("Chosen Move:", chosenMove.getName());
return { return {
move: sortedMovePool[r]!.moveId, move: chosenMove.moveId,
targets: moveTargets[sortedMovePool[r]!.moveId], targets: moveTargets[chosenMove.moveId],
useMode: MoveUseMode.NORMAL, useMode: MoveUseMode.NORMAL,
}; };
} }