pokemon-showdown/sim/examples/battle-stream-example.ts
Guangcong Luo 78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

51 lines
1.3 KiB
TypeScript

/**
* Battle Stream Example
* Pokemon Showdown - http://pokemonshowdown.com/
*
* Example of how to create AIs battling against each other.
* Run this using `node build && node .sim-dist/examples/battle-stream-example`.
*
* @license MIT
* @author Guangcong Luo <guangcongluo@gmail.com>
*/
import { BattleStream, getPlayerStreams, Teams } from '..';
import { RandomPlayerAI } from '../tools/random-player-ai';
/*********************************************************************
* Run AI
*********************************************************************/
const streams = getPlayerStreams(new BattleStream());
const spec = {
formatid: "gen7customgame",
};
const p1spec = {
name: "Bot 1",
team: Teams.pack(Teams.generate('gen7randombattle')),
};
const p2spec = {
name: "Bot 2",
team: Teams.pack(Teams.generate('gen7randombattle')),
};
const p1 = new RandomPlayerAI(streams.p1);
const p2 = new RandomPlayerAI(streams.p2);
console.log("p1 is " + p1.constructor.name);
console.log("p2 is " + p2.constructor.name);
void p1.start();
void p2.start();
void (async () => {
for await (const chunk of streams.omniscient) {
console.log(chunk);
}
})();
void streams.omniscient.write(`>start ${JSON.stringify(spec)}
>player p1 ${JSON.stringify(p1spec)}
>player p2 ${JSON.stringify(p2spec)}`);