예제 #1
0
    def to_html(self, stats=[]):
        """Return svg representation of the simulator"""

        stats = stats[:]
        recent_reward = self.collected_rewards[-100:] + [0]
        objects_eaten_str = ', '.join(
            ["%s: %s" % (o, c) for o, c in self.objects_eaten.items()])
        stats.extend([
            "nearest wall = %.1f" % (self.distance_to_walls(), ),
            "reward       = %.1f" %
            (sum(recent_reward) / len(recent_reward), ),
            "objects eaten => %s" % (objects_eaten_str, ),
        ])

        scene = svg.Scene(
            (self.size[0] + 20, self.size[1] + 20 + 20 * len(stats)))
        scene.add(svg.Rectangle((10, 10), self.size))

        for line in self.observation_lines:
            scene.add(
                svg.Line(line.p1 + self.hero.position + Point2(10, 10),
                         line.p2 + self.hero.position + Point2(10, 10)))

        for obj in self.objects + [self.hero]:
            scene.add(obj.draw())

        offset = self.size[1] + 15
        for txt in stats:
            scene.add(svg.Text((10, offset + 20), txt, 15))
            offset += 20

        return scene
예제 #2
0
    def to_html(self, info=[]):
        """Visualize"""
        info = info[:]
        info.append("Reward = %.1f" % self.collect_reward())
        joint1, joint2 = self.joint_positions()

        total_length = self.params['l1_m'] + self.params['l2_m']
        # 9 / 10 th of half the screen width
        total_length_px = (8. / 10.) * (min(self.size) / 2.)
        scaling_ratio = total_length_px / total_length
        center = (self.size[0] / 2, self.size[1] / 2)

        def transform(point):
            """Transforms from state reference world
            to screen and pixels reference world"""

            x = center[0] + scaling_ratio * point[0]
            y = center[1] + scaling_ratio * point[1]
            return int(x), int(y)

        scene = svg.Scene(
            (self.size[0] + 20, self.size[1] + 20 + 20 * len(info)))
        scene.add(svg.Rectangle((10, 10), self.size))

        joint1 = transform(joint1)
        joint2 = transform(joint2)
        scene.add(svg.Line(center, joint1))
        scene.add(svg.Line(joint1, joint2))

        scene.add(svg.Circle(center, 5, color='red'))
        scene.add(svg.Circle(joint1, 3, color='blue'))
        scene.add(svg.Circle(joint2, 3, color='green'))

        offset = self.size[1] + 15
        for txt in info:
            scene.add(svg.Text((10, offset + 20), txt, 15))
            offset += 20
        return scene
예제 #3
0
    def to_html(self, stats=[]):
        """Return svg representation of the simulator"""

        stats = stats[:]
        recent_reward = self.collected_rewards[-100:] + [0]
        objects_eaten_str = ', '.join(["%s: %s" % (o,c) for o,c in self.objects_eaten.items()])
        stats.extend([
            "reward       = %.1f" % (sum(recent_reward)/len(recent_reward),),
            "objects eaten => %s" % (objects_eaten_str,),
        ])

        scene = svg.Scene((self.size[0] + 20, self.size[1] + 20 + 20 * len(stats)))
        scene.add(svg.Rectangle((10, 10), self.size))

        for i, line in enumerate(self.observation_lines):
            if self.just_shot and i == (self.settings["num_observation_lines"] / 2):
                scene.add(svg.Line(line.p1 + self.hero.position + Point2(10,10),
                                   line.p2 + self.hero.position + Point2(10,10), color='red'))
            else:
                scene.add(svg.Line(line.p1 + self.hero.position + Point2(10,10),
                                   line.p2 + self.hero.position + Point2(10,10)))

        for obj in self.objects:
            scene.add(obj.draw())

        if self.just_got_hit:
            scene.add(self.hero.draw('red'))
        else:
            scene.add(self.hero.draw())

        offset = self.size[1] + 15
        for txt in stats:
            scene.add(svg.Text((10, offset + 20), txt, 15))
            offset += 20

        return scene