示例#1
0
    def getEnv(self, id):
        x = self._Robots[id]._real_location._x
        y = self._Robots[id]._real_location._y
        array = [True, True, True, True]

        if (Point.existsXY(x, y - 1) == False):
            array[UP()] = False
        elif (self._mat_robot_id[x][y - 1] != -1 | self._mat_zone[x][y - 1]):
            array[UP()] = False

        if (Point.existsXY(x, y + 1) == False):
            array[DOWN()] = False
        elif (self._mat_robot_id[x][y + 1] != -1 | self._mat_zone[x][y + 1]):
            array[DOWN()] = False

        if (Point.existsXY(x - 1, y) == False):
            array[LEFT()] = False
        elif (self._mat_robot_id[x - 1][y] != -1 | self._mat_zone[x - 1][y]):
            array[LEFT()] = False

        if (Point.existsXY(x + 1, y) == False):
            array[RIGHT()] = False
        elif (self._mat_robot_id[x + 1][y] != -1 | self._mat_zone[x + 1][y]):
            array[RIGHT()] = False

        return array
示例#2
0
文件: Arena.py 项目: 4321igal/Matala3
    def getEnv(self, id):
        x = self._Robots[id]._real_location._x
        y = self._Robots[id]._real_location._y
        array = [True,True,True,True]

        if (Point.existsXY(x, y-1) == False):
            array[UP()] = False
        elif(self._mat_robot_id[x][y-1]!=-1 | self._mat_zone[x][y-1]):
            array[UP()] =False

        if (Point.existsXY(x, y+1) == False):
            array[DOWN()] = False
        elif(self._mat_robot_id[x][y+1]!=-1 | self._mat_zone[x][y+1]):
            array[DOWN()] =False

        if (Point.existsXY(x - 1, y) == False):
            array[LEFT()] = False
        elif(self._mat_robot_id[x-1][y]!=-1 | self._mat_zone[x-1][y]):
            array[LEFT()] =False

        if(Point.existsXY(x+1, y) == False):
            array[RIGHT()] = False
        elif(self._mat_robot_id[x+1][y]!=-1 | self._mat_zone[x+1][y]):
            array[RIGHT()] =False

        return array
示例#3
0
    def showGUI(self):
        X = []
        for i in range(int(ARENA_X())):
            line = int(ARENA_Y())*[-1]
            X.append(line)

        for i in range(int(ARENA_X())):
            for j in range(int(ARENA_Y())):
                if(X[i][j] != -1): continue

                if(self._Arena._mat_robot_id[i][j]!=-1):
                    if(self._Arena._Robots[self._Arena._mat_robot_id[i][j]]._can_move):
                        X[i][j] = ROBOTS_MOVE_COLOR()
                        for i2 in range(i - ROBOT_LEANGHT(), i + ROBOT_LEANGHT()):
                            for j2 in range(j - ROBOT_LEANGHT(), j + ROBOT_LEANGHT()):
                                if (Point.existsXY(i2, j2)):
                                    X[i2][j2] = ROBOTS_MOVE_COLOR()
                    else:
                        X[i][j] = ROBOTS_NOT_MOVE_COLOR()
                        for i2 in range(i - ROBOT_LEANGHT(), i + ROBOT_LEANGHT()):
                            for j2 in range(j - ROBOT_LEANGHT(), j + ROBOT_LEANGHT()):
                                if (Point.existsXY(i2, j2)):
                                    X[i2][j2] = ROBOTS_NOT_MOVE_COLOR()


                elif (self._Arena._mat_zone[i][j] == 2):
                    X[i][j] = 1000
                elif (self._Arena._mat_zone[i][j] == 1):
                    X[i][j] = 500
                elif (self._Arena._mat_zone[i][j] == 0):
                    X[i][j] = 0

        fig, ax = plt.subplots()
        ax.imshow(X, cmap='RdGy', interpolation='nearest')

        callback = self

        Msg1_loc = plt.axes([0.05, 0.95, 0.90, 0.045])
        Msg1 = Button(Msg1_loc, "Time= "+str(self._time) + ",   Robot moved= "+str(Arena._mone_move) + ",    Messages = " + str(self.Messages_mone))#) +" |  << Click here for details >>")
        #Msg1.on_clicked(callback.actionMsg1)

        #button1:
        butt1_loc = plt.axes([0.1, 0.001, 0.25, 0.065])
        butt1 = Button(butt1_loc, str(BUTTON_NUMBER_1())+' step forward')
        butt1.on_clicked(callback.actionButton1)

        # button2:
        butt2_loc = plt.axes([0.4, 0.001, 0.25, 0.065])
        butt2 = Button(butt2_loc, str(BUTTON_NUMBER_2()) +' step forward')
        butt2.on_clicked(callback.actionButton2)

        ##button3:
        butt3_loc = plt.axes([0.7, 0.001, 0.25, 0.065])
        butt3 = Button(butt3_loc, str(BUTTON_NUMBER_3()) +' step forward')
        butt3.on_clicked(callback.actionButton3)

        plt.show()
示例#4
0
文件: Air.py 项目: 4321igal/Matala3
    def sendMessage(message, robot):
        canSend = Air.canSend(robot)
        if(canSend == True):
            message._real_location = robot._real_location
            if (bool(ACTIVE_MATDISTANCE())):
                Point.fillMatDistance(Air.static_mat_zone,message._mat_distance, message._real_location)

            Air._messages.append(message)

        return canSend
示例#5
0
    def sendMessage(message, robot):
        canSend = Air.canSend(robot)
        if (canSend == True):
            message._real_location = robot._real_location
            if (bool(ACTIVE_MATDISTANCE())):
                Point.fillMatDistance(Air.static_mat_zone,
                                      message._mat_distance,
                                      message._real_location)

            Air._messages.append(message)

        return canSend
示例#6
0
 def getMessage(robot):
     sum_range = 0
     flag = False
     if (len(Air._messages) == 0): return NO_MSG()
     nearest_messagesa = Air._messages[0]
     robot_loc = robot._real_location
     r = 0
     for i in range(0, len(Air._messages)):
         r = 0
         if (bool(ACTIVE_MATDISTANCE())):
             r = Air._messages[i]._mat_distance[robot_loc._x][robot_loc._y]
         else:
             r = Point.airDistancePoints(robot_loc,
                                         Air._messages[i]._real_location)
         if (r == INFINITY() or r <= 0): continue
         if (r <= MIN_MSG_RANGE()):
             Air._messages[i]._snn = (MAX_MSG_RANGE() -
                                      r) * (MAX_MSG_RANGE() - r)
             return Air._messages[i]
         elif (r >= MAX_MSG_RANGE()):
             continue
         else:
             sum_range = sum_range + r
             nearest_mess_loc = nearest_messagesa._real_location
             messa_i = Air._messages[i]._real_location
             if (flag == False):
                 flag = True
                 nearest_messagesa = Air._messages[i]
                 nearest_messagesa._snn = (MAX_MSG_RANGE() -
                                           r) * (MAX_MSG_RANGE() - r)
                 return nearest_messagesa
             elif (Point.distance(Air.static_mat_zone, robot_loc,
                                  nearest_mess_loc) >
                   Point.distance(Air.static_mat_zone, robot_loc, messa_i)):
                 nearest_messagesa = Air._messages[i]
                 nearest_messagesa._snn = (MAX_MSG_RANGE() -
                                           r) * (MAX_MSG_RANGE() - r)
     if (flag): return NO_MSG()
     if (sum_range == 0): return NO_MSG()
     if (r == 0 or sum_range >= MAX_MSG_RANGE()):
         return NO_MSG()
     else:
         nearest_messagesa._snn = nearest_messagesa._snn - sum_range
         return nearest_messagesa
示例#7
0
文件: Air.py 项目: 4321igal/Matala3
 def getMessage(robot):
     sum_range = 0
     flag = False
     if(len(Air._messages) ==0 ): return NO_MSG()
     nearest_messagesa = Air._messages[0]
     robot_loc = robot._real_location
     r=0
     for i in range(0, len(Air._messages)):
         r =0
         if (bool(ACTIVE_MATDISTANCE())):
             r = Air._messages[i]._mat_distance[robot_loc._x][robot_loc._y]
         else:
             r = Point.airDistancePoints(robot_loc, Air._messages[i]._real_location)
         if(r == INFINITY() or r<=0): continue
         if(r <=MIN_MSG_RANGE()):
             Air._messages[i]._snn = (MAX_MSG_RANGE()-r)*(MAX_MSG_RANGE()-r)
             return Air._messages[i]
         elif(r >=MAX_MSG_RANGE()):
             continue
         else:
             sum_range = sum_range + r
             nearest_mess_loc = nearest_messagesa._real_location
             messa_i = Air._messages[i]._real_location
             if(flag == False):
                 flag = True
                 nearest_messagesa = Air._messages[i]
                 nearest_messagesa._snn = (MAX_MSG_RANGE() - r) * (MAX_MSG_RANGE() - r)
                 return nearest_messagesa
             elif(Point.distance(Air.static_mat_zone, robot_loc,nearest_mess_loc) > Point.distance(Air.static_mat_zone, robot_loc,messa_i)):
                 nearest_messagesa = Air._messages[i]
                 nearest_messagesa._snn = (MAX_MSG_RANGE() - r) * (MAX_MSG_RANGE() - r)
     if(flag): return NO_MSG()
     if(sum_range==0): return NO_MSG()
     if(r==0 or sum_range>= MAX_MSG_RANGE()):
         return NO_MSG()
     else:
         nearest_messagesa._snn = nearest_messagesa._snn - sum_range
         return nearest_messagesa
示例#8
0
文件: Air.py 项目: 4321igal/Matala3
    def canSend(robot):
        sum_range = 0
        robot_loc = Robot(robot)._real_location
        for i in range(0, len(Air._messages)):
            r = 0
            if (bool(ACTIVE_MATDISTANCE())):
                r = Air._messages[i]._mat_distance[robot_loc._x][robot_loc._y]
            else:
                r = Point.airDistancePoints(robot_loc, Air._messages[i]._real_location)

            if (r < MAX_MSG_RANGE()):
                sum_range = sum_range + r
        if (sum_range < math.sqrt(MAX_MSG_RANGE())):
            return True
        else:
            return False
示例#9
0
    def canSend(robot):
        sum_range = 0
        robot_loc = Robot(robot)._real_location
        for i in range(0, len(Air._messages)):
            r = 0
            if (bool(ACTIVE_MATDISTANCE())):
                r = Air._messages[i]._mat_distance[robot_loc._x][robot_loc._y]
            else:
                r = Point.airDistancePoints(robot_loc,
                                            Air._messages[i]._real_location)

            if (r < MAX_MSG_RANGE()):
                sum_range = sum_range + r
        if (sum_range < math.sqrt(MAX_MSG_RANGE())):
            return True
        else:
            return False
示例#10
0
文件: Message.py 项目: effy17/matala3
    def __init__(self, Id_Sender, Id_Message, Time, sender_estimated_loc):
        self._id_source = Id_Sender  # Upond creation: source = sender.
        self._id_message = Id_Message  # transmit_Message function (on Simulation) updates that value
        self._sender_history = [
        ]  # From here you can also find the latest sender.
        self._sender_estimated_location = sender_estimated_loc

        self._create_time = Time  #so that we dont pass 'MSG_LIFE_TIME'.
        self._version = 0  #so that we dont pass 'MAX_VERSION'.
        self._real_location = Point(0, 0)
        self._snn = 0
        self._mat_distance = []
        #Iputing '_mat_distance' distances:

        if (bool(ACTIVE_MATDISTANCE())):
            for i in range(int(float(ARENA_Y()))):
                self._mat_distance.append(int(ARENA_X()) * [INFINITY()])
示例#11
0
    def moveRobot(self, id, direction):
        array = self.getEnv(id)
        if (array[direction] == False):
            return False
        else:
            Arena._mone_move += 1
            x = self._Robots[id]._real_location._x
            y = self._Robots[id]._real_location._y
            self._mat_robot_id[x][y] = -1

            tolog = ""
            if (direction == UP()):
                tolog = ("Robot " + str(id) + ": move UP From [" + str(x) +
                         "][" + str(y) + "] to [" + str(x) + "][" +
                         str(y - 1) + "]")
                y = y - 1
            elif (direction == DOWN()):
                tolog = ("Robot " + str(id) + ": move DOWN From [" + str(x) +
                         "][" + str(y) + "] to [" + str(x) + "][" +
                         str(y + 1) + "]")
                y = y + 1
            elif (direction == LEFT()):
                tolog = ("Robot " + str(id) + ": move LEFT From [" + str(x) +
                         "][" + str(y) + "] to [" + str(x - 1) + "][" +
                         str(y) + "]")
                x = x - 1
            else:
                tolog = ("Robot " + str(id) + ": move RIGHT From [" + str(x) +
                         "][" + str(y) + "] to [" + str(x + 1) + "][" +
                         str(y) + "]")
                x = x + 1

            Log.addLine(tolog)
            #print(tolog)
            self._mat_robot_id[x][y] = id
            self._Robots[id]._real_location = Point(x, y)

            return True
示例#12
0
    def __init__(self):
        self._mat_robot_id = []
        self._Robots = []
        self._Robots_sort_Random = []
        self._mat_zone = []  # (white = 0    gray = 1     black = 2)

        for i in range(int(float(ARENA_X()))):
            self._mat_robot_id.append(int(ARENA_Y()) * [-1])
            self._mat_zone.append(int(ARENA_Y()) * [WHITE()])

        # Mark gray areas:
        Gray_area_point = GRAY_AREA()
        for b in range(len(Gray_area_point)):
            Log.addLine("create gray area point between: " +
                        str(Gray_area_point[b]))
            for i in range(Gray_area_point[b][0], Gray_area_point[b][2] + 1):
                for j in range(Gray_area_point[b][1],
                               Gray_area_point[b][3] + 1):
                    self._mat_zone[i][j] = GRAY()

        # Mark black areas:
        black_area_point = BLACK_AREA()
        for b in range(len(black_area_point)):
            Log.addLine("create black area point between: " +
                        str(black_area_point[b]))
            for i in range(black_area_point[b][0], black_area_point[b][2] + 1):
                for j in range(black_area_point[b][1],
                               black_area_point[b][3] + 1):
                    self._mat_zone[i][j] = BLACK()

        # Creates a new robot dinamic to variable "Robots"
        for s in range(0, int(ROBOTS_MOVE())):
            self._Robots.append(Robot(s))
            self._Robots_sort_Random.append(s)
            Log.addLine("create new Robot- " + self._Robots[s].toString())

        # Creates a new robot static to variable "Robots"
        for s in range(int(ROBOTS_MOVE()),
                       int(ROBOTS_MOVE()) + int(ROBOTS_NOT_MOVE())):
            self._Robots.append(Robot(s))
            self._Robots_sort_Random.append(s)
            self._Robots[s]._can_move = False

            Log.addLine("create new Robot- " + self._Robots[s].toString())

        #put the robots on Arena:
        for s in range(0, len(self._Robots)):
            x = randint(1, int(ARENA_X()) - 2)
            y = randint(1, int(ARENA_Y()) - 2)
            bool1 = self._mat_robot_id[x][y] != -1
            bool2 = self._mat_zone[x][y] == BLACK()
            bool3 = self._Robots[s]._can_move == False
            bool4 = self._mat_zone[x][y] != WHITE()
            while ((bool1 | bool2) | (bool3 & bool4)):
                x = randint(1, ARENA_X() - 2)
                y = randint(1, ARENA_Y() - 2)
                bool1 = self._mat_robot_id[x][y] != -1
                bool2 = self._mat_zone[x][y] == BLACK()
                bool3 = self._Robots[s]._can_move == False
                bool4 = self._mat_zone[x][y] != WHITE()

            self._Robots.append(Robot(s))
            self._mat_robot_id[x][y] = self._Robots[s]._id
            self._Robots[s]._real_location = Point(x, y)

            if (bool3):
                self._Robots[s]._estimated_location = Point(x, y)
                self._Robots[s]._estimated_location._deviation = 0
            Log.addLine("put Robot_" + str(self._Robots[s]._id) +
                        self._Robots[s]._real_location.toString())

        self.sortRandomRobotsArray()
示例#13
0
    def showGUI(self):
        X = []
        for i in range(int(ARENA_X())):
            line = int(ARENA_Y()) * [-1]
            X.append(line)

        for i in range(int(ARENA_X())):
            for j in range(int(ARENA_Y())):
                if (X[i][j] != -1): continue

                if (self._Arena._mat_robot_id[i][j] != -1):
                    if (self._Arena._Robots[self._Arena._mat_robot_id[i]
                                            [j]]._can_move):
                        X[i][j] = ROBOTS_MOVE_COLOR()
                        for i2 in range(i - ROBOT_LEANGHT(),
                                        i + ROBOT_LEANGHT()):
                            for j2 in range(j - ROBOT_LEANGHT(),
                                            j + ROBOT_LEANGHT()):
                                if (Point.existsXY(i2, j2)):
                                    X[i2][j2] = ROBOTS_MOVE_COLOR()
                    else:
                        X[i][j] = ROBOTS_NOT_MOVE_COLOR()
                        for i2 in range(i - ROBOT_LEANGHT(),
                                        i + ROBOT_LEANGHT()):
                            for j2 in range(j - ROBOT_LEANGHT(),
                                            j + ROBOT_LEANGHT()):
                                if (Point.existsXY(i2, j2)):
                                    X[i2][j2] = ROBOTS_NOT_MOVE_COLOR()

                elif (self._Arena._mat_zone[i][j] == 2):
                    X[i][j] = 1000
                elif (self._Arena._mat_zone[i][j] == 1):
                    X[i][j] = 500
                elif (self._Arena._mat_zone[i][j] == 0):
                    X[i][j] = 0

        fig, ax = plt.subplots()
        ax.imshow(X, cmap='RdGy', interpolation='nearest')

        callback = self

        Msg1_loc = plt.axes([0.05, 0.95, 0.90, 0.045])
        Msg1 = Button(
            Msg1_loc, "Time= " + str(self._time) + ",   Robot moved= " +
            str(Arena._mone_move) + ",    Messages = " +
            str(self.Messages_mone))  #) +" |  << Click here for details >>")
        #Msg1.on_clicked(callback.actionMsg1)

        #button1:
        butt1_loc = plt.axes([0.1, 0.001, 0.25, 0.065])
        butt1 = Button(butt1_loc, str(BUTTON_NUMBER_1()) + ' step forward')
        butt1.on_clicked(callback.actionButton1)

        # button2:
        butt2_loc = plt.axes([0.4, 0.001, 0.25, 0.065])
        butt2 = Button(butt2_loc, str(BUTTON_NUMBER_2()) + ' step forward')
        butt2.on_clicked(callback.actionButton2)

        ##button3:
        butt3_loc = plt.axes([0.7, 0.001, 0.25, 0.065])
        butt3 = Button(butt3_loc, str(BUTTON_NUMBER_3()) + ' step forward')
        butt3.on_clicked(callback.actionButton3)

        plt.show()