mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-19 00:57:21 -05:00
`import =` and `export =` are really only intended for backwards compatibility with CommonJS. While I really don't like the new module system TC39 has designed for us, it's what we should be using, and consistency is important.
55 lines
1.4 KiB
TypeScript
55 lines
1.4 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} from '../battle-stream';
|
|
import {Dex} from '../dex';
|
|
import {RandomPlayerAI} from '../tools/random-player-ai';
|
|
|
|
/*********************************************************************
|
|
* Run AI
|
|
*********************************************************************/
|
|
// tslint:disable:no-floating-promises
|
|
|
|
const streams = getPlayerStreams(new BattleStream());
|
|
|
|
const spec = {
|
|
formatid: "gen7customgame",
|
|
};
|
|
const p1spec = {
|
|
name: "Bot 1",
|
|
team: Dex.packTeam(Dex.generateTeam('gen7randombattle')),
|
|
};
|
|
const p2spec = {
|
|
name: "Bot 2",
|
|
team: Dex.packTeam(Dex.generateTeam('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);
|
|
|
|
p1.start();
|
|
p2.start();
|
|
|
|
(async () => {
|
|
let chunk;
|
|
// tslint:disable-next-line no-conditional-assignment
|
|
while ((chunk = await streams.omniscient.read())) {
|
|
console.log(chunk);
|
|
}
|
|
})();
|
|
|
|
streams.omniscient.write(`>start ${JSON.stringify(spec)}
|
|
>player p1 ${JSON.stringify(p1spec)}
|
|
>player p2 ${JSON.stringify(p2spec)}`);
|