def pilgrim_full(robot): unit_church = SPECS['CHURCH'] pos_x = robot.me.x pos_y = robot.me.y carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() if karb_map[pos_y][pos_x] == 1 or fuel_map[pos_y][pos_x] == 1: friendly_units = vision.sort_visible_friendlies_by_distance(robot) if friendly_units: for f_unit in friendly_units: dx = f_unit.x - pos_x dy = f_unit.y - pos_y if f_unit.unit == unit_church and abs(dx) <= 1 and abs(dy) <= 1 and utility.is_cell_occupied(occupied_map, f_unit.x, f_unit.y): robot.log("Giving church " + str(f_unit.id) + " " + str(carry_karb) + " karbonite and " + str(carry_fuel) + " fuel.") robot.log(str(f_unit)) robot.log(str(robot.me)) robot.log(str((dx, dy))) # if utility.is_cell_occupied(occupied_map, pos_x + f_unit.x - pos_x, pos_y + f_unit.y - pos_y): # robot.log("Exists") return robot.give(dx, dy, carry_karb, carry_fuel) for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and (karb_map[pos_y + direction[0]][pos_x + direction[1]] != 1 or fuel_map[pos_y + direction[0]][pos_x + direction[1]] != 1) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: if robot.karbonite > 50 and robot.fuel > 200: robot.log("Drop a church like it's hot") return robot.build_unit(unit_church, direction[1], direction[0])
def pilgrim_full(robot): unit_castle = SPECS['CASTLE'] unit_church = SPECS['CHURCH'] pos_x = robot.me.x pos_y = robot.me.y carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() if karb_map[pos_y][pos_x] == 1 or fuel_map[pos_y][pos_x] == 1: friendly_units = vision.sort_visible_friendlies_by_distance(robot) if friendly_units: for f_unit in friendly_units: dx = f_unit.x - pos_x dy = f_unit.y - pos_y if f_unit.unit == unit_church or f_unit.unit == unit_castle: if (dy, dx in directions) and abs(dx) <= 1 and abs(dy) <= 1 and (robot.get_visible_robot_map()[pos_y + dy][pos_x + dx] > 0): return robot.give(dx, dy, carry_karb, carry_fuel) for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and (karb_map[pos_y + direction[0]][pos_x + direction[1]] != 1 or fuel_map[pos_y + direction[0]][pos_x + direction[1]] != 1) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: if robot.karbonite > 50 and robot.fuel > 200: robot.log("Drop a church like it's hot") return robot.build_unit(unit_church, direction[1], direction[0])
def pilgrim(robot): communications.self_communicate_loop(robot) if robot.me.signal == 0: for friendly_unit in vision.sort_visible_friendlies_by_distance(robot): if friendly_unit.unit == 0 and friendly_unit.signal > -1: robot.signal(friendly_unit.signal, 0) break unit_signal = robot.me.signal carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel pos_x = robot.me.x pos_y = robot.me.y if carry_fuel > 80 or carry_karb > 18 : # robot.log("Nearing capacity") return pilgrim_full(robot) # robot.log('Position is ' + str(pos_x) + ' ' + str(pos_y)) ab = pilgrim_mine(robot) if ab !=0: return ab else: bc = pilgrim_move(robot, unit_signal) if bc !=0: return bc
def pilgrim(robot): communications.self_communicate_loop(robot) carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel # The pilgrim is on a mine and wants to deposit resources if carry_fuel > 80 or carry_karb > 18: # robot.log("Nearing capacity") return pilgrim_full(robot) # The pilgrim checks if it has a mine on it's current position pilgrim_is_mining = pilgrim_mine(robot) if pilgrim_is_mining != 0: return pilgrim_is_mining # Recieve signal from castle on which mine to go to and start self broadcasting if robot.me.signal == 0: for friendly_unit in vision.sort_visible_friendlies_by_distance(robot): if friendly_unit.unit == 0 and friendly_unit.signal > -1: robot.signal(friendly_unit.signal, 0) break # Move Section unit_signal = robot.me.signal # If signal is for mine postion, then start self broadcasting that position, edge case is (0,0) mine if unit_signal < 6464 and unit_signal > 0: robot.signal(add_mine_position_to_signal(robot, unit_signal), 0) robot.log("Pilgrim " + str(unit_signal)) # robot.log('Position is ' + str(pos_x) + ' ' + str(pos_y)) pilgrim_is_moving = pilgrim_move(robot, unit_signal) if pilgrim_is_moving != 0: return pilgrim_is_moving
def pilgrim(robot): # TODO - Fix random difficult to find timeout errors happening for some pilgrims in large maps (-s 56) # TODO - Add scout bots, who scout if no mine to mine communications.self_communicate_loop(robot) carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel # The pilgrim is on a mine and wants to deposit resources if carry_fuel > 80 or carry_karb > 18: # robot.log("Nearing capacity") return pilgrim_full(robot) # The pilgrim checks if it has a mine on it's current position pilgrim_is_mining = pilgrim_mine(robot) if pilgrim_is_mining !=0: return pilgrim_is_mining # Recieve signal from castle on which mine to go to and start self broadcasting if robot.me.signal == 0: unused_store, friendly_units = vision.sort_visible_friendlies_by_distance(robot) for friendly_unit in friendly_units: if friendly_unit.unit == 0 and friendly_unit.signal > -1: robot.signal(friendly_unit.signal, 0) break if utility.fuel_less_check(robot): return None # TODO - Add code to make pilgrim move to church or castle rather just building a new church # Move Section unit_signal = robot.me.signal # If signal is for mine postion, then start self broadcasting that position, edge case is (0,0) mine if unit_signal < 6464 and unit_signal > 0: robot.signal(add_mine_position_to_signal(robot, unit_signal), 0) # robot.log('Position is ' + str(pos_x) + ' ' + str(pos_y)) pilgrim_is_moving = pilgrim_move(robot, unit_signal) if pilgrim_is_moving !=0: return pilgrim_is_moving
def pilgrim_full(robot): pos_x = robot.me.x pos_y = robot.me.y carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() if karb_map[pos_y][pos_x] == 1 or fuel_map[pos_y][pos_x] == 1: _, friendly_units = vision.sort_visible_friendlies_by_distance(robot) if friendly_units: for f_unit in friendly_units: dx = f_unit.x - pos_x dy = f_unit.y - pos_y if f_unit.unit == constants.unit_church or f_unit.unit == constants.unit_castle: if (dy, dx in directions ) and abs(dx) <= 1 and abs(dy) <= 1 and ( robot.get_visible_robot_map()[pos_y + dy][pos_x + dx] > 0): robot.signal(0, 0) return robot.give(dx, dy, carry_karb, carry_fuel) # TODO - Make churches not be built if castle is in vision range # TODO - If multiple mine spots in vision, try placing at proper place # FIXME - Don't put churches on resources for direction in directions: if (not utility.is_cell_occupied( occupied_map, pos_x + direction[1], pos_y + direction[0] )) and (karb_map[pos_y + direction[0]][pos_x + direction[1]] != 1 or fuel_map[pos_y + direction[0]][pos_x + direction[1]] != 1) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: if robot.karbonite > 50 and robot.fuel > 200: robot.log("Drop a church like it's hot") robot.signal(0, 0) return robot.build_unit(constants.unit_church, direction[1], direction[0])
def pilgrim_full(robot): pos_x = robot.me.x pos_y = robot.me.y carry_karb = robot.me.karbonite carry_fuel = robot.me.fuel karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = constants.directions if karb_map[pos_y][pos_x] == 1 or fuel_map[pos_y][pos_x] == 1: unused_store, friendly_units = vision.sort_visible_friendlies_by_distance(robot) if friendly_units: for f_unit in friendly_units: dx = f_unit.x - pos_x dy = f_unit.y - pos_y if f_unit.unit == constants.unit_church or f_unit.unit == constants.unit_castle: if (dy, dx in directions) and abs(dx) <= 1 and abs(dy) <= 1 and (robot.get_visible_robot_map()[pos_y + dy][pos_x + dx] > 0): robot.signal(0, 0) return robot.give(dx, dy, carry_karb, carry_fuel) # FIXME - Make churches not be built if castle /other church is in vision range potential_church_postitons = [] for church_pos in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + church_pos[1], pos_y + church_pos[0])) and passable_map[pos_y + church_pos[0]][pos_x + church_pos[1]] == 1 and karb_map[pos_y + church_pos[0]][pos_x + church_pos[1]] != 1 and fuel_map[pos_y + church_pos[0]][pos_x + church_pos[1]] != 1: count = 0 for direction in directions: if not utility.is_out_of_bounds(len(occupied_map), pos_x + church_pos[1] + direction[1], pos_y + church_pos[0] + direction[0]): if karb_map[pos_y + church_pos[0] + direction[0]][pos_x + church_pos[0] + direction[1]] == 1 or fuel_map[pos_y + church_pos[0] + direction[0]][pos_x + church_pos[0] + direction[1]] == 1: count += 1 potential_church_postitons.append((church_pos[0], church_pos[1], count)) max_resource_pos = (0, 0, 0) for pos in potential_church_postitons: if pos[2] > max_resource_pos[2]: max_resource_pos = pos if robot.karbonite > 50 and robot.fuel > 200: robot.log("Drop a church like it's hot") robot.signal(0, 0) return robot.build_unit(constants.unit_church, max_resource_pos[1], max_resource_pos[0])