Skip to content

Commit

Permalink
Gen 9 Battle Factory: Enhance team generation restrictions (smogon#10694
Browse files Browse the repository at this point in the history
)

* Gen9 Battle Factory: Enhance team generation restrictions

* one more comment

* remove unneeded comment, also space->tab

* precompute typemod and take into account immunity

* trim comment

* actually add immunity to weakness counter

* one more refactor and then it's all over :)

* actually done now!
  • Loading branch information
adrivrie authored Nov 27, 2024
1 parent 8563a56 commit 554a59e
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions data/random-battles/gen9/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,20 @@ export class RandomTeams {
}
if (skip) continue;

if (!teamData.forceResult && !this.forceMonotype) {
// Limit 3 of any weakness
for (const typeName of this.dex.types.names()) {
// it's weak to the type
if (this.dex.getEffectiveness(typeName, species) > 0 && this.dex.getImmunity(typeName, types)) {
if (teamData.weaknesses[typeName] >= 3 * limitFactor) {
skip = true;
break;
}
}
}
}
if (skip) continue;

const set = this.randomFactorySet(species, teamData, this.factoryTier);
if (!set) continue;

Expand Down Expand Up @@ -2626,18 +2640,16 @@ export class RandomTeams {
}

for (const typeName of this.dex.types.names()) {
// Cover any major weakness (3+) with at least one resistance
if (teamData.resistances[typeName] >= 1) continue;
if (resistanceAbilities[ability.id]?.includes(typeName) || !this.dex.getImmunity(typeName, types)) {
// Heuristic: assume that Pokémon with these abilities don't have (too) negative typing.
teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
continue;
}
const typeMod = this.dex.getEffectiveness(typeName, types);
if (typeMod < 0) {
teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
// Track resistances because we will require it for triple weaknesses
if (
typeMod < 0 ||
resistanceAbilities[ability.id]?.includes(typeName) ||
!this.dex.getImmunity(typeName, types)
) {
// We don't care about the number of resistances, so just set to 1
teamData.resistances[typeName] = 1;
// Track weaknesses
} else if (typeMod > 0) {
teamData.weaknesses[typeName] = (teamData.weaknesses[typeName] || 0) + 1;
}
Expand All @@ -2648,6 +2660,8 @@ export class RandomTeams {
// Quality control we cannot afford for monotype
if (!teamData.forceResult && !this.forceMonotype) {
for (const type in teamData.weaknesses) {
// We reject if our team is triple weak to any type without having a resist
if (teamData.resistances[type]) continue;
if (teamData.weaknesses[type] >= 3 * limitFactor) return this.randomFactoryTeam(side, ++depth);
}
}
Expand Down

0 comments on commit 554a59e

Please sign in to comment.