smogon / pokemon-showdown

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

JavaScript library not taking in teams input #8144

Closed MusicDev33 closed 3 years ago

MusicDev33 commented 3 years ago

What I'm Trying to Do

So I'm trying to simulate battles with the NPM package. I essentially am just trying to pass in the team I want (packed) into the PLAYEROPTIONS object at the beginning of the battle. Here's what my input looks like:

const player1 = {
  name: 'Test 1',
  avatar: 'Test A',
  team: testTeam
};

const player2 = {
  name: 'Test 2',
  avatar: 'Test B',
  team: team2
}

console.log(`>player p1 ${JSON.stringify(player1)}`);
console.log(team2);

stream.write(`>start {"formatid":"gen8randombattle"}`);

let team = '||||||||||100|]';
for (let i = 0; i < 5; i++) {
  team += team;
}
stream.write(`>player p1 ${JSON.stringify(player1)}`);
stream.write(`>player p2 ${JSON.stringify(player2)}`);
stream.write('>p1 default');
stream.write('>p2 default');

In the above code, testTeam is looks exactly like this: Bewear||lifeorb|fluffy|closecombat,doubleedge,darkestlariat,swordsdance||85,85,85,85,85,85||||82|]Corsola||rockyhelmet|regenerator|stealthrock,recover,powergem,scald||85,,85,85,85,85||,0,,,,||90|]Zoroark||lifeorb|illusion|darkpulse,sludgebomb,nastyplot,flamethrower||85,,85,85,85,85||,0,,,,||84|]Alakazam||lifeorb|magicguard|shadowball,focusblast,psychic,nastyplot||85,,85,85,85,85||,0,,,,||78|]Registeel||chestoberry|clearbody|protect,seismictoss,toxic,rest||85,,85,85,85,85|N|,0,,,,||82|]Hitmonlee||whiteherb|unburden|poisonjab,closecombat,curse,knockoff||85,85,85,85,85,85|M|||84|

and the final stdin looks like this:

>player p1 {"name":"Test 1","avatar":"Test A","team":"Bewear||lifeorb|fluffy|closecombat,doubleedge,darkestlariat,swordsdance||85,85,85,85,85,85||||82|]Corsola||rockyhelmet|regenerator|stealthrock,recover,powergem,scald||85,,85,85,85,85||,0,,,,||90|]Zoroark||lifeorb|illusion|darkpulse,sludgebomb,nastyplot,flamethrower||85,,85,85,85,85||,0,,,,||84|]Alakazam||lifeorb|magicguard|shadowball,focusblast,psychic,nastyplot||85,,85,85,85,85||,0,,,,||78|]Registeel||chestoberry|clearbody|protect,seismictoss,toxic,rest||85,,85,85,85,85|N|,0,,,,||82|]Hitmonlee||whiteherb|unburden|poisonjab,closecombat,curse,knockoff||85,85,85,85,85,85|M|||84|"}

The team 2 variable just uses the command line tools to generate a team (packed) to pass in.

Problem

Whenever I start the battle and read the outputs, the simulator is still generating random teams even though I've passed in a team. As far as I can see, all the inputs look correct, and I've double-checked the documentation (which is a little sparse and not super helpful if I'm being honest). Is there anything I need to be doing on my end to make the battle simulator take in the teams?

Zarel commented 3 years ago

Hm. I don't know if we have the ability to force a random battle to take a specified team, but it shouldn't be too hard of a feature to add if not.

Zarel commented 3 years ago

Yep, it looks like in random battles, any team you try to pass is simply discarded. It's probably safe to make it default to a passed team. I'll make that change soon.

Zarel commented 3 years ago

If you don't want to wait for the next release, one workaround you can do is to use gen8ou @@@ !teampreview as your format, instead of gen8randombattle. I believe this will use basically the same rules.

MusicDev33 commented 3 years ago

So how does using teams on the new commit work? Also using gen8ou @@@ !teampreview gives the following error: Error: Rule " !teampreview" should be trimmed, I'm assuming I'm using that incorrectly

Zarel commented 3 years ago

Your code should be correct for the newest version. Is it still not working?

MusicDev33 commented 3 years ago

No, it's still not working. Here's my code:

const testTeam = 'Bewear||lifeorb|fluffy|closecombat,doubleedge,darkestlariat,swordsdance||85,85,85,85,85,85||||82|]Corsola||rockyhelmet|regenerator|stealthrock,recover,powergem,scald||85,,85,85,85,85||,0,,,,||90|]Zoroark||lifeorb|illusion|darkpulse,sludgebomb,nastyplot,flamethrower||85,,85,85,85,85||,0,,,,||84|]Alakazam||lifeorb|magicguard|shadowball,focusblast,psychic,nastyplot||85,,85,85,85,85||,0,,,,||78|]Registeel||chestoberry|clearbody|protect,seismictoss,toxic,rest||85,,85,85,85,85|N|,0,,,,||82|]Hitmonlee||whiteherb|unburden|poisonjab,closecombat,curse,knockoff||85,85,85,85,85,85|M|||84|';

  const player1 = {
    name: 'Test 1',
    avatar: 'Test A',
    team: testTeam
  };

stream.write(`>start {"formatid":"gen8randombattle"}`);
Zarel commented 3 years ago

Are you missing some support code? Your code works if fleshed out, for me:

const Sim = require('pokemon-showdown');

const testTeam = 'Bewear||lifeorb|fluffy|closecombat,doubleedge,darkestlariat,swordsdance||85,85,85,85,85,85||||82|]Corsola||rockyhelmet|regenerator|stealthrock,recover,powergem,scald||85,,85,85,85,85||,0,,,,||90|]Zoroark||lifeorb|illusion|darkpulse,sludgebomb,nastyplot,flamethrower||85,,85,85,85,85||,0,,,,||84|]Alakazam||lifeorb|magicguard|shadowball,focusblast,psychic,nastyplot||85,,85,85,85,85||,0,,,,||78|]Registeel||chestoberry|clearbody|protect,seismictoss,toxic,rest||85,,85,85,85,85|N|,0,,,,||82|]Hitmonlee||whiteherb|unburden|poisonjab,closecombat,curse,knockoff||85,85,85,85,85,85|M|||84|';

const p1 = {
    name: 'Test 1',
    team: testTeam
};
const p2 = {
    name: 'Test 1',
    team: testTeam
};

const stream = new Sim.BattleStream();

(async () => {
    for await (const output of stream) {
        console.log(output);
    }
})();

stream.write(`>start {"formatid":"gen8randombattle"}`);
stream.write(`>player p1 ${JSON.stringify(p1)}`);
stream.write(`>player p2 ${JSON.stringify(p2)}`);
stream.write(`>p1 default`);
stream.write(`>p2 default`);
MusicDev33 commented 3 years ago

Have you checked what Pokemon each of the players are using? That's where my problem is, I just ran it and both are using Pokemon not from the test team. It'll run, but it's randomizing teams instead of using the one I input

Zarel commented 3 years ago

Yeah, it's two Bewears as expected:

update
|
|t:|1617397347
|move|p2a: Bewear|Close Combat|p1a: Bewear
|-supereffective|p1a: Bewear
|split|p1
|-damage|p1a: Bewear|104/331
|-damage|p1a: Bewear|32/100
|-unboost|p2a: Bewear|def|1
|-unboost|p2a: Bewear|spd|1
|split|p2
|-damage|p2a: Bewear|298/331|[from] item: Life Orb
|-damage|p2a: Bewear|91/100|[from] item: Life Orb
|move|p1a: Bewear|Close Combat|p2a: Bewear
|-supereffective|p2a: Bewear
|split|p2
|-damage|p2a: Bewear|0 fnt
|-damage|p2a: Bewear|0 fnt
|-unboost|p1a: Bewear|def|1
|-unboost|p1a: Bewear|spd|1
|split|p1
|-damage|p1a: Bewear|71/331|[from] item: Life Orb
|-damage|p1a: Bewear|22/100|[from] item: Life Orb
|faint|p2a: Bewear
|
|upkeep
Zarel commented 3 years ago

Are you sure you have 0.11.5?

MusicDev33 commented 3 years ago

Yep! I have 0.11.5

MusicDev33 commented 3 years ago

Okay, I deleted my package-lock.json, removed pokemon-showdown and reinstalled, everything seems to be working again. I suspect it might've been something weird with npm update.