Esempio n. 1
0
 def update_viy_pos(self):
     positions = []
     for i in range(self.agent_map.map_size.height):
         for j in range(self.agent_map.map_size.width):
             if self.agent_map[Position(i, j)] == P_VIY:
                 positions.append(Position(i, j))
     if len(positions) == 1:
         self.agent_map[positions[0]] = VIY
Esempio n. 2
0
 def get_min_pos(self):
     min_pos = Position(0, 0)
     for i in range(len(self.map)):
         for j in range(len(self.map[i])):
             if self.map[i][j] < self.map[min_pos.x][
                     min_pos.y] and self.pos.x != i and self.pos.y != j:
                 min_pos = Position(i, j)
     return min_pos
Esempio n. 3
0
    def __init__(self, map: Map):
        self.world_map = map
        self.agent_map = self.get_agent_map()
        # position
        self.x = 1
        self.y = 1

        self.world_map.agent_pos = Position(self.x, self.y)
        self.agent_map.agent_pos = Position(self.x, self.y)
        self.can_kick = True
Esempio n. 4
0
 def update_map(self):
     """
     Analizes agent's sensors and updates map
     """
     self.agent_map[self.pos] = self.world_map[self.pos]
     self.update_positions(self.check_pos(Position(self.x + 1, self.y)))
     self.update_positions(self.check_pos(Position(self.x - 1, self.y)))
     self.update_positions(self.check_pos(Position(self.x, self.y + 1)))
     self.update_positions(self.check_pos(Position(self.x, self.y - 1)))
     self.update_viy_pos()
Esempio n. 5
0
 def get_moves(self, check_func):
     moves = []
     if check_func(Position(self.pos.x - 1, self.pos.y)):
         moves.append(self.go_left)
     if check_func(Position(self.pos.x + 1, self.pos.y)):
         moves.append(self.go_right)
     if check_func(Position(self.pos.x, self.pos.y - 1)):
         moves.append(self.go_bottom)
     if check_func(Position(self.pos.x, self.pos.y + 1)):
         moves.append(self.go_top)
     return moves
Esempio n. 6
0
 def kick(self, pos):
     if self.world_map[pos] == VIY and self.can_kick:
         self.world_map[pos] = EMPTY
         for i in range(self.agent_map.map_size.height):
             for j in range(self.agent_map.map_size.width):
                 if self.agent_map[Position(i, j)] == P_VIY:
                     self.agent_map[Position(i, j)] = ANY
                 elif self.agent_map[Position(i, j)] == VIY:
                     self.agent_map[Position(i, j)] = SAFE
         print('VIY KILLED')
     self.can_kick = False
Esempio n. 7
0
    def get_available_moves(self):
        moves = []

        def check_move(pos):
            if self.is_available_pos(pos):
                moves.append(pos)

        check_move(Position(self.x + 1, self.y))
        check_move(Position(self.x - 1, self.y))
        check_move(Position(self.x, self.y + 1))
        check_move(Position(self.x, self.y - 1))
        return moves
Esempio n. 8
0
 def dp(self, node: Node, temp_matrix: list):
     cur_node = temp_matrix[node.pos.x][node.pos.y]
     if cur_node.total_weight / cur_node.count > node.total_weight / node.count:
         node.visited = True
         temp_matrix[node.pos.x][node.pos.y] = node
     positions = (Position(node.pos.x - 1, node.pos.y),
                  Position(node.pos.x + 1,
                           node.pos.y), Position(node.pos.x,
                                                 node.pos.y - 1),
                  Position(node.pos.x, node.pos.y + 1))
     for pos in positions:
         if not temp_matrix[pos.x][pos.y].visited:
             new_node = Node(from_node=node,
                             count=node.count + 1,
                             total_weight=node.total_weight +
                             self.map[pos.x][pos.y],
                             pos=pos)
             self.dp(new_node, temp_matrix)
Esempio n. 9
0
 def build_temp_matrix(self):
     temp = []
     for i in range(len(self.map)):
         temp.append([])
         for j in range(len(self.map[i])):
             node = Node()
             if not self.env.check_cell(Position(i, j)):
                 node.visited = True
             temp[-1].append(node)
     return temp
Esempio n. 10
0
 def go_bottom(self):
     self._move(Position(self.pos.x, self.pos.y - 1))
Esempio n. 11
0
 def go_top(self):
     self._move(Position(self.pos.x, self.pos.y + 1))
Esempio n. 12
0
 def go_right(self):
     self._move(Position(self.pos.x + 1, self.pos.y))
Esempio n. 13
0
 def go_left(self):
     self._move(Position(self.pos.x - 1, self.pos.y))
Esempio n. 14
0
 def update_positions(self, item):
     self.update_pos(Position(self.x + 1, self.y), item)
     self.update_pos(Position(self.x - 1, self.y), item)
     self.update_pos(Position(self.x, self.y + 1), item)
     self.update_pos(Position(self.x, self.y - 1), item)
Esempio n. 15
0
 def pos(self):
     return Position(self.x, self.y)
Esempio n. 16
0
 def move(self, pos):
     self.x = pos.x
     self.y = pos.y
     self.world_map.agent_pos = Position(self.x, self.y)
     self.agent_map.agent_pos = Position(self.x, self.y)