Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Pokemon Protocols

pokemon_protocols.livemd

Pokemon Protocols

Mix.install([
  {:kino, github: "livebook-dev/kino", override: true},
  {:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
  {:vega_lite, "~> 0.1.4"},
  {:kino_vega_lite, "~> 0.1.1"},
  {:benchee, "~> 0.1"},
  {:ecto, "~> 3.7"},
  {:math, "~> 0.7.0"},
  {:faker, "~> 0.17.0"},
  {:utils, path: "#{__DIR__}/../utils"},
  {:tested_cell, git: "https://github.com/BrooklinJazz/tested_cell"}
])

Navigation

Return Home Report An Issue

Overview

Pokemon are creatures which have the ability to evolve into more powerful versions of themselves.

For example, Charmander evolves into Charmeleon, and Charmeleon evolves into Charizard.

flowchart LR
  c1[Charmander]
  c2[Charmeleon]
  c3[Charizard]
  c1 --> c2 --> c3

In this exercise, you will create an Evolvable protocol which returns the evolved version of a Pokemon.

Evolvable.evolve(%Charmander{})
%Charmeleon{hp: 58, attack: 64: defense: 58}

Pokemon Structs

In the Elixir cell below, Using the stats from Pokemon DB, you’re going to create a struct that represents each of the following Pokemon.

Each struct should include the following.

  • :hp
  • :attack
  • :defense

You can use the base values as defaults from Pokemon DB as shown in the following diagram.

classDiagram
  class Charmander {
    hp: 39
    attack: 52
    defense: 43
  }

  class Charmeleon {
    hp: 58
    attack: 64
    defense: 58
  }

  class Charizard {
    hp: 78
    attack: 84
    defense: 78
  }
defmodule Charmander do
end

defmodule Charmeleon do
end

defmodule Charizard do
end

Utils.feedback(:pokemon_evolution_structs, [Charmander, Charmeleon, Charizard])

Evolvable Protocol

In the Elixir cell below, create an Evolvable protocol with an evolve/1 function.

A Charmander struct should return a new Charmeleon struct.

Evolvable.evolve(%Charmander{})
%Charmeleon{hp: 58, attack: 64: defense: 58}

A Charmeleon struct should return a new Charizard struct.

Evolvable.evolve(%Charmeleon{})
%Charizard{hp: 78, attack: 84: defense: 78}
defprotocol Evolvable do
end

Utils.feedback(:evolvable, [Evolvable, Charmander, Charmeleon, Charizard])

Commit Your Progress

Run the following in your command line from the project folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish pokemon protocols exercise"