def optimum_block(self, robot, env): block_list = env.blocks if len(block_list) == 1: if robot.robot_id == 0 and env.red_dropped_off < env.blue_dropped_off and env.blue_dropped_off > 2: return (block_list[0][0], block_list[0][1]) elif robot.robot_id == 1 and env.red_dropped_off > env.blue_dropped_off and env.red_dropped_off > 2: return (block_list[0][0], block_list[0][1]) elif env.red_dropped_off == env.blue_dropped_off: pass else: return None new_block_list = [] cur_pos = robot.current_position() for block in block_list: p = (block[0], block[1]) block_position = (block[0], block[1]) if robot.robot_id == 0: other_target = self.blue_current_target else: other_target = self.red_current_target if h(other_target, p) < 20: continue if not (robot.path_possible([int(block[0]), int(block[1])])): continue else: distance = h(p, cur_pos) other_robot_distance = h( convert_to_grid_coords( robot.robot_data[(robot.robot_id + 1) % 2][1:3]), p) danger_coord, danger = env.optimum_heading( [block[0], block[1]], convert_to_grid_coords( robot.robot_data[(robot.robot_id + 1) % 2][1:3])) if danger >= 6: if not (robot.path_possible( [int(danger_coord[0]), int(danger_coord[1])])): print('No danger path') continue combined_heuristic = distance * 2 + -other_robot_distance * 1 + danger * 1 - h( other_target, p) print(combined_heuristic) if robot.robot_id + block[2] == 2: new_block_list.append( [block[0], block[1], (combined_heuristic) * 0.3]) elif block[2] == 0: new_block_list.append( [block[0], block[1], combined_heuristic]) if new_block_list == []: return None optblock = min(new_block_list, key=lambda x: x[2]) return (optblock[0], optblock[1])
def choose_block(self, block_list, robot, factor=0.5, env=None): cur_pos = robot.current_position() new_block_list = [] for block in block_list: p = (block[0], block[1]) dis = h(p, cur_pos) if env: _, danger = env.optimum_heading( [block[0], block[1]], convert_to_grid_coords( robot.robot_data[(robot.robot_id + 1) % 2][1:3])) else: danger = 0 print('dis: ' + str(dis)) print('danger: ' + str(danger)) if robot.robot_id == 0: other_target = self.blue_current_target else: other_target = self.red_current_target if h(other_target, p) < 20: continue if robot.robot_id + block[2] == 2: new_block_list.append( [block[0], block[1], (dis + danger * 2) * factor]) elif block[2] == 0: new_block_list.append([block[0], block[1], dis + danger * 2]) if new_block_list == []: return None optblock = min(new_block_list, key=lambda x: x[2]) return (optblock[0], optblock[1])
def optimum_block(self, robot, env): block_list = env.blocks new_block_list = [] cur_pos = robot.current_position() for block in block_list: p = (block[0],block[1]) block_position = (block[0], block[1]) if robot.robot_id ==0: other_target = self.blue_current_target else: other_target = self.red_current_target if h(other_target, p) <20: continue if not(robot.path_possible([int(block[0]),int(block[1])])): continue else: distance = h(p, cur_pos) other_robot_distance = h(convert_to_grid_coords(robot.robot_data[(robot.robot_id+1)%2][1:3]), p) _, danger = env.optimum_heading([block[0],block[1]], convert_to_grid_coords(robot.robot_data[(robot.robot_id+1)%2][1:3])) combined_heuristic = distance*1 + -other_robot_distance*1 + danger*2 - h(other_target, p) if robot.robot_id + block[2] ==2: new_block_list.append([block[0],block[1],(combined_heuristic)*0.5]) elif block[2] ==0: new_block_list.append([block[0], block[1], combined_heuristic]) if new_block_list == []: return None optblock = min(new_block_list, key=lambda x: x[2]) return (optblock[0],optblock[1])
def choose_block(block_list, robot, factor=0.5): cur_pos = robot.current_position() new_block_list = [] for block in block_list: p = (block[0], block[1]) dis = h(p, cur_pos) if robot.robot_id == 0: other_target = blue_current_target else: other_target = red_current_target if h(other_target, p) < 15: continue if robot.robot_id + block[2] == 2: new_block_list.append([block[0], block[1], dis * factor]) elif block[2] == 0: new_block_list.append([block[0], block[1], dis]) if new_block_list == []: return None optblock = min(new_block_list, key=lambda x: x[2]) return (optblock[0], optblock[1])
def choose_block(block_list, robot, factor): cur_pos = robot.current_position() new_block_list = [] for block in block_list: p = (block[0], block[1]) dis = h(p, cur_pos) if robot.robot_id + block[2] == 2: new_block_list.append([block[0], block[1], dis * factor]) elif block[2] == 0: new_block_list.append([block[0], block[1], dis]) if new_block_list == []: if robot.robot_id == 0: return (7, 73) else: return (7, 7) optblock = min(new_block_list, key=lambda x: x[2]) return (optblock[0], optblock[1])