smogon / pokemon-showdown

Pokémon battle simulator.
https://pokemonshowdown.com
MIT License
4.77k stars 2.79k forks source link

Understanding the packed team format #4852

Closed jamesqo closed 6 years ago

jamesqo commented 6 years ago

I'm want to use the sim API for a program of mine and I'm trying to understand how teams are unencoded. For example if I run pokemon-showdown generate-team gen7randombattle I get this output:

Chimecho||leftovers||shadowball,psychic,recover,calmmind||85,,85,85,85,85||,0,,,,||83|]Sceptile||sceptilite||gigadrain,focusblast,earthquake,dragonpulse||85,85,85,85,85,85||||78|]Goodra||assaultvest||thunderbolt,sludgebomb,dracometeor,earthquake||85,85,85,85,85,85||||79|]Necrozma|necrozmadawnwings|ultranecroziumz||photongeyser,powergem,moongeistbeam,calmmind||85,,85,85,85,85||,0,,,,||73|]Tyrantrum||lifeorb||dragonclaw,dragondance,superpower,earthquake||85,85,85,85,85,85||||79|]Blaziken||lifeorb|H|stoneedge,highjumpkick,swordsdance,blazekick||85,85,85,85,85,85||||73|

Markdown output to avoid wrap: https://gist.github.com/jamesqo/1868caf52c87f4036ccb6564b7db2a96

The first 3 fields for each Pokemon seem pretty obvious (name, item, moveset). I don't get what the fields after those are though, can someone explain?

KrisXV commented 6 years ago

the format is generally:

Pokemon Species|Nickname*|Item*|Ability (1)*|Moves|Nature*|EVs (2)*|Gender (3)*|IVs (2)*|Shininess (4)*|Level,Hidden Power type,Pokeball

* If Applicable 1: If nothing appears, that means it's the first ability or a special event ability like Battle Bond, "1" means it's the second ability, "H" means it's a Hidden Ability 2: ,, means ,0, for EVs and ,31, for IVs, and the EVs/IVs line up with HP/Atk/Def/SpA/SpD/Spe; if there are no EVs, or all IVs are set to 31, there will be nothing here 3: If nothing's here, the gender is random or will be the template's only assigned gender 4: If a set is shiny, an "S" will be here, if not, there will be nothing

Level will not appear if it's 100; Hidden Power type will not appear if the Pokemon is not running Hidden Power and/or the type is Dark

Zarel commented 6 years ago

You want Dex.fastUnpackTeam, by the way.

zarel@Lysine ~/W/showdown (master)> node
> const Dex = require('./sim/dex');
undefined
> Dex.fastUnpackTeam('Chimecho||leftovers||shadowball,psychic,recover,calmmind||85,,85,85,85,85||,0,,,,||83|]Sceptile||sceptilite||gigadrain,focusblast,earthquake,dragonpulse||85,85,85,85,85,85||||78|]Goodra||assaultvest||thunderbolt,sludgebomb,dracometeor,earthquake||85,85,85,85,85,85||||79|]Necrozma|necrozmadawnwings|ultranecroziumz||photongeyser,powergem,moongeistbeam,calmmind||85,,85,85,85,85||,0,,,,||73|]Tyrantrum||lifeorb||dragonclaw,dragondance,superpower,earthquake||85,85,85,85,85,85||||79|]Blaziken||lifeorb|H|stoneedge,highjumpkick,swordsdance,blazekick||85,85,85,85,85,85||||73|')
[ { name: 'Chimecho',
    species: 'Chimecho',
    item: 'leftovers',
    ability: 'Levitate',
    moves: [ 'shadowball', 'psychic', 'recover', 'calmmind' ],
    nature: '',
    evs: { hp: 85, atk: 0, def: 85, spa: 85, spd: 85, spe: 85 },
    ivs: { hp: 31, atk: 0, def: 31, spa: 31, spd: 31, spe: 31 },
    level: 83 },
  { name: 'Sceptile',
    species: 'Sceptile',
    item: 'sceptilite',
    ability: 'Overgrow',
    moves: [ 'gigadrain', 'focusblast', 'earthquake', 'dragonpulse' ],
    nature: '',
    evs: { hp: 85, atk: 85, def: 85, spa: 85, spd: 85, spe: 85 },
    level: 78 },
  { name: 'Goodra',
    species: 'Goodra',
    item: 'assaultvest',
    ability: 'Sap Sipper',
    moves: [ 'thunderbolt', 'sludgebomb', 'dracometeor', 'earthquake' ],
    nature: '',
    evs: { hp: 85, atk: 85, def: 85, spa: 85, spd: 85, spe: 85 },
    level: 79 },
  { name: 'Necrozma',
    species: 'necrozmadawnwings',
    item: 'ultranecroziumz',
    ability: 'Prism Armor',
    moves: [ 'photongeyser', 'powergem', 'moongeistbeam', 'calmmind' ],
    nature: '',
    evs: { hp: 85, atk: 0, def: 85, spa: 85, spd: 85, spe: 85 },
    ivs: { hp: 31, atk: 0, def: 31, spa: 31, spd: 31, spe: 31 },
    level: 73 },
  { name: 'Tyrantrum',
    species: 'Tyrantrum',
    item: 'lifeorb',
    ability: 'Strong Jaw',
    moves: [ 'dragonclaw', 'dragondance', 'superpower', 'earthquake' ],
    nature: '',
    evs: { hp: 85, atk: 85, def: 85, spa: 85, spd: 85, spe: 85 },
    level: 79 },
  { name: 'Blaziken',
    species: 'Blaziken',
    item: 'lifeorb',
    ability: 'Speed Boost',
    moves: [ 'stoneedge', 'highjumpkick', 'swordsdance', 'blazekick' ],
    nature: '',
    evs: { hp: 85, atk: 85, def: 85, spa: 85, spd: 85, spe: 85 },
    level: 73 } ]
Zarel commented 6 years ago

Reading the source code for fastUnpackTeam is the best way to understand the packed format:

https://github.com/Zarel/Pokemon-Showdown/blob/fb0f401a6bc83a9b176040ede94e3e67fadaaa95/sim/dex.js#L1208-L1334

Zarel commented 6 years ago

There's also pokemon-showdown unpack-team but I guess you wanted to learn the format for yourself instead of just having PS unpack it for you?

Zarel commented 6 years ago

But if you didn't care for that, you can just pipe it:

zarel@Lysine ~/W/showdown (master)>
./pokemon-showdown generate-team | ./pokemon-showdown unpack-team
[{"name":"Tornadus","species":"Tornadus","item":"","ability":"Prankster","moves":["acrobatics","substitute","bulkup","superpower"],"nature":"","evs":{"hp":85,"atk":85,"def":85,"spa":85,"spd":85,"spe":85},"level":78},{"name":"Banette","species":"Banette","item":"banettite","ability":"Cursed Body","moves":["willowisp","taunt","knockoff","shadowclaw"],"nature":"","evs":{"hp":85,"atk":85,"def":85,"spa":85,"spd":85,"spe":85},"level":79},{"name":"Miltank","species":"Miltank","item":"leftovers","ability":"Sap Sipper","moves":["curse","earthquake","bodyslam","healbell"],"nature":"","evs":{"hp":85,"atk":85,"def":85,"spa":85,"spd":85,"spe":85},"level":81},{"name":"Zoroark","species":"Zoroark","item":"lifeorb","ability":"Illusion","moves":["focusblast","nastyplot","sludgebomb","darkpulse"],"nature":"","evs":{"hp":85,"atk":0,"def":85,"spa":85,"spd":85,"spe":85},"ivs":{"hp":31,"atk":0,"def":31,"spa":31,"spd":31,"spe":31},"level":78},{"name":"Relicanth","species":"Relicanth","item":"leftovers","ability":"Rock Head","moves":["earthquake","headsmash","toxic","waterfall"],"nature":"","evs":{"hp":85,"atk":85,"def":85,"spa":85,"spd":85,"spe":85},"level":83},{"name":"Jolteon","species":"Jolteon","item":"choicespecs","ability":"Volt Absorb","moves":["thunderbolt","hiddenpowerice","signalbeam","shadowball"],"nature":"","evs":{"hp":85,"atk":0,"def":85,"spa":85,"spd":85,"spe":85},"ivs":{"hp":31,"atk":0,"def":31,"spa":31,"spd":31,"spe":31},"level":79}]