Skip to content

Commit

Permalink
updaeting doc images
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Jan 30, 2021
1 parent 43926f7 commit 0ba9e6d
Show file tree
Hide file tree
Showing 23 changed files with 23 additions and 17 deletions.
Binary file modified docs/games/GriddlyRTS/img/GriddlyRTS-level-Block2D-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/GriddlyRTS/img/GriddlyRTS-level-Block2D-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/GriddlyRTS/img/GriddlyRTS-tile-harvester-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/GriddlyRTS/img/GriddlyRTS-tile-puncher-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/GriddlyRTS/img/GriddlyRTS-tile-pusher-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Heal_Or_Die/img/Heal_Or_Die-tile-healer-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Heal_Or_Die/img/Heal_Or_Die-tile-warrior-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Kill_The_King/img/Kill_The_King-level-Sprite2D-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Push_Mania/img/Push_Mania-level-Sprite2D-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Push_Mania/img/Push_Mania-level-Sprite2D-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Push_Mania/img/Push_Mania-tile-hole-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/games/Push_Mania/img/Push_Mania-tile-pusher-Sprite2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions python/docs/sphinxdocs/game_docs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import logging
import os
import textwrap
Expand Down Expand Up @@ -142,7 +143,6 @@ def _generate_code_example(self, game_breakdown):
env.render(observer='global') # Renders the entire environment
"""


code_example_sphinx += 'The most basic way to create a Griddly Gym Environment. ' \
'Defaults to level 0 and SPRITE_2D rendering.\n\n'
code_example_sphinx += f'.. code-block:: python\n\n{textwrap.indent(basic_code_example, " ")}\n\n'
Expand Down Expand Up @@ -343,7 +343,7 @@ def generate(self):
# Save the doc images
for doc_image_filename, np_doc_image in doc_images.items():
self._logger.debug(f'Writing image {doc_image_filename}')
renderer.render(np_doc_image, doc_sphinx_root.joinpath(doc_image_filename))
renderer.render(np_doc_image.swapaxes(0, 2), doc_sphinx_root.joinpath(doc_image_filename))

relative_doc_path = game_doc_root.joinpath('index.rst')

Expand All @@ -366,7 +366,7 @@ def generate(self):
sphinx_string += f' - {taster_sphinx}'
# Save the taster images
for taster_image_filename, np_taster_image in taster_images.items():
renderer.render(np_taster_image, self._docs_root.joinpath(taster_image_filename))
renderer.render(np_taster_image.swapaxes(0, 2), self._docs_root.joinpath(taster_image_filename))

remaining_cols = 2 - col_index

Expand All @@ -378,7 +378,14 @@ def generate(self):
with open(self._docs_root.joinpath('index.rst'), 'w') as f:
f.write(sphinx_string)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Automatically generate documentation for games.')
parser.add_argument('--filename-suffix', default='.yaml', help='Suffix for filenames to create documentation')

args = parser.parse_args()

filename_suffix = args.filename_suffix
games_path = Path('../../../resources/games')

docs_root = Path('../../../docs/games')
Expand All @@ -392,7 +399,7 @@ def generate(self):
print(f'Directories: {gdy_subdirectory}')

for filename in filenames:
if filename.endswith('.yaml'):
if filename.endswith(filename_suffix):
category = gdy_subdirectory.parts[0]
gdy_file = directory_path.joinpath(filename).resolve()
relative_gdy_path = gdy_file.relative_to(games_path.resolve())
Expand Down
Binary file modified python/examples/griddlyrts/griddly_rts_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/griddlyrts/griddly_rts_p1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/griddlyrts/griddly_rts_p2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 10 additions & 12 deletions python/examples/griddlyrts/play_griddlyrts_gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

from griddly import GymWrapperFactory, gd
from griddly.RenderTools import VideoRecorder, RenderToFile
from griddly.util.wrappers import InvalidMaskingRTSWrapper
from griddly.util.wrappers import ValidActionSpaceWrapper

if __name__ == '__main__':
wrapper = GymWrapperFactory()

wrapper.build_gym_from_yaml("GriddlyRTS-Adv",
'RTS/GriddlyRTS.yaml',
global_observer_type=gd.ObserverType.SPRITE_2D,
player_observer_type=gd.ObserverType.SPRITE_2D,
global_observer_type=gd.ObserverType.VECTOR,
player_observer_type=gd.ObserverType.VECTOR,
level=0)

env_original = gym.make(f'GDY-GriddlyRTS-Adv-v0')
# env_original = gym.make(f'GDY-GriddlyRTS-Adv-v0')

env_original.reset()

env = InvalidMaskingRTSWrapper(env_original)
env = ValidActionSpaceWrapper(env_original)

start = timer()

Expand Down Expand Up @@ -63,17 +63,15 @@

action_masks = env.get_unit_action_mask([6, 3], ['gather', 'move'], padded=False)

env.render(observer='global')
env.render(observer=0)
env.render(observer=1)
global_obs = env.render(observer='global')
p1_obs = env.render(observer=0)
p2_obs = env.render(observer=1)

obs, reward, done, info = env.step(action)

global_observation = env.render(mode='rgb_array', observer='global')

global_recorder.add_frame(global_observation)
player1_recorder.add_frame(obs[0].swapaxes(0, 2))
player2_recorder.add_frame(obs[1].swapaxes(0, 2))
global_recorder.add_frame(global_obs)
player1_recorder.add_frame(p1_obs)
player2_recorder.add_frame(p2_obs)

if done:
state = env.get_state()
Expand Down
3 changes: 2 additions & 1 deletion python/griddly/util/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __exit__(self, type, value, traceback):

def render_rgb(self):

observation = np.array(self.game.observe(), copy=False)
# Set copy to true here because we want to use these later after environment resets
observation = np.array(self.game.observe(), copy=True)

if self.observer_type == gd.ObserverType.VECTOR:
self._vector2rgb = Vector2RGB(10, observation.shape[0])
Expand Down

0 comments on commit 0ba9e6d

Please sign in to comment.