Skip to content

A (simple) fight simulator between any two Pokemon using FastAPI with Jinja frontend

Notifications You must be signed in to change notification settings

LAMaglan/PokeFightSimulator

Repository files navigation

Bakground

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

Details of battle simulation

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.

General

Can run with poetry locally, or with docker

Container (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)

Poetry (local)

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

Example images

index.html
index_example

pokemon_details.html
pokemon_stats_example

battle.html
battle_example

types.html
types_example

About

A (simple) fight simulator between any two Pokemon using FastAPI with Jinja frontend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published