示例#1
0
    def move_random(self, percent):
        me = self.gameEngine.ghosts[self.ghostname]
        
        if GE.dist(me, self.old_wp) < me['radius'] + GE.THRESHOLD:
            if random.random() <= percent and not self.old_wp['id'] == self.home:
                self.old_wp = random.choice(self.gameEngine.points)
            else:
                self.old_wp = self.gameEngine.points[self.gameEngine.findClosestWP(self.gameEngine.pacman)]
            
        my_wp = self.gameEngine.findClosestMapPoint(me)
        path = self.gameEngine.find_shortest_path(my_wp, self.old_wp)


        if len(path) == 1:
            return path[0]['id'], path[len(path)-1]['id']

        index = 1
        
        while index < len(path)-1 and GE.dist(path[index], me) < me['radius'] + GE.THRESHOLD :
            index += 1;

        while index < len(path)-1 and GE.dist(path[index], self.gameEngine.ghosts[self.ghostname]) < 2 * self.gameEngine.ghosts[self.ghostname]['radius'] + 2.0 * GE.THRESHOLD and self.gameEngine.positionBlocked(path[index], self.gameEngine.ghosts[self.ghostname]):
            index +=1;

 
        return path[index]['id'], path[len(path)-1]['id']
示例#2
0
    def update(self):
        if not self.gameEngine.initialized or not self.ghostname in self.gameEngine.ghosts or self.state == GE.State.SETUP:
            return
        me = self.gameEngine.ghosts[self.ghostname]
                          
        if self.state == GE.State.RUNNING and self.startTime + self.sleepTime > rospy.get_time():
            return
 

        if (self.state == GE.State.STOPPED or self.state == GE.State.PAUSED):
            self.move_base_client.cancel_all_goals()
            self.current_wp = None
            self.headingToWp = False
            #self.old_wp = self.gameEngin.points[self.home]
            return
  
        if (self.state in [GE.State.INIT, GE.State.GAME_OVER] or self.dead):
            new_wp,end = self.return_home();
            self.headingToWp = False
        elif (self.state == GE.State.FLEEING):
            if GE.dist(self.gameEngine.pacman, me) < self.gameEngine.pacman['radius'] + me['radius'] + 1.5*GE.THRESHOLD:
                self.dead = True
                new_wp,end = self.return_home();
                self.headingToWp = False
            else:
                new_wp,end = self.newBehavior()
                  
        elif self.headingToWp and GE.dist(me, self.gameEngine.points[self.current_wp]) < me['radius'] + GE.THRESHOLD:
            self.headingToWp = False
            return
        elif self.headingToWp:
            return
        else:
            new_wp,end = self.newBehavior()
        
        if not (new_wp == self.current_wp):
            self.current_wp = new_wp
            self.move_base_client.cancel_all_goals()
            self.send_goal(self.current_wp)
        else:
            nearestWP = self.gameEngine.findClosestWP(me)
            if self.state in [GE.State.RUNNING, GE.State.FLEEING] and nearestWP == self.current_wp and self.current_wp == end and GE.dist(me, self.gameEngine.points[self.current_wp]) < me['radius']:
                self.headingToWp = True
                
                pm_wp = self.gameEngine.findClosestWP(self.gameEngine.pacman)
                if (end == pm_wp):
                    pm_mp = self.gameEngine.findClosestMapPoint(self.gameEngine.pacman)
                    if pm_mp['neighbors'][0] == pm_wp:
                        self.current_wp = pm_mp['neighbors'][1]
                    else:
                        self.current_wp = pm_mp['neighbors'][0]
                    
                else:
                    while self.current_wp == end:
                        print self.ghostname + str(self.current_wp)
                        self.current_wp = random.choice(self.gameEngine.points[nearestWP]['neighbors'])
               
                self.move_base_client.cancel_all_goals()
                self.send_goal(self.current_wp)
示例#3
0
    def return_home(self):
        if GE.dist(self.gameEngine.points[self.home], self.gameEngine.pacman) < self.gameEngine.pacman['radius'] + GE.THRESHOLD:
            self.dead = False
        my_position = self.gameEngine.pacman
        my_wp = self.gameEngine.findClosestMapPoint(my_position)
       
        path = self.gameEngine.find_shortest_path(my_wp,self.gameEngine.points[self.home])
        index = 1
        while index < len(path)-1 and GE.dist(path[index], self.gameEngine.pacman) < self.gameEngine.pacman['radius'] + 1.5 * GE.THRESHOLD :
            index += 1;

        return path[index]['id']
示例#4
0
 def return_home(self):
     if GE.dist(self.gameEngine.points[self.home], self.gameEngine.pacman) < self.gameEngine.pacman['radius'] + GE.THRESHOLD:
         self.move_base_client.cancel_all_goals()
     my_position = self.gameEngine.pacman
     my_wp = self.gameEngine.findClosestMapPoint(my_position)
    
     path = self.gameEngine.find_shortest_path(my_wp,self.gameEngine.points[self.home])
     index = 1
     while index < len(path)-1 and GE.dist(path[index], self.gameEngine.pacman) < self.gameEngine.pacman['radius'] + 1.5 * GE.THRESHOLD :
         index += 1;
     if index < len(path)-1 and GE.dist(path[index], self.gameEngine.pacman) < 2 * self.gameEngine.pacman['radius'] + 2.0 * GE.THRESHOLD and self.gameEngine.positionBlocked(path[index], self.gameEngine.pacman):
         index +=1;
     return path[index]['id']
示例#5
0
    def return_home(self):
        if GE.dist(self.gameEngine.points[self.home], self.gameEngine.pacman
                   ) < self.gameEngine.pacman['radius'] + GE.THRESHOLD:
            self.dead = False
        my_position = self.gameEngine.pacman
        my_wp = self.gameEngine.findClosestMapPoint(my_position)

        path = self.gameEngine.find_shortest_path(
            my_wp, self.gameEngine.points[self.home])
        index = 1
        while index < len(path) - 1 and GE.dist(
                path[index], self.gameEngine.pacman
        ) < self.gameEngine.pacman['radius'] + 1.5 * GE.THRESHOLD:
            index += 1

        return path[index]['id']
示例#6
0
    def return_home(self):
        if GE.dist(self.gameEngine.points[self.home], self.gameEngine.ghosts[self.ghostname]) < self.gameEngine.ghosts[self.ghostname]['radius'] + GE.THRESHOLD:
            self.dead = False
        my_position = self.gameEngine.ghosts[self.ghostname]
        my_wp = self.gameEngine.findClosestMapPoint(my_position)
       
        path = self.gameEngine.find_shortest_path(my_wp,self.gameEngine.points[self.home])
        
        if len(path) == 1:
            return path[0]['id'], path[len(path)-1]['id']

        index = 1
        while index < len(path)-1 and GE.dist(path[index], self.gameEngine.ghosts[self.ghostname]) < self.gameEngine.ghosts[self.ghostname]['radius'] + 1.5 * GE.THRESHOLD :
            index += 1;
        
        while index < len(path)-1 and GE.dist(path[index], self.gameEngine.ghosts[self.ghostname]) < 2 * self.gameEngine.ghosts[self.ghostname]['radius'] + 2.0 * GE.THRESHOLD and self.gameEngine.positionBlocked(path[index], self.gameEngine.ghosts[self.ghostname]):
            index +=1;
 
        return path[index]['id'], path[len(path)-1]['id']
示例#7
0
    def return_home(self):
        if GE.dist(self.gameEngine.points[self.home], self.gameEngine.pacman
                   ) < self.gameEngine.pacman['radius'] + GE.THRESHOLD:
            self.move_base_client.cancel_all_goals()
        my_position = self.gameEngine.pacman
        my_wp = self.gameEngine.findClosestMapPoint(my_position)

        path = self.gameEngine.find_shortest_path(
            my_wp, self.gameEngine.points[self.home])
        index = 1
        while index < len(path) - 1 and GE.dist(
                path[index], self.gameEngine.pacman
        ) < self.gameEngine.pacman['radius'] + 1.5 * GE.THRESHOLD:
            index += 1
        if index < len(path) - 1 and GE.dist(
                path[index], self.gameEngine.pacman
        ) < 2 * self.gameEngine.pacman[
                'radius'] + 2.0 * GE.THRESHOLD and self.gameEngine.positionBlocked(
                    path[index], self.gameEngine.pacman):
            index += 1
        return path[index]['id']
示例#8
0
    def chase_pacman(self):
        my_position = self.gameEngine.ghosts[self.ghostname]
        pm_position = self.gameEngine.pacman
        
        my_wp = self.gameEngine.findClosestMapPoint(my_position)
        pm_wp = self.gameEngine.findClosestWP(pm_position)
        path = self.gameEngine.find_shortest_path(my_wp, self.gameEngine.points[pm_wp])
        
        if len(path) == 1:
            return path[0]['id'], path[len(path)-1]['id']
        
        index = 1

        while index < len(path)-1 and GE.dist(path[index], self.gameEngine.ghosts[self.ghostname]) < self.gameEngine.ghosts[self.ghostname]['radius'] + GE.THRESHOLD :
            index += 1;

 
        return path[index]['id'], path[len(path)-1]['id']