diff --git a/flake.nix b/flake.nix
index d873aac..1034495 100644
--- a/flake.nix
+++ b/flake.nix
@@ -17,7 +17,7 @@
devShells = forEachSupportedSystem ({pkgs}: {
default = pkgs.mkShell {
packages = with pkgs;
- [python311 virtualenv]
+ [python311 virtualenv julia]
++ (with pkgs.python311Packages; [pip requests jupyter pandas numpy matplotlib plotnine polars pyarrow]);
};
});
diff --git a/julia.ipynb b/julia.ipynb
new file mode 100644
index 0000000..2561788
--- /dev/null
+++ b/julia.ipynb
@@ -0,0 +1,53 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Julia Version 1.10.0\n",
+ "Commit 3120989f39 (2023-12-25 18:01 UTC)\n",
+ "Build Info:\n",
+ "\n",
+ " Note: This is an unofficial build, please report bugs to the project\n",
+ " responsible for this build and not to the Julia project unless you can\n",
+ " reproduce the issue using official builds available at https://julialang.org/downloads\n",
+ "\n",
+ "Platform Info:\n",
+ " OS: Linux (x86_64-unknown-linux-gnu)\n",
+ " CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz\n",
+ " WORD_SIZE: 64\n",
+ " LIBM: libopenlibm\n",
+ " LLVM: libLLVM-15.0.7 (ORCJIT, skylake)\n",
+ " Threads: 1 on 8 virtual cores\n",
+ "Environment:\n",
+ " LD_LIBRARY_PATH = /nix/store/ccbxkk7cdnfgsl6mgfdlikni4mxwandj-pipewire-1.0.3-jack/lib\n",
+ " JULIA_NUM_THREADS = \n"
+ ]
+ }
+ ],
+ "source": [
+ "versioninfo()"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Julia 1.10.0",
+ "language": "julia",
+ "name": "julia-1.10"
+ },
+ "language_info": {
+ "file_extension": ".jl",
+ "mimetype": "application/julia",
+ "name": "julia",
+ "version": "1.10.0"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/pokémon.ipynb b/pokémon.ipynb
index e17fab5..49977a5 100644
--- a/pokémon.ipynb
+++ b/pokémon.ipynb
@@ -239,7 +239,7 @@
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -268,7 +268,7 @@
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -294,6 +294,174 @@
" + labs(title=\"Amount of fairy Pokémon in each generation\", y=\"Amount of Pokémon\")\n",
")"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "types = pokémon.select([\"Type 1\"]).unique().to_series().to_list()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "
shape: (18, 19) | Normal | Fire | Water | Electric | Grass | Ice | Fighting | Poison | Ground | Flying | Psychic | Bug | Rock | Ghost | Dragon | Dark | Steel | Fairy |
---|
str | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 |
"Normal" | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 0.5 | 0.0 | 1.0 | 1.0 | 0.5 | 1.0 |
"Fire" | 1.0 | 0.5 | 0.5 | 1.0 | 2.0 | 2.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 0.5 | 1.0 | 0.5 | 1.0 | 2.0 | 1.0 |
"Water" | 1.0 | 2.0 | 0.5 | 1.0 | 0.5 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 0.5 | 1.0 | 1.0 | 1.0 |
"Electric" | 1.0 | 1.0 | 2.0 | 0.5 | 0.5 | 1.0 | 1.0 | 1.0 | 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 0.5 | 1.0 | 0.5 | 2.0 | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 | 1.0 | 0.5 | 1.0 |
"Ghost" | 0.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 1.0 | 2.0 | 1.0 | 0.5 | 1.0 | 1.0 |
"Dragon" | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 0.5 | 0.0 |
"Dark" | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 0.5 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 1.0 | 2.0 | 1.0 | 0.5 | 1.0 | 0.5 |
"Steel" | 1.0 | 0.5 | 0.5 | 0.5 | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 | 0.5 | 2.0 |
"Fairy" | 1.0 | 0.5 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 0.5 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 2.0 | 2.0 | 0.5 | 1.0 |
"
+ ],
+ "text/plain": [
+ "shape: (18, 19)\n",
+ "┌──────────┬────────┬──────┬───────┬───┬────────┬──────┬───────┬───────┐\n",
+ "│ ┆ Normal ┆ Fire ┆ Water ┆ … ┆ Dragon ┆ Dark ┆ Steel ┆ Fairy │\n",
+ "│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │\n",
+ "│ str ┆ f64 ┆ f64 ┆ f64 ┆ ┆ f64 ┆ f64 ┆ f64 ┆ f64 │\n",
+ "╞══════════╪════════╪══════╪═══════╪═══╪════════╪══════╪═══════╪═══════╡\n",
+ "│ Normal ┆ 1.0 ┆ 1.0 ┆ 1.0 ┆ … ┆ 1.0 ┆ 1.0 ┆ 0.5 ┆ 1.0 │\n",
+ "│ Fire ┆ 1.0 ┆ 0.5 ┆ 0.5 ┆ … ┆ 0.5 ┆ 1.0 ┆ 2.0 ┆ 1.0 │\n",
+ "│ Water ┆ 1.0 ┆ 2.0 ┆ 0.5 ┆ … ┆ 0.5 ┆ 1.0 ┆ 1.0 ┆ 1.0 │\n",
+ "│ Electric ┆ 1.0 ┆ 1.0 ┆ 2.0 ┆ … ┆ 0.5 ┆ 1.0 ┆ 1.0 ┆ 1.0 │\n",
+ "│ Grass ┆ 1.0 ┆ 0.5 ┆ 2.0 ┆ … ┆ 0.5 ┆ 1.0 ┆ 0.5 ┆ 1.0 │\n",
+ "│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │\n",
+ "│ Ghost ┆ 0.0 ┆ 1.0 ┆ 1.0 ┆ … ┆ 1.0 ┆ 0.5 ┆ 1.0 ┆ 1.0 │\n",
+ "│ Dragon ┆ 1.0 ┆ 1.0 ┆ 1.0 ┆ … ┆ 2.0 ┆ 1.0 ┆ 0.5 ┆ 0.0 │\n",
+ "│ Dark ┆ 1.0 ┆ 1.0 ┆ 1.0 ┆ … ┆ 1.0 ┆ 0.5 ┆ 1.0 ┆ 0.5 │\n",
+ "│ Steel ┆ 1.0 ┆ 0.5 ┆ 0.5 ┆ … ┆ 1.0 ┆ 1.0 ┆ 0.5 ┆ 2.0 │\n",
+ "│ Fairy ┆ 1.0 ┆ 0.5 ┆ 1.0 ┆ … ┆ 2.0 ┆ 2.0 ┆ 0.5 ┆ 1.0 │\n",
+ "└──────────┴────────┴──────┴───────┴───┴────────┴──────┴───────┴───────┘"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "pokétype = ps.read_csv(\"./pokémon/Pokemon Type Chart.csv\")\n",
+ "pokétype"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 255,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from dataclasses import dataclass\n",
+ "from enum import Enum\n",
+ "from typing import TypeVar\n",
+ "import random\n",
+ "\n",
+ "TPokémon = TypeVar(\"TPokémon\", bound=\"Pokémon\")\n",
+ "\n",
+ "pokémon_list: list = []\n",
+ "\n",
+ "class Effective(Enum):\n",
+ " \"\"\"\n",
+ " Enum Description: \n",
+ " \"\"\"\n",
+ " SUPER = \"It's super effective!\"\n",
+ " NORMAL = \"\"\n",
+ " NOTVERY = \"It's not very effective...\"\n",
+ " NOT = \"But it has no effect!\"\n",
+ "\n",
+ "\n",
+ "@dataclass\n",
+ "class Pokémon:\n",
+ " name: str\n",
+ " types: list\n",
+ " hp: int\n",
+ " curr_hp: int\n",
+ " attack: int\n",
+ " defense: int\n",
+ " sp_atk: int\n",
+ " sp_def: int\n",
+ "\n",
+ " def attack_opponent(self, opponent: TPokémon, typeatk: str, atkpwr: int):\n",
+ " if opponent.curr_hp == 0:\n",
+ " print(\"You cannot attack a fainted Pokémon!\")\n",
+ " return\n",
+ "\n",
+ " type_modifier = pokétype.filter(pokétype[\"\"].str.contains(typeatk))[opponent.types[0]][0]\n",
+ " if (opponent.types[1] is not None):\n",
+ " type_modifier *= pokétype.filter(pokétype[\"\"].str.contains(typeatk))[opponent.types[1]][0]\n",
+ " \n",
+ " damage = self.attack * type_modifier * (atkpwr / 100)\n",
+ " \n",
+ "\n",
+ " if(typeatk in self.types):\n",
+ " damage = damage * 1.5\n",
+ " opponent.curr_hp = opponent.curr_hp - damage\n",
+ " print(f\"\"\"{self.name} attacks {opponent.name} for {int(damage)} damage!\\n\n",
+ "{Effective.SUPER.value if type_modifier > 1.0 else Effective.NORMAL.value}\n",
+ "{Effective.NOTVERY.value if ((type_modifier < 1.0) and (type_modifier > 0.0)) else Effective.NORMAL.value}\n",
+ "{Effective.NOT.value if type_modifier == 0.0 else Effective.NORMAL.value}\"\"\")\n",
+ "\n",
+ " if (opponent.curr_hp <= 0):\n",
+ " opponent.curr_hp = 0\n",
+ " print(f\"{opponent.name} fainted!\")\n",
+ " return\n",
+ " print(f\"It now has {int(opponent.curr_hp)} HP\")\n",
+ "\n",
+ " def heal(self):\n",
+ " self.curr_hp = self.hp\n",
+ "\n",
+ "for row in pokémon.rows(named=True):\n",
+ " pokémon_list.append(Pokémon(\n",
+ " name = row[\"Name\"],\n",
+ " types = [row[\"Type 1\"], row[\"Type 2\"]],\n",
+ " hp = row[\"HP\"],\n",
+ " curr_hp = row[\"HP\"],\n",
+ " attack = row[\"Attack\"],\n",
+ " defense = row[\"Defense\"],\n",
+ " sp_atk = row[\"Sp. Atk\"],\n",
+ " sp_def = row[\"Sp. Def\"],\n",
+ " ))\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 256,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Bulbasaur attacks Butterfree for 16 damage!\n",
+ "\n",
+ "\n",
+ "It's not very effective...\n",
+ "\n",
+ "It now has 167 HP\n"
+ ]
+ }
+ ],
+ "source": [
+ "pokémon_list[0].attack_opponent(pokémon_list[15], \"Grass\", 40)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 201,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for poke in pokémon_list:\n",
+ " poke.heal()"
+ ]
}
],
"metadata": {
diff --git a/pokémon/Pokemon Type Chart.csv b/pokémon/Pokemon Type Chart.csv
new file mode 100644
index 0000000..07e70a8
--- /dev/null
+++ b/pokémon/Pokemon Type Chart.csv
@@ -0,0 +1,19 @@
+,Normal,Fire,Water,Electric,Grass,Ice,Fighting,Poison,Ground,Flying,Psychic,Bug,Rock,Ghost,Dragon,Dark,Steel,Fairy
+Normal,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.5,0.0,1.0,1.0,0.5,1.0
+Fire,1.0,0.5,0.5,1.0,2.0,2.0,1.0,1.0,1.0,1.0,1.0,2.0,0.5,1.0,0.5,1.0,2.0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