Exemplo n.º 1
0
    def render(self, mode='human'):
        if mode == 'disable':
            self.rendered = False
        elif mode == 'human':
            size = width, height = 900, 520
            center = (width // 2, height // 2 + 30)
            black = 105, 150, 90

            pygame.init()
            self.clock = pygame.time.Clock()
            self.screen = pygame.display.set_mode(size)

            self.rendered = True
        elif mode == 'rgb_array':
            size = width, height = 900, 520
            center = (width // 2, height // 2 + 30)
            black = 105, 150, 90

            pygame.init()
            self.clock = pygame.time.Clock()
            self.screen = pygame.display.set_mode(size)

            self.rendered = True

            # surf = pygame.surfarray.make_surface(size)
            # self.screen.blit(surf, (0, 0))
            # image = pygame.Surface(size)
            # image.blit(self.screen, (0, 0), ((0, 0), size))
            img = pygame.Surface(size)
            draw_frame(img, self.gameplay)
            arr = pygame.surfarray.array3d(img)
            arr = np.swapaxes(arr, 0, 1)
            return arr
Exemplo n.º 2
0
                    *qlearning.one_step(prev_states, players))
                prev_states = next_states
            except KeyboardInterrupt as e:
                raise e
            except Exception:
                prev_states = None

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    raise KeyboardInterrupt
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_v:
                        display = not display

            if display:
                draw_frame(screen, gameplay)

                # screen.blit(ball, ballrect)
                pygame.display.flip()
                clock.tick(20)
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        break

            if i % 20 == 0:
                logging.debug(
                    "%s\t, %s-%s" %
                    (round(gameplay.Ac, 1), gameplay.Kb, gameplay.Cb))

            if any(dones):
                gameplay = create_start_conditions(
        #     gameplay.Pa.D[1].mb |= 1
        # if keys[pygame.K_s]:
        #     gameplay.Pa.D[1].mb |= 2
        # if keys[pygame.K_d]:
        #     gameplay.Pa.D[1].mb |= 8
        # if keys[pygame.K_a]:
        #     gameplay.Pa.D[1].mb |= 4
        # if keys[pygame.K_LCTRL]:
        #     if red_unpressed:
        #         gameplay.Pa.D[1].mb |= 16
        #         gameplay.Pa.D[1].bc = 1
        #     red_unpressed = False
        # else:
        #     red_unpressed = True

        draw_frame(screen, gameplay, reward=reward, ret=ret)

        # screen.blit(ball, ballrect)
        pygame.display.flip()
        clock.tick(60)
        gameplay.step(1)

        # if gameplay.zb == 2:
        #     gameplay = create_start_conditions(
        #         posizione_palla=Vector(0, 0),
        #         velocita_palla=Vector(0, 0),
        #         posizione_blu=Vector(277.5, 0),
        #         velocita_blu=Vector(0, 0),
        #         input_blu=0,
        #         posizione_rosso=Vector(-277.5, 0),
        #         velocita_rosso=Vector(0, 0),