Пример #1
0
    def execute(self, registry):
        '''
        Evaluate move orders.

        #any existing move orders should be evaluated
        #(going round robin on submitting players, in order)
        #R1: No collision checking
        #R2: Stop short of offending segment
        #R3: Stop tangent to offending unit
        '''

        player_nums = sorted(self.player_move_list.keys())
        # "rotate" player nums based on the turn number, so 
        # a different player gets to go "first" every turn
        num_of_players = len(player_nums)
        if not num_of_players:
            return
        num_of_shuffles = self.turn_num % num_of_players
        for x in range(num_of_shuffles):
            player_num.append(player_num.pop(0))
        
        lists = [self.player_move_list[x] for x in player_nums]
        combined_list = swizzle(lists)
        
        self.results = {}
        
        for playerMove in combined_list:
            
            unit = registry.getById(playerMove.unitid)
            path_pairs = [(playerMove.path[i-1],playerMove.path[i]) for i in range(1,len(playerMove.path))]
            path_taken = [playerMove.path[0]]
            for start,end in path_pairs:
                intersecting = []
                for other in registry.getAllByType(Unit):
                    if unit!=other:
                        if geometry.shipsWillCollideOnSegment(start, end, unit, other):
                            intersecting.append(other)
                
                if not intersecting:
                    unit.setLocation(end)
                    path_taken.append(end)
                else:
                    shortest = geometry.distance(start,end)
                    shortest_point = end
                    
                    for other in intersecting:
                        pt = geometry.whereWillItStop(start, end, unit, other)
                        if geometry.distance(start,pt)<shortest:
                            shortest = geometry.distance(start,pt)
                            shortest_point = pt
                        
                    unit.setLocation(shortest_point)
                    path_taken.append(shortest_point)
                    break
            
            self.results[unit.gid] = path_taken
Пример #2
0
            for start,end in path_pairs:
                intersecting = []
                for other in registry.getAllByType(Unit):
                    if unit!=other:
                        if geometry.shipsWillCollideOnSegment(start, end, unit, other):
                            intersecting.append(other)
                
                if not intersecting:
                    unit.setLocation(end)
                    path_taken.append(end)
                else:
                    shortest = geometry.distance(start,end)
                    shortest_point = end
                    
                    for other in intersecting:
                        pt = geometry.whereWillItStop(start, end, unit, other)
                        if geometry.distance(start,pt)<shortest:
                            shortest = geometry.distance(start,pt)
                            shortest_point = pt
                        
                    unit.setLocation(shortest_point)
                    path_taken.append(shortest_point)
                    break
            
            self.results[unit.gid] = path_taken
        
    def getResults(self):
        return DTO_Results(self.results)
        
class AttackTurn:
    '''