ineedpoopoo / pokemonshowdown-ai

Reinforcement learning for Pokemon.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pokemon Showdown AI

Build codecov

For this project I plan on making and training a neural network to play in a Pokemon gen-4 random battle. The code is pretty unstable right now so I wouldn't recommend trying to use it out of the box.

This project has three parts:

  • PsBot framework for creating a general Pokemon Showdown bot and setting up the battle interface.
  • Battle state tracker and PS protocol parser.
  • Neural network management and training scripts.
2022-08-14_demo.mp4

Me (left) vs a model (right) that was trained over ~16k games against itself

Build Instructions

# Download the repository.
git clone https://github.com/taylorhansen/pokemonshowdown-ai
cd pokemonshowdown-ai
npm install

# Setup config, edit as desired.
cp src/config/config.example.ts src/config/config.ts

# Compile the project.
npm run build

Testing

# Run formatter.
npm run format

# Run linter.
npm run lint

# Run tests with coverage.
npm test

Training

npm run train

Trains the neural network through self-play. This requires a powerful computer, and may take several hours depending on how it's configured.

The training script saves logs to ./logs/ and checkpoints to ./models/ (can be changed by config).

Some metrics such as loss, gradients, evaluation scores, etc. can be viewed using TensorBoard.

pip install tensorboard
tensorboard --logdir metrics

Comparing trained models

npm run compare

Based on the config, runs several games between each of the models that were created by differently-configured training runs (via npm run train), round-robin style, in order to determine which model performs the best against the others. Includes support for a baseline randomly-acting model and fixed random seeds.

Running

npm run psbot

Connects to the PS server specified in the config and starts accepting battle challenges in the gen4randombattle format, which is the format that this project is using for now. By default it loads the model from the last completed training run in ./models/train. This allows the model to take on human challengers or any other outside bots.

License

See LICENSE.

About

Reinforcement learning for Pokemon.

License:MIT License


Languages

Language:TypeScript 100.0%Language:Shell 0.0%Language:JavaScript 0.0%