Pokemon fight simulator using FastAPI.
Details and sprites retrieved from https://pokeapi.co/
Sprites for typesretrieved from https://github.com/msikma/pokesprite
Frontend with HTML/Jinja
Note: a fair amount of help from ChatGPT throughout
Pokemon base stats, and effort values for each stat are extracted from pokeapi.co.
The actual stats used in the battle simulation are calculated based on these data, chosen level and a random "individual value":
see update_stats
method within the Pokemon
class (utils.py) for full details.
In the actual battle simulation (see battle_simlator()
in utils.py) the pokemon with the highest speed becomes the first attacker.
In the case of equal speed, a random pokemon is chosen. After each round, the defender and attacker switch roles, until one of the
pokemon loses (HP reaches 0). During the battle, the cumulative type advantages across types for the
attacker are assessed against all the types that the defender has. The type advantages are data/types.csv
based on here.
Ff an attacker has a type that has no effect on one of the types the defender has, then the calculated damage is 0.
Can run with poetry locally, or with docker
To run with docker, install docker from here
Build the docker image
docker build -t <chosen image name>
Run the docker container
docker run -d -p 8000:80 <name from previous step>
On local PC, will run on http://127.0.0.1:8000 (open in a browser)
See swagger docs in /docs
, e.g.
http://127.0.0.1:8000/docs
To stop the docker container, run
docker stop <name of container, can get from `docker ps`>
Alternatively, can run without the -d
flag
docker run -p 8000:80 <name from previous step>
The docker container will be "removed" when terminal/process is shut (i.e. no need to manually stop).
This latter approach is more useful for logging purposes,
unless logging is written to file (see logging_config.py)
To run with poetry, install poetry from here
activate poetry environment
poetry shell
install dependencies from pyproject.toml
poetry install
start the FastAPI:
uvicorn main:app --reload
On local PC, will run on http://127.0.0.1:8000
See swagger docs in /docs
, e.g.
http://127.0.0.1:8000/docs