Пример #1
0
    def animate_pacumen(self, pacumen, previous_pacumen, image):
        if self.frame_time < 0:
            print('Press any key to step forward, "q" to play')
            keys = wait_for_keys()

            if 'q' in keys:
                self.frame_time = 0.1

        if self.frame_time > 0.01 or self.frame_time < 0:
            fx, fy = self.get_position(previous_pacumen)
            px, py = self.get_position(pacumen)
            frames = 4.0

            for i in range(1, int(frames) + 1):
                pos = px * i / frames + fx * (
                    frames - i) / frames, py * i / frames + fy * (frames -
                                                                  i) / frames
                self.move_pacumen(pos, self.get_direction(pacumen), image)
                refresh_display()
                update_display(abs(self.frame_time) / frames)
        else:
            self.move_pacumen(self.get_position(pacumen),
                              self.get_direction(pacumen), image)

        refresh_display()
Пример #2
0
    def draw_expanded_cells(self, cells):
        """
        Draws an overlay of expanded grid positions. This is specifically for
        search agents, where it is desirable to see how the nodes of a given
        maze were expanded.
        """
        n = float(len(cells))
        base_color = [1.0, 0.0, 0.0]

        self.clear_expanded_cells()
        self.expanded_cells = []

        for k, cell in enumerate(cells):
            screen_pos = self.to_screen(cell)
            cell_color = format_color(*[(n - k) * c * .5 / n + .25
                                        for c in base_color])
            block = square(screen_pos,
                           0.5 * self.grid_size,
                           color=cell_color,
                           filled=1,
                           behind=2)
            self.expanded_cells.append(block)

            if self.frame_time < 0:
                refresh_display()
Пример #3
0
    def update_distributions(self, distributions):
        """
        Draws an agent's belief distributions. High posterior beliefs are
        represented by bright colors, while low beliefs are represented by
        dim colors.
        """
        distributions = map(lambda value: value.copy(), distributions)

        if self.distribution_images is None:
            self.draw_distributions(self.previous_state)

        for x in range(len(self.distribution_images)):
            for y in range(len(self.distribution_images[0])):
                image = self.distribution_images[x][y]
                weights = [dist[(x, y)] for dist in distributions]

                if sum(weights) != 0:
                    pass

                color = [0.0, 0.0, 0.0]
                colors = GHOST_VEC_COLORS[1:]

                for weight, g_color in zip(weights, colors):
                    color = [
                        min(1.0, c + 0.95 * g * weight**.3)
                        for c, g in zip(color, g_color)
                    ]

                change_color(image, format_color(*color))

        refresh_display()
Пример #4
0
    def move_pacumen(self, position, direction, image):
        screen_position = self.to_screen(position)
        endpoints = self.get_endpoints(direction, position)
        radius = PACUMEN_SCALE * self.grid_size

        move_circle(image[0], screen_position, radius, endpoints)

        refresh_display()
Пример #5
0
    def draw_agent_objects(self, state):
        self.agent_images = []

        for index, agent in enumerate(state.agent_states):
            if agent.is_pacumen:
                image = self.draw_pacumen(agent)
                self.agent_images.append((agent, image))
            else:
                image = self.draw_ghost(agent, index)
                self.agent_images.append((agent, image))

        refresh_display()
Пример #6
0
    def move_ghost(self, ghost, ghost_index, previous_ghost,
                   ghost_image_parts):
        old_x, old_y = self.to_screen(self.get_position(previous_ghost))
        new_x, new_y = self.to_screen(self.get_position(ghost))
        delta = new_x - old_x, new_y - old_y

        for ghost_image_part in ghost_image_parts:
            move_by(ghost_image_part, delta)

        refresh_display()

        if ghost.scared_timer > 0:
            color = SCARED_COLOR
        else:
            color = GHOST_COLORS[ghost_index]

        edit(ghost_image_parts[0], ('fill', color), ('outline', color))
        self.move_ghost_eyes(self.get_position(ghost),
                             self.get_direction(ghost), ghost_image_parts[-4:])

        refresh_display()
Пример #7
0
    def draw_static_objects(self, state):
        self.draw_walls(state.layout.walls)
        self.dots = self.draw_dots(state.layout.dots)
        self.pellets = self.draw_pellets(state.layout.pellets)

        refresh_display()