Zarel/Pokemon-Showdown — pull request #255 by Jay2645 (2013-06-25 23:07:30+00:00)
Title: Modified Random Battle code to prevent unfair teams.

Random Battle now attempts to minimize the amount of "bad" teams generated; although there is a leveling system which tries to boost less-powerful Pokemon, every now and again the team generator conspires against you to give you a Ralts, Magikarp, Rattata, and Stunfisk while your enemy gets Groudon, Arceus, Mewtwo, and Darkrai. Even if you have a level 99 Wurmple, it's still a liability and isn't much fun to play.

This tries to fix unfair teams through three steps:
1. Places limits on the number of NU/Uber Pokemon that can be on a single team. LC Pokemon have a "hard" limit of 2; NFEs/NUs/Ubers are also limited to 2, but it is a "soft" limit (they have a 20% chance of being added anyway). LC/NFE/NU Pokemon all share a counter (so having a LC Pokemon, a NFE Pokemon, and a NU Pokemon would make the counter 3), while Ubers have their own individual counter.
2. Places a soft limit of 2 on the amount of Pokemon of a specific type on one team. This is to prevent one team being made entirely of grass-types while the other is entirely made of fire-types.
3. Restricts Pokemon from the same evolutionary line from being placed on the same team. For example, Growlithe is illegal if the team already has Arcanine on it. Note that this does not cover split evolutionary lines; Jolteon and Vaporeon are legal together, but Jolteon and Eevee are not.