示例#1
0
文件: waterworld.py 项目: CyrilMa/AI
    def _add_creep(self):
        creep_type = self.rng.choice([0, 1])

        creep = None
        pos = (0, 0)
        dist = 0.0

        while dist < 1.5:
            radius = self.CREEP_RADII[creep_type] * 1.5
            pos = self.rng.uniform(radius, self.height - radius, size=2)
            dist = math.sqrt(
                (self.player.pos.x - pos[0])**2 + (self.player.pos.y - pos[1])**2)

        creep = Creep(
            self.CREEP_COLORS[creep_type],
            self.CREEP_RADII[creep_type],
            pos,
            self.rng.choice([-1, 1], 2),
            self.rng.rand() * self.CREEP_SPEED,
            self.CREEP_REWARD[creep_type],
            self.CREEP_TYPES[creep_type],
            self.width,
            self.height,
            self.rng.rand()
        )

        self.creeps.add(creep)

        self.creep_counts[self.CREEP_TYPES[creep_type]] += 1
示例#2
0
    def init(self):
        """
            Starts/Resets the game to its inital state
        """

        self.player = Player(self.AGENT_RADIUS, self.AGENT_COLOR,
                             self.AGENT_SPEED, self.AGENT_INIT_POS, self.width,
                             self.height)
        self.player_group = pygame.sprite.Group()
        self.player_group.add(self.player)

        self.good_creep = Creep(self.CREEP_GOOD['color'],
                                self.CREEP_GOOD['radius'], self._rngCreepPos(),
                                (1, 1), 0.0, 1.0, "GOOD", self.width,
                                self.height)

        self.bad_creep = PuckCreep((self.width, self.height), self.CREEP_BAD,
                                   self.screen_dim[0] * 0.75,
                                   self.screen_dim[1] * 0.75)

        self.creeps = pygame.sprite.Group()
        self.creeps.add(self.good_creep)
        self.creeps.add(self.bad_creep)

        self.score = 0
        self.ticks = 0
        self.lives = -1
    def _add_creep(self):
        #lame way to do weighted selection. Its 50/50 atm.
        creep_type = choice([0]*50 + [1]*50) 

        creep = None
        creep_hits = [None]
        pos = ( 0,0 )
        dist = 0.0

        while len(creep_hits) > 0 and dist < 2.0:
            pos = ( 
                int(uniform(self.CREEP_RADII[creep_type]*2.5, self.width-self.CREEP_RADII[creep_type]*2.5)), 
                int(uniform(self.CREEP_RADII[creep_type]*2.5, self.height-self.CREEP_RADII[creep_type]*2.5)) 
            )  
            dist = math.sqrt( (self.player.pos.x - pos[0])**2 + (self.player.pos.y - pos[1])**2 )
  
            creep = Creep(
                self.CREEP_COLORS[creep_type], 
                self.CREEP_RADII[creep_type], 
                pos,
                ( choice([-1,1]), choice([-1,1]) ), 
                self.CREEP_SPEED,
                self.CREEP_REWARD[creep_type],
                self.CREEP_TYPES[creep_type], 
                self.width, 
                self.height
            )

            creep_hits = pygame.sprite.spritecollide(creep, self.creeps, False) #check if we are hitting another other creeps if it was placed here

        self.creeps.add(creep)

        self.creep_counts[ self.CREEP_TYPES[creep_type] ] += 1