<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hsahovic</title>
    <description>The latest articles on DEV Community by hsahovic (@hsahovic).</description>
    <link>https://dev.to/hsahovic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F389906%2F0937fea9-6f4e-4554-a4d7-fd8b72db5409.jpeg</url>
      <title>DEV Community: hsahovic</title>
      <link>https://dev.to/hsahovic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hsahovic"/>
    <language>en</language>
    <item>
      <title>poke-env, a python library for Pokemon Reinforcement Learning</title>
      <dc:creator>hsahovic</dc:creator>
      <pubDate>Wed, 20 May 2020 05:52:14 +0000</pubDate>
      <link>https://dev.to/hsahovic/poke-env-a-python-library-for-pokemon-reinforcement-learning-4ff8</link>
      <guid>https://dev.to/hsahovic/poke-env-a-python-library-for-pokemon-reinforcement-learning-4ff8</guid>
      <description>&lt;p&gt;In Spring 2019, I worked on a &lt;a href="https://github.com/hsahovic/reinforcement-learning-pokemon-bot"&gt;Reinforcement Learning university project&lt;/a&gt; centered around creating Pokemon battling bots for &lt;a href="https://play.pokemonshowdown.com/"&gt;Pokemon Showdown&lt;/a&gt;, a popular and open-source simulator. Reinforcement Learning (RL) is a branch of AI whose goal is to design &lt;em&gt;agents&lt;/em&gt; interacting in an &lt;em&gt;environment&lt;/em&gt;, with the goal of maximizing a given &lt;em&gt;reward&lt;/em&gt;. Games are a natural fit for RL, and creating the very best Pokemon agent sounded like a fun challenge.&lt;/p&gt;

&lt;p&gt;Surprisingly, the hardest part of this project was not related to reinforcement learning. In the end, the RL-related code we wrote only made up a small fraction of our project.&lt;/p&gt;

&lt;p&gt;The real difficulty lied in implementing everything else, which ranged from communicating with the simulation server via Websockets, parsing and formatting simulation protocol message and keeping track of the states of the battles the agents were playing.&lt;/p&gt;

&lt;p&gt;By the end of the project, I was tempted to continue working on it, and maybe open-source it. At the same time, I realized that we were not alone in wanting to create Pokemon battling bots: &lt;a href="https://github.com/search?q=pokemon+showdown+bot"&gt;they were dozens of somewhat similar projects&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This observation led to an idea: what if instead of open-sourcing agents, I focused on the environment? And so, in August 2019, &lt;code&gt;poke-env&lt;/code&gt;was born. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;poke-env&lt;/code&gt; is a python package that takes care of everything you need to create agents, and lets you focus on actually creating battling bots. Today, it offers a simple API, &lt;a href="https://poke-env.readthedocs.io/en/stable/"&gt;comprehensive documentation and examples&lt;/a&gt;, and many cool features such as a built-in &lt;a href="https://gym.openai.com/"&gt;Open AI Gym&lt;/a&gt; API.&lt;/p&gt;

&lt;p&gt;What does it look like? Well, creating an agent can be as simple as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;YourFirstAgent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;choose_move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;battle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;move&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;battle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;available_moves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base_power&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# A powerful move! Let's use it
&lt;/span&gt;                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# No available move? Let's switch then!
&lt;/span&gt;        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;switch&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;battle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;available_switches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current_hp_fraction&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;battle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_pokemon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current_hp_fraction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# This other pokemon has more HP left... Let's switch it in?
&lt;/span&gt;                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Not sure what to do?
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choose_random_move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;battle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The project is now being used by a growing number of researchers, students and AI Pokemon enthusiasts around the world. It gave birth to &lt;a href="https://github.com/dem1995/pokemon-evolutionary-agents"&gt;multiple projects&lt;/a&gt; and continues to expand.&lt;/p&gt;

&lt;p&gt;Interested in trying it out? Getting started is a simple &lt;code&gt;pip install poke-env&lt;/code&gt; away :)&lt;/p&gt;

&lt;p&gt;We have &lt;a href="https://poke-env.readthedocs.io/en/stable/"&gt;all the documentation&lt;/a&gt; and &lt;a href="https://poke-env.readthedocs.io/en/stable/examples.html"&gt;examples&lt;/a&gt; you might need to get rolling. You can also check out the &lt;a href="https://github.com/hsahovic/poke-env"&gt;project's repo&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>python</category>
      <category>machinelearning</category>
      <category>opensource</category>
      <category>octograd2020</category>
    </item>
  </channel>
</rss>
