Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Line Tools Invalid Generated Team For Format #10187

Open
ImmortalNG opened this issue Feb 27, 2024 · 0 comments
Open

Command Line Tools Invalid Generated Team For Format #10187

ImmortalNG opened this issue Feb 27, 2024 · 0 comments

Comments

@ImmortalNG
Copy link

ImmortalNG commented Feb 27, 2024

Teams generated for a format are invalid. I don't know js so the best fix I could do was running the validator.
Also gen9 just doesn't work with formats. <- fixed by removing enforce banlist
Edit: Gen2, Gen4, Gen6 doesn't work either, no func to generate a team
Edit 2: The fix doesn't work. Not all formats (like random battle) have validator valid functions so it fails.
`randomTeam() {
this.enforceNoDirectCustomBanlistChanges();
const Teams = require('../../../sim/teams.js').Teams;
const TeamValidator = require('../../../sim/team-validator.js').TeamValidator;
const validator = TeamValidator.get(this.format.id);

const seed = this.prng.seed;
const ruleTable = this.dex.formats.getRuleTable(this.format);
var pokemon = [];
const isMonotype = !!this.forceMonotype || ruleTable.has("sametypeclause");
const isDoubles = this.format.gameType !== "singles";
const typePool = this.dex.types.names();
const type = this.forceMonotype || this.sample(typePool);
const usePotD = global.Config && Config.potd && ruleTable.has("potd");
const potd = usePotD ? this.dex.species.get(Config.potd) : null;
const baseFormes = {};
const typeCount = {};
const typeComboCount = {};
const typeWeaknesses = {};
const teamDetails = {};
let numMaxLevelPokemon = 0;
const pokemonList = [];
for (const poke of Object.keys(this.randomData)) {
  if (isDoubles && this.randomData[poke]?.doublesMoves || !isDoubles && this.randomData[poke]?.moves) {
    pokemonList.push(poke);
  }
}
const [pokemonPool, baseSpeciesPool] = this.getPokemonPool(type, pokemon, isMonotype, pokemonList);
while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) {
  const baseSpecies = this.sampleNoReplace(baseSpeciesPool);
  let species = this.dex.species.get(this.sample(pokemonPool[baseSpecies]));
  if (!species.exists)
    continue;
  if (baseFormes[species.baseSpecies])
    continue;
  if (species.name === "Zoroark" && pokemon.length >= this.maxTeamSize - 1)
    continue;
  if (pokemon.some((pkmn) => pkmn.name === "Zoroark") && pokemon.length >= this.maxTeamSize - 1 && ["Zacian", "Zacian-Crowned", "Zamazenta", "Zamazenta-Crowned", "Eternatus"].includes(species.name))
    continue;
  const types = species.types;
  const typeCombo = types.slice().sort().join();
  const weakToFreezeDry = this.dex.getEffectiveness("Ice", species) > 0 || this.dex.getEffectiveness("Ice", species) > -2 && types.includes("Water");
  const limitFactor = Math.round(this.maxTeamSize / 6) || 1;
    
  if (!isMonotype && !this.forceMonotype) {
    let skip = false;
    for (const typeName of types) {
      if (typeCount[typeName] >= 2 * limitFactor) {
        skip = true;
        break;
      }
    }
    if (skip)
      continue;
      
    for (const typeName of this.dex.types.names()) {
      if (this.dex.getEffectiveness(typeName, species) > 0) {
        if (!typeWeaknesses[typeName])
          typeWeaknesses[typeName] = 0;
        if (typeWeaknesses[typeName] >= 3 * limitFactor) {
          skip = true;
          break;
        }
      }
    }
    if (skip)
      continue;
      
    if (weakToFreezeDry) {
      if (!typeWeaknesses["Freeze-Dry"])
        typeWeaknesses["Freeze-Dry"] = 0;
      if (typeWeaknesses["Freeze-Dry"] >= 4 * limitFactor)
        continue;
    }
    if (!this.adjustLevel && numMaxLevelPokemon >= limitFactor && this.getLevel(species, isDoubles, ruleTable.has("dynamaxclause")) === 100)
      continue;
  }
  if (!this.forceMonotype && isMonotype && typeComboCount[typeCombo] >= 3 * limitFactor)
    continue;
  if (potd?.exists && (pokemon.length === 1 || this.maxTeamSize === 1))
    species = potd;
  const set = this.randomSet(
    species,
    teamDetails,
    pokemon.length === 0,
    isDoubles,
    ruleTable.has("dynamaxclause")
  );
    
  pokemon.push(set);
  var team = Teams.import(Teams.pack(pokemon));
  var result = validator.validateTeam(team);  
  if (result)
      pokemon = pokemon.splice(0, -1);
      continue;  
    
  if (pokemon.length === this.maxTeamSize)
    break;
    
  baseFormes[species.baseSpecies] = 1;
  for (const typeName of types) {
    if (typeName in typeCount) {
      typeCount[typeName]++;
    } else {
      typeCount[typeName] = 1;
    }
  }
  if (typeCombo in typeComboCount) {
    typeComboCount[typeCombo]++;
  } else {
    typeComboCount[typeCombo] = 1;
  }
  for (const typeName of this.dex.types.names()) {
    if (this.dex.getEffectiveness(typeName, species) > 0) {
      typeWeaknesses[typeName]++;
    }
  }
  if (weakToFreezeDry)
    typeWeaknesses["Freeze-Dry"]++;
  if (set.level === 100)
    numMaxLevelPokemon++;
  if (set.ability === "Drizzle" || set.moves.includes("raindance"))
    teamDetails.rain = 1;
  if (set.ability === "Drought" || set.moves.includes("sunnyday"))
    teamDetails.sun = 1;
  if (set.ability === "Sand Stream")
    teamDetails.sand = 1;
  if (set.ability === "Snow Warning")
    teamDetails.hail = 1;
  if (set.moves.includes("spikes"))
    teamDetails.spikes = (teamDetails.spikes || 0) + 1;
  if (set.moves.includes("stealthrock"))
    teamDetails.stealthRock = 1;
  if (set.moves.includes("stickyweb"))
    teamDetails.stickyWeb = 1;
  if (set.moves.includes("toxicspikes"))
    teamDetails.toxicSpikes = 1;
  if (set.moves.includes("defog"))
    teamDetails.defog = 1;
  if (set.moves.includes("rapidspin"))
    teamDetails.rapidSpin = 1;
  if (set.moves.includes("auroraveil") || set.moves.includes("reflect") && set.moves.includes("lightscreen")) {
    teamDetails.screens = 1;
  }
}
  
if (pokemon.length < this.maxTeamSize && pokemon.length < 12) {
  throw new Error(`Could not build a random team for ${this.format} (seed=${seed})`);
}
  
return pokemon;

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant