Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Baekalfen committed Oct 19, 2023
1 parent 9d13804 commit 0b2c632
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 39 deletions.
11 changes: 3 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="pyboy.PyBoy"><code class="flex name class">
<span>class <span class="ident">PyBoy</span></span>
<span>(</span><span>gamerom_file, *, bootrom_file=None, profiling=False, disable_renderer=False, sound=False, cgb=None, randomize=False, **kwargs)</span>
<span>(</span><span>gamerom_file, *, bootrom_file=None, disable_renderer=False, sound=False, sound_emulated=False, cgb=None, randomize=False, **kwargs)</span>
</code></dt>
<dd>
<section class="desc"><p>PyBoy is loadable as an object in Python. This means, it can be initialized from another script, and be
Expand All @@ -87,7 +87,6 @@ <h2 id="args">Args</h2>
</dl>
<h2 id="kwargs">Kwargs</h2>
<p>bootrom_file (str): Filepath to a boot-ROM to use. If unsure, specify <code>None</code>.
profiling (bool): Profile the emulator and report opcode usage (internal use).
disable_renderer (bool): Can be used to optimize performance, by internally disable rendering of the screen.
color_palette (tuple): Specify the color palette to use for rendering.</p>
<p>Other keyword arguments may exist for plugins that are not listed here. They can be viewed with the
Expand All @@ -102,9 +101,9 @@ <h2 id="kwargs">Kwargs</h2>
gamerom_file,
*,
bootrom_file=None,
profiling=False,
disable_renderer=False,
sound=False,
sound_emulated=False,
cgb=None,
randomize=False,
**kwargs
Expand All @@ -128,7 +127,6 @@ <h2 id="kwargs">Kwargs</h2>

Kwargs:
bootrom_file (str): Filepath to a boot-ROM to use. If unsure, specify `None`.
profiling (bool): Profile the emulator and report opcode usage (internal use).
disable_renderer (bool): Can be used to optimize performance, by internally disable rendering of the screen.
color_palette (tuple): Specify the color palette to use for rendering.

Expand All @@ -152,9 +150,9 @@ <h2 id="kwargs">Kwargs</h2>
kwargs[&#34;color_palette&#34;],
disable_renderer,
sound,
sound_emulated,
cgb,
randomize=randomize,
profiling=profiling,
)

# Performance measures
Expand Down Expand Up @@ -313,9 +311,6 @@ <h2 id="kwargs">Kwargs</h2>
self.mb.stop(save)
self.stopped = True

def _cpu_hitrate(self):
return self.mb.cpu.hitrate

###################################################################
# Scripts and bot methods
#
Expand Down
80 changes: 57 additions & 23 deletions docs/plugins/base_plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ <h1 class="title">Module <code>pyboy.plugins.base_plugin</code></h1>
def __init__(self, *args, game_area_section=(0, 0, 32, 32), game_area_wrap_around=False, **kwargs):
super().__init__(*args, **kwargs)
self.tilemap_background = self.pyboy.botsupport_manager().tilemap_background()
self.tilemap_window = self.pyboy.botsupport_manager().tilemap_window()
self.tilemap_use_background = True
self.sprite_offset = 0
self.game_has_started = False
self._tile_cache_invalid = True
self._sprite_cache_invalid = True
Expand Down Expand Up @@ -194,12 +197,6 @@ <h1 class="title">Module <code>pyboy.plugins.base_plugin</code></h1>
&#34;&#34;&#34;
raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

def game_over(self):
&#34;&#34;&#34;
After calling `start_game`, you can call this method at any time to know if the game is over.
&#34;&#34;&#34;
raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

def _sprites_on_screen(self):
if self._sprite_cache_invalid:
self._cached_sprites_on_screen = []
Expand All @@ -226,14 +223,25 @@ <h1 class="title">Module <code>pyboy.plugins.base_plugin</code></h1>
for x in range(width):
_x = (xx+x+SCX) % 32
_y = (yy+y+SCY) % 32
self._cached_game_area_tiles[y][x] = self.tilemap_background.tile_identifier(_x, _y)
if self.tilemap_use_background:
self._cached_game_area_tiles[y][x] = self.tilemap_background.tile_identifier(_x, _y)
else:
self._cached_game_area_tiles[y][x] = self.tilemap_window.tile_identifier(_x, _y)
else:
self._cached_game_area_tiles = np.asarray(
self.tilemap_background[xx:xx + width, yy:yy + height], dtype=np.uint32
)
if self.tilemap_use_background:
self._cached_game_area_tiles = np.asarray(
self.tilemap_background[xx:xx + width, yy:yy + height], dtype=np.uint32
)
else:
self._cached_game_area_tiles = np.asarray(
self.tilemap_window[xx:xx + width, yy:yy + height], dtype=np.uint32
)
self._tile_cache_invalid = False
return self._cached_game_area_tiles

def use_background(self, value):
self.tilemap_use_background = value

def game_area(self):
&#34;&#34;&#34;
This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.
Expand All @@ -253,7 +261,8 @@ <h1 class="title">Module <code>pyboy.plugins.base_plugin</code></h1>
_x = (s.x // 8) - xx
_y = (s.y // 8) - yy
if 0 &lt;= _y &lt; height and 0 &lt;= _x &lt; width:
tiles_matrix[_y][_x] = s.tile_identifier
tiles_matrix[_y][
_x] = s.tile_identifier + self.sprite_offset # Adding offset to try to seperate sprites from tiles
return tiles_matrix

def _game_area_np(self, observation_type=&#34;tiles&#34;):
Expand Down Expand Up @@ -315,6 +324,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
def __init__(self, *args, game_area_section=(0, 0, 32, 32), game_area_wrap_around=False, **kwargs):
super().__init__(*args, **kwargs)
self.tilemap_background = self.pyboy.botsupport_manager().tilemap_background()
self.tilemap_window = self.pyboy.botsupport_manager().tilemap_window()
self.tilemap_use_background = True
self.sprite_offset = 0
self.game_has_started = False
self._tile_cache_invalid = True
self._sprite_cache_invalid = True
Expand Down Expand Up @@ -383,12 +395,6 @@ <h2 class="section-title" id="header-classes">Classes</h2>
&#34;&#34;&#34;
raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

def game_over(self):
&#34;&#34;&#34;
After calling `start_game`, you can call this method at any time to know if the game is over.
&#34;&#34;&#34;
raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

def _sprites_on_screen(self):
if self._sprite_cache_invalid:
self._cached_sprites_on_screen = []
Expand All @@ -415,14 +421,25 @@ <h2 class="section-title" id="header-classes">Classes</h2>
for x in range(width):
_x = (xx+x+SCX) % 32
_y = (yy+y+SCY) % 32
self._cached_game_area_tiles[y][x] = self.tilemap_background.tile_identifier(_x, _y)
if self.tilemap_use_background:
self._cached_game_area_tiles[y][x] = self.tilemap_background.tile_identifier(_x, _y)
else:
self._cached_game_area_tiles[y][x] = self.tilemap_window.tile_identifier(_x, _y)
else:
self._cached_game_area_tiles = np.asarray(
self.tilemap_background[xx:xx + width, yy:yy + height], dtype=np.uint32
)
if self.tilemap_use_background:
self._cached_game_area_tiles = np.asarray(
self.tilemap_background[xx:xx + width, yy:yy + height], dtype=np.uint32
)
else:
self._cached_game_area_tiles = np.asarray(
self.tilemap_window[xx:xx + width, yy:yy + height], dtype=np.uint32
)
self._tile_cache_invalid = False
return self._cached_game_area_tiles

def use_background(self, value):
self.tilemap_use_background = value

def game_area(self):
&#34;&#34;&#34;
This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.
Expand All @@ -442,7 +459,8 @@ <h2 class="section-title" id="header-classes">Classes</h2>
_x = (s.x // 8) - xx
_y = (s.y // 8) - yy
if 0 &lt;= _y &lt; height and 0 &lt;= _x &lt; width:
tiles_matrix[_y][_x] = s.tile_identifier
tiles_matrix[_y][
_x] = s.tile_identifier + self.sprite_offset # Adding offset to try to seperate sprites from tiles
return tiles_matrix

def _game_area_np(self, observation_type=&#34;tiles&#34;):
Expand Down Expand Up @@ -479,6 +497,7 @@ <h3>Ancestors</h3>
<h3>Subclasses</h3>
<ul class="hlist">
<li><a title="pyboy.plugins.game_wrapper_kirby_dream_land.GameWrapperKirbyDreamLand" href="game_wrapper_kirby_dream_land.html#pyboy.plugins.game_wrapper_kirby_dream_land.GameWrapperKirbyDreamLand">GameWrapperKirbyDreamLand</a></li>
<li><a title="pyboy.plugins.game_wrapper_pokemon_gen1.GameWrapperPokemonGen1" href="game_wrapper_pokemon_gen1.html#pyboy.plugins.game_wrapper_pokemon_gen1.GameWrapperPokemonGen1">GameWrapperPokemonGen1</a></li>
<li><a title="pyboy.plugins.game_wrapper_super_mario_land.GameWrapperSuperMarioLand" href="game_wrapper_super_mario_land.html#pyboy.plugins.game_wrapper_super_mario_land.GameWrapperSuperMarioLand">GameWrapperSuperMarioLand</a></li>
<li><a title="pyboy.plugins.game_wrapper_tetris.GameWrapperTetris" href="game_wrapper_tetris.html#pyboy.plugins.game_wrapper_tetris.GameWrapperTetris">GameWrapperTetris</a></li>
</ul>
Expand Down Expand Up @@ -566,6 +585,19 @@ <h2 id="args">Args</h2>
raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background"><code class="name flex">
<span>def <span class="ident">use_background</span></span>(<span>self, value)</span>
</code></dt>
<dd>
<section class="desc"></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def use_background(self, value):
self.tilemap_use_background = value</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area"><code class="name flex">
<span>def <span class="ident">game_area</span></span>(<span>self)</span>
</code></dt>
Expand Down Expand Up @@ -599,7 +631,8 @@ <h2 id="returns">Returns</h2>
_x = (s.x // 8) - xx
_y = (s.y // 8) - yy
if 0 &lt;= _y &lt; height and 0 &lt;= _x &lt; width:
tiles_matrix[_y][_x] = s.tile_identifier
tiles_matrix[_y][
_x] = s.tile_identifier + self.sprite_offset # Adding offset to try to seperate sprites from tiles
return tiles_matrix</code></pre>
</details>
</dd>
Expand Down Expand Up @@ -627,6 +660,7 @@ <h4><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper" href="#pyboy.plu
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.start_game" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.start_game">start_game</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.reset_game" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.reset_game">reset_game</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_over" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.game_over">game_over</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background">use_background</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area">game_area</a></code></li>
</ul>
</li>
Expand Down
Loading

0 comments on commit 0b2c632

Please sign in to comment.