예제 #1
0
            game_window.nodes.append(x.position.as_int_array)

        game_window.greedy_relays = []
        for x in dist_list.relay_list[1:]:
            game_window.greedy_relays.append(x.position.as_int_array)

        for x in greedy_list.relay_list:
            game_window.pursue_relays.append(x.position.as_int_array)

        game_window.selection = node_list[node_selector].position.as_int_array

        # call the tick/draw function
        game_window.tick(deltaT)

        # add random velocity onto the scenario, except to "base station"
        greedy_list.reset()

        event = game_window.catch_events()

        if event == K_w:
            node_list[node_selector].position.velocity_add([0, move_coefficient])
        if event == K_s:
            node_list[node_selector].position.velocity_add([0, -move_coefficient])
        if event == K_a:
            node_list[node_selector].position.velocity_add([-move_coefficient, 0])
        if event == K_d:
            node_list[node_selector].position.velocity_add([move_coefficient, 0])
        if event == 92:
            print("Attempt to trigger Debugger")

        if event == K_o:
예제 #2
0
class MultiForwardPursueNode(Node):
    pursue_target: List[Node]
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        self.__a, self.__global_relay_link = environment
        self.pursue_target = []

        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    @property
    def environment_relays(self):
        accumulator = []
        for x in self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    def follow(self):
        try:
            self.proof.node_list = self.environment
            self.proof.execute_pipeline()
        except:
            pass

        # for x in self.environment_relays:
        #     if self.type is NodeType.Relay:
        #         self.move_along_line(self.angle_to(x), (self.distance_to(x) - self.unit_distance) * .2)
        #         try:
        #             self.move_along_line(self.angle_to(self.proof.relay_list[0]),
        #                                  self.distance_to(self.proof.relay_list[0]) * .2)
        #         except:
        #             pass

        for x in self.pursue_target:
            print("we runnning")
            if self.type is NodeType.Relay:
                self.move_along_line(
                    self.angle_to(x),
                    (self.distance_to(x) - self.unit_distance) * .2)
                try:
                    self.move_along_line(
                        self.angle_to(self.proof.relay_list[0]),
                        self.distance_to(self.proof.relay_list[0]) * .6)
                    print("it gets triggered")

                except:
                    pass

            elif self.type is NodeType.Home:
                if self.distance_to(x) > self.unit_distance * .8:
                    new_node = MultiForwardPursueNode(
                        [self.__a, self.__global_relay_link],
                        self.unit_distance,
                        in_node=Node(Pos(0, 0)))

                    new_node.type = NodeType.Relay
                    new_node.move_along_line(new_node.angle_to(x),
                                             self.distance_to(x) * .8)

                    new_node.pursue_target.append(x)
                    self.pursue_target.append(new_node)
                    self.pursue_target.remove(x)
                    self.__global_relay_link.append(new_node)

                # if in call-back range
                if self.distance_to(x) < self.unit_distance * .1:
                    current_target = x
                    little_set = self.pursue_target + current_target.pursue_target
                    self.pursue_target = set(little_set)

                    try:
                        self.__global_relay_link.remove(current_target)
                        print("triggered from the bottom")
                    except:
                        print("form the bottom")

        self.proof.reset()
class ForwardPursueNode(Node):
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        #
        # if type(in_node) is type(Node):
        #     self = in_node

        self.__a, self.__global_relay_link = environment
        self.pursue_target = None
        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance * 1.2:
                    accumulator.append(x)
        return accumulator

    @property
    def environment_centroid(self):
        points = list(map(lambda x: x.position.as_array, self.environment))
        points = np.sum(points, axis=0)
        return np.divide(points, len(self.environment))

    def follow(self):
        if self.type is NodeType.Relay:
            # a propegated velocity is used to move everything around

            print("follow works")
            self.proof.node_list = self.environment

            self.move_along_line(
                self.angle_to(self.pursue_target),
                (self.distance_to(self.pursue_target) - self.unit_distance) *
                .2)

            try:
                self.proof.execute_pipeline()
                self.move_along_line(
                    self.angle_to(self.proof.relay_list[0]),
                    self.distance_to(self.proof.relay_list[0]) * .2)
                self.proof.reset()
            except:
                pass

        elif self.type is NodeType.Home:
            if self.distance_to(self.pursue_target) > self.unit_distance * .8:
                new_node = ForwardPursueNode(
                    [self.__a, self.__global_relay_link],
                    self.unit_distance,
                    in_node=Node(Pos(0, 0)))

                new_node.type = NodeType.Relay
                new_node.move_along_line(
                    new_node.angle_to(self.pursue_target),
                    self.distance_to(self.pursue_target) * .8)

                new_node.pursue_target = self.pursue_target
                self.pursue_target = new_node
                self.__global_relay_link.append(new_node)

            # if in call-back range
            if self.distance_to(self.pursue_target) < self.unit_distance * .1:
                current_target = self.pursue_target
                self.pursue_target = current_target.pursue_target
                try:
                    self.__global_relay_link.remove(current_target)
                except Exception as e:
                    print(e)
                    print("Node removal error")
예제 #4
0
class MultiForwardPursueNode(Node):
    pursue_target: List[Node]
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        self.__a, self.__global_relay_link = environment
        self.pursue_target = []
        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            print(self.distance_to(x))
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    def follow(self):
        for x in self.pursue_target:
            if self.distance_to(x) > self.unit_distance * .8:
                if self.type is NodeType.Relay:
                    self.move_along_line(
                        self.angle_to(x),
                        (self.distance_to(x) - self.unit_distance) * .2)

                    try:
                        self.proof.execute_pipeline()
                        self.move_along_line(
                            self.angle_to(self.proof.relay_list[0]),
                            self.distance_to(self.proof.relay_list[0]) * .6)
                        self.proof.reset()
                    except:
                        pass

                elif self.type is NodeType.Home:
                    for r in self.__global_relay_link[1:]:
                        if x.distance_to(r) < self.unit_distance * .7:
                            r.pursue_target.append(x)
                            self.pursue_target.remove(x)
                            if r not in self.pursue_target:
                                self.pursue_target.append(r)
                            break

                    if x in self.pursue_target:
                        new_node = MultiForwardPursueNode(
                            [self.__a, self.__global_relay_link],
                            self.unit_distance,
                            in_node=Node(Pos(0, 0)))

                        new_node.type = NodeType.Relay
                        new_node.move_along_line(new_node.angle_to(x),
                                                 self.distance_to(x) * .8)

                        new_node.pursue_target.append(x)
                        # needs work
                        self.pursue_target.remove(x)
                        self.pursue_target.append(new_node)
                        self.__global_relay_link.append(new_node)