import unittest import numpy as np from pixelworld.envs.pixelworld import agents, events, universe, library from pixelworld.envs.pixelworld.tests import test_core from pixelworld.envs.pixelworld.tests.library.world import test_library_world snake = library.import_item('world', 'snake') class TestSnake(test_library_world.TestLibraryWorld): world = None def __init__(self, *args, **kwargs): super(TestSnake, self).__init__(*args, **kwargs) self.world = kwargs.pop('world', 'snake') def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def _test_solver(self): self.world = universe.create_world('snake', width=12, height=12) done = False head = self.world.objects['head'] self.world.render()
import numpy as np from pixelworld.envs.pixelworld import core, library, objects, object_attributes, randomizers pixelpack = library.import_item('world', 'pixelpack') from pixelpack import Packed, Product, height, width, shelves, products, \ worker, goals, judge, randomizer class Progress(core.FloatObjectAttribute, core.DerivedObjectAttribute, core.SteppingObjectAttribute): """keeps track of the worker's packing progress""" _depends_on = ['packed', 'color'] _step_after = ['pushes'] def prepare(self): for obj in self.objects: self._set_indicator_colors(obj) def _get_normalized_height(self, obj): y, x = obj.position h = self.world.height return (h - y - 1) / (h - 2) def _set_indicator_colors(self, obj): progress = self.get(obj) for child in obj._children: height = self._get_normalized_height(child)
import unittest import numpy as np from pixelworld.envs.pixelworld import agents, events, universe, library from pixelworld.envs.pixelworld.tests import test_core import pixelworld.envs.pixelworld.library.helpers as h sip = library.import_item('world', 'aliens_pixels') class TestAliensPixels(test_core.TestCase): world = None def __init__(self, *args, **kwargs): self.world = kwargs.pop('world', 'aliens_pixels') super(TestAliensPixels, self).__init__(*args, **kwargs) def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def test_barricades_can_be_destroyed(self): # create the objects we want objects, _, _ = h.world.screen(""" B P """, sip.legend)
import unittest import numpy as np from pixelworld.envs.pixelworld import agents, universe, objects, library from pixelworld.envs.pixelworld.tests.library.world import test_library_world import pixelworld.envs.pixelworld.library.helpers as h block_breaker = library.import_item('world', 'block_breaker') class TestBlockBreaker(test_library_world.TestLibraryWorld): world = None def __init__(self, *args, **kwargs): super(TestBlockBreaker, self).__init__(*args, **kwargs) self.world = kwargs.pop('world', 'block_breaker') def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def test_bricks_disappear_and_goal_achieved(self): # create the obejcts we want objects, height, width = h.world.screen(""" WWWW W BW
import unittest import numpy as np from pixelworld.envs.pixelworld import universe, events, agents, library from pixelworld.envs.pixelworld.tests import test_core sokoban = library.import_item('world', 'sokoban') class TestSokoban(test_core.TestCase): world = None def __init__(self, *args, **kwargs): self.world = kwargs.pop('world', 'sokoban') super(TestSokoban, self).__init__(*args, **kwargs) def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def test_walls(self): # switch to provided screen screen = """ ---- -* - - -
import unittest import numpy as np from pixelworld.envs.pixelworld import universe, library import pixelworld.envs.pixelworld.library.helpers as h from pixelworld.envs.pixelworld.tests import test_core pixelzuma = library.import_item('world', 'pixelzuma') pixelzuma_full = library.import_item('world', 'pixelzuma_full') class TestPixelzuma(test_core.TestCase): world = None def __init__(self, *args, **kwargs): self.world = kwargs.pop('world', 'pixelzuma_full') super(TestPixelzuma, self).__init__(*args, **kwargs) def tearDown(self): self.world.end() def _test_walkthrough(self): self.world = universe.create_world('pixelzuma_full') walkthrough = """ #down_the_ladder DOWN DOWN DOWN #over_to_the_rope_and_down_the_ladder RIGHT RIGHT JUMPRIGHT NOOP JUMPRIGHT NOOP RIGHT DOWN DOWN DOWN
import unittest import numpy as np from pixelworld.envs.pixelworld import agents, universe, library from pixelworld.envs.pixelworld.tests import test_core import pixelworld.envs.pixelworld.library.helpers as h from pixelworld.envs.pixelworld.tests.library.world import test_library_world chomper = library.import_item('world', 'chomper') class TestChomper(test_library_world.TestLibraryWorld): world = None def __init__(self, *args, **kwargs): super(TestChomper, self).__init__(*args, **kwargs) self.world = kwargs.pop('world', 'chomper') def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def test_loop(self): """Check that ghost goes around a loop when there are no branching choices""" objects, height, width = h.world.screen( """
import unittest import random import numpy as np from pixelworld.envs.pixelworld import agents, universe, library from pixelworld.envs.pixelworld.tests import test_core from pixelworld.envs.pixelworld.tests.library.world import test_library_world taxi = library.import_item('world', 'taxi') class TestTaxi(test_library_world.TestLibraryWorld): world = None def __init__(self, *args, **kwargs): super(TestTaxi, self).__init__(*args, **kwargs) self.world = kwargs.pop('world', 'taxi') def setUp(self): if isinstance(self.world, basestring): self.world = universe.create_world(self.world) def tearDown(self): self.world.end() def test_spawning(self): # check that we start with no passengers self.assertEqual(len(self.world.objects.find(name='passenger')), 0)
import numpy as np from pixelworld.envs.pixelworld import core, object_attributes as oa, library from ..helpers import h, L switch = library.import_item('world', 'switch') Switch, SwitchHitEvent = switch.Switch, switch.SwitchHitEvent class MultiSwitchJudge(core.Judge): """A judge that rewards you for flipping all the switches in the correct order, and penalizes you for flipping a switch out of order. The episode ends when you have flipped all of the switches. """ # id of the next switch to flip _next_switch = 0 # ignore the switch-hitting event reward _use_event_reward = False def prepare(self): """Prepare the judge by finding the switch with the lowest id and making that the next switch to flip. """ self._next_switch = self._world.objects.find(name='switch')[0].id def _calculate_reward(self, goals, events): """Calculate the reward. In this case it is +100 for flipping the right switch and -100 for flipping the wrong switch. Parameters ----------
""" Pixelzuma PixelWorld environment """ from ..helpers import h, L from pixelworld.envs.pixelworld import core, randomizers, object_attributes, library pixelzuma = library.import_item('world', 'pixelzuma') #------------------------------------------------------------------------------ # Pixelzuma World #------------------------------------------------------------------------------ screen_map = """ ABC DEFGH IJKLMNO PQRSTUVWX """ # Screen layout, see legend screens = { 'A': """ ------------------ - T$TT TT T - - T TT TT T X --------H--------- - H - - H - - H -
import unittest from pixelworld.envs.pixelworld import universe, agents, library from pixelworld.envs.pixelworld.tests import test_core from pixelworld.envs.pixelworld.tests.library.world import test_library_world hanoi = library.import_item('world', 'hanoi') class TestHanoi(test_library_world.TestLibraryWorld): world = None def __init__(self, *args, **kwargs): super(TestHanoi, self).__init__(*args, **kwargs) def setUp(self): self.world = universe.create_world('hanoi', num_disks=2) def tearDown(self): self.world.end() def validate_arrangement(self): """Check that all the disks are in the right position""" # for each tower for location in xrange(3): disks = self.world.objects.find(name='disk', location=location) # sort disks by size disks = sorted(disks, key=lambda disk: disk.size, reverse=True) for i, disk in enumerate(disks): # check that disks are at the right y-position based on their relative sizes