Skip to content

Commit

Permalink
Snake game
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Suarez committed Aug 19, 2024
1 parent b1a59ef commit c4a0e76
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 77 deletions.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/rst/api.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/rst/landing.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/rst/ocean.doctree
Binary file not shown.
Binary file not shown.
10 changes: 9 additions & 1 deletion docs/build/html/_sources/rst/landing.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
You have an environment, a PyTorch model, and a reinforcement learning library that are designed to work together but don't. PufferLib provides one-line wrappers that make them play nice.

.. card::
:link: _static/snake/game.html
:width: 75%
:margin: 4 2 auto auto
:text-align: center

**Play Snake vs RL in your browser!**

.. card::
:link: https://colab.research.google.com/drive/1pK5QQG9-MfVdbUNr2vXr2l6zJBS-au1V?usp=sharing
:width: 75%
Expand Down Expand Up @@ -44,7 +52,7 @@ You have an environment, a PyTorch model, and a reinforcement learning library t

|
Join our community Discord for support and Discussion, follow my Twitter for news, and star the repo to feed the puffer. We also have a :download:`Whitepaper <../_static/neurips_2023_aloe.pdf>` featured at the NeurIPS 2023 ALOE workshop.
Join our community Discord for support and Discussion, follow my Twitter for news, and star the repo to feed the puffer. We also have a `whitepaper <https://arxiv.org/abs/2406.12905>`_.

.. dropdown:: Installation

Expand Down
14 changes: 7 additions & 7 deletions docs/build/html/_sources/rst/ocean.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,55 @@ Make Functions
Squared
*******

.. autoclass:: pufferlib.environments.ocean.ocean.Squared
.. autoclass:: pufferlib.environments.ocean.sanity.Squared
:members:
:undoc-members:
:noindex:

Password (exploration environment)
**********************************

.. autoclass:: pufferlib.environments.ocean.ocean.Password
.. autoclass:: pufferlib.environments.ocean.sanity.Password
:members:
:undoc-members:
:noindex:

Stochastic
**********

.. autoclass:: pufferlib.environments.ocean.ocean.Stochastic
.. autoclass:: pufferlib.environments.ocean.sanity.Stochastic
:members:
:undoc-members:
:noindex:

Memory
******

.. autoclass:: pufferlib.environments.ocean.ocean.Memory
.. autoclass:: pufferlib.environments.ocean.sanity.Memory
:members:
:undoc-members:
:noindex:

Multiagent
**********

.. autoclass:: pufferlib.environments.ocean.ocean.Multiagent
.. autoclass:: pufferlib.environments.ocean.sanity.Multiagent
:members:
:undoc-members:
:noindex:

Spaces
******

.. autoclass:: pufferlib.environments.ocean.ocean.Spaces
.. autoclass:: pufferlib.environments.ocean.sanity.Spaces
:members:
:undoc-members:
:noindex:

Bandit
******

.. autoclass:: pufferlib.environments.ocean.ocean.Bandit
.. autoclass:: pufferlib.environments.ocean.sanity.Bandit
:members:
:undoc-members:
:noindex:
1 change: 1 addition & 0 deletions docs/build/html/_static/snake/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctypehtml><html lang=EN-us><head><meta charset=utf-8><meta content="text/html; charset=utf-8"http-equiv=Content-Type><title>raylib web game</title><meta content="raylib web game"name=title><meta content="New raylib web videogame, developed using raylib videogames library"name=description><meta content="raylib, programming, examples, html5, C, C++, library, learn, games, videogames"name=keywords><meta content="width=device-width"name=viewport><meta content=website property=og:type><meta content="raylib web game"property=og:title><meta content=image/png property=og:image:type><meta content=https://www.raylib.com/common/raylib_logo.png property=og:image><meta content="New raylib web videogame, developed using raylib videogames library"property=og:image:alt><meta content="raylib - example"property=og:site_name><meta content=https://www.raylib.com/games.html property=og:url><meta content="New raylib web videogame, developed using raylib videogames library"property=og:description><meta content=summary_large_image name=twitter:card><meta content=@raysan5 name=twitter:site><meta content="raylib web game"name=twitter:title><meta content=https://www.raylib.com/common/raylib_logo.png name=twitter:image><meta content="New raylib web videogame, developed using raylib videogames library"name=twitter:image:alt><meta content=https://www.raylib.com/games.html name=twitter:url><meta content="New raylib web videogame, developed using raylib videogames library"name=twitter:description><link href=https://www.raylib.com/favicon.ico rel="shortcut icon"><style>body{margin:0;overflow:hidden;background-color:#000}canvas.emscripten{border:0 none;background-color:#000}</style><script src=https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js></script><script>function saveFileFromMEMFSToDisk(e,a){var i,o=FS.readFile(e);i=new Blob([o.buffer],{type:"application/octet-binary"}),saveAs(i,a)}</script></head><body><canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas><p id=output><script>var Module={print:function(){var e=document.getElementById("output");return e&&(e.value=""),function(n){arguments.length>1&&(n=Array.prototype.slice.call(arguments).join(" ")),console.log(n),e&&(e.value+=n+"\n",e.scrollTop=e.scrollHeight)}}(),canvas:document.getElementById("canvas")}</script><script src=game.js async></script></body></html>
1 change: 1 addition & 0 deletions docs/build/html/_static/snake/game.js

Large diffs are not rendered by default.

Binary file added docs/build/html/_static/snake/game.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions docs/build/html/rst/_static/snake/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctypehtml><html lang=EN-us><head><meta charset=utf-8><meta content="text/html; charset=utf-8"http-equiv=Content-Type><title>raylib web game</title><meta content="raylib web game"name=title><meta content="New raylib web videogame, developed using raylib videogames library"name=description><meta content="raylib, programming, examples, html5, C, C++, library, learn, games, videogames"name=keywords><meta content="width=device-width"name=viewport><meta content=website property=og:type><meta content="raylib web game"property=og:title><meta content=image/png property=og:image:type><meta content=https://www.raylib.com/common/raylib_logo.png property=og:image><meta content="New raylib web videogame, developed using raylib videogames library"property=og:image:alt><meta content="raylib - example"property=og:site_name><meta content=https://www.raylib.com/games.html property=og:url><meta content="New raylib web videogame, developed using raylib videogames library"property=og:description><meta content=summary_large_image name=twitter:card><meta content=@raysan5 name=twitter:site><meta content="raylib web game"name=twitter:title><meta content=https://www.raylib.com/common/raylib_logo.png name=twitter:image><meta content="New raylib web videogame, developed using raylib videogames library"name=twitter:image:alt><meta content=https://www.raylib.com/games.html name=twitter:url><meta content="New raylib web videogame, developed using raylib videogames library"name=twitter:description><link href=https://www.raylib.com/favicon.ico rel="shortcut icon"><style>body{margin:0;overflow:hidden;background-color:#000}canvas.emscripten{border:0 none;background-color:#000}</style><script src=https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js></script><script>function saveFileFromMEMFSToDisk(e,a){var i,o=FS.readFile(e);i=new Blob([o.buffer],{type:"application/octet-binary"}),saveAs(i,a)}</script></head><body><canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas><p id=output><script>var Module={print:function(){var e=document.getElementById("output");return e&&(e.value=""),function(n){arguments.length>1&&(n=Array.prototype.slice.call(arguments).join(" ")),console.log(n),e&&(e.value+=n+"\n",e.scrollTop=e.scrollHeight)}}(),canvas:document.getElementById("canvas")}</script><script src=game.js async></script></body></html>
1 change: 1 addition & 0 deletions docs/build/html/rst/_static/snake/game.js

Large diffs are not rendered by default.

Binary file added docs/build/html/rst/_static/snake/game.wasm
Binary file not shown.
41 changes: 0 additions & 41 deletions docs/build/html/rst/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,47 +401,6 @@ <h1>Environments<a class="headerlink" href="#environments" title="Permalink to t
<p>All included environments expose make_env and env_creator functions. make_env is the one that you want most of the time. The other one is used to expose e.g. class interfaces for environments that support them so that you can pass around static references.</p>
<p>Additionally, all environments expose a Policy class with a baseline model. Note that not all environments have <em>custom</em> policies, and the default simply flattens observations before applying a linear layer. Atari, Procgen, Neural MMO, Nethack/Minihack, and Pokemon Red currently have reasonable policies.</p>
<p>The PufferLib Squared environment is used as an example below. Everything is exposed through __init__, so you can call these methods through e.g. pufferlib.environments.ocean.make_env</p>
<dl class="py class">
<dt class="sig sig-object py">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pufferlib.environments.ocean.ocean.</span></span><span class="sig-name descname"><span class="pre">Squared</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">distance_to_target</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_targets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-</span> <span class="pre">1</span></span></em><span class="sig-paren">)</span></dt>
<dd><p>Pufferlib Squared environment</p>
<p>Agent starts at the center of a square grid.
Targets are placed on the perimeter of the grid.
Reward is 1 minus the L-inf distance to the closest target.
This means that reward varies from -1 to 1.
Reward is not given for targets that have already been hit.</p>
<p>Observation space: Box(-1, 1, (grid_size, grid_size)). The map.
Action space: Discrete(8). Which direction to move.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>distance_to_target</strong> – The distance from the center to the closest target.</p></li>
<li><p><strong>num_targets</strong> – The number of targets to randomly generate.</p></li>
</ul>
</dd>
</dl>
<dl class="py attribute">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">MOVES</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[(0,</span> <span class="pre">-1),</span> <span class="pre">(0,</span> <span class="pre">1),</span> <span class="pre">(-1,</span> <span class="pre">0),</span> <span class="pre">(1,</span> <span class="pre">0),</span> <span class="pre">(1,</span> <span class="pre">-1),</span> <span class="pre">(-1,</span> <span class="pre">-1),</span> <span class="pre">(1,</span> <span class="pre">1),</span> <span class="pre">(-1,</span> <span class="pre">1)]</span></em></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">reset</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">step</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">action</span></span></em><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">render</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py">
<span class="sig-prename descclassname"><span class="pre">pufferlib.environments.ocean.torch.</span></span><span class="sig-name descname"><span class="pre">Policy</span></span></dt>
Expand Down
7 changes: 6 additions & 1 deletion docs/build/html/rst/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@
<p>You have an environment, a PyTorch model, and a reinforcement learning library that are designed to work together but don’t. PufferLib provides one-line wrappers that make them play nice.</p>
<div class="sd-card sd-sphinx-override sd-w-75 sd-mt-4 sd-mb-2 sd-ml-auto sd-mr-auto sd-shadow-sm sd-card-hover sd-text-center docutils">
<div class="sd-card-body docutils">
<p class="sd-card-text"><strong>Play Snake vs RL in your browser!</strong></p>
</div>
<a class="sd-stretched-link reference external" href="_static/snake/game.html"></a></div>
<div class="sd-card sd-sphinx-override sd-w-75 sd-mt-4 sd-mb-2 sd-ml-auto sd-mr-auto sd-shadow-sm sd-card-hover sd-text-center docutils">
<div class="sd-card-body docutils">
<p class="sd-card-text"><strong>Click to Demo PufferLib in Colab</strong></p>
</div>
<a class="sd-stretched-link reference external" href="https://colab.research.google.com/drive/1pK5QQG9-MfVdbUNr2vXr2l6zJBS-au1V?usp=sharing"></a></div>
Expand Down Expand Up @@ -328,7 +333,7 @@
</div><div class="line-block">
<div class="line"><br /></div>
</div>
<p>Join our community Discord for support and Discussion, follow my Twitter for news, and star the repo to feed the puffer. We also have a <a class="reference download internal" download="" href="../_downloads/b6289fa6a05068cc61ddac77ec727f3f/neurips_2023_aloe.pdf"><code class="xref download docutils literal notranslate"><span class="pre">Whitepaper</span></code></a> featured at the NeurIPS 2023 ALOE workshop.</p>
<p>Join our community Discord for support and Discussion, follow my Twitter for news, and star the repo to feed the puffer. We also have a <a class="reference external" href="https://arxiv.org/abs/2406.12905">whitepaper</a>.</p>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
Installation<div class="sd-summary-down docutils">
Expand Down
Loading

0 comments on commit c4a0e76

Please sign in to comment.