def pilgrim_move(robot, unit_signal): if robot.fuel <= 2 : return 0 pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() occupied_map = robot.get_visible_robot_map() random_directions = utility.random_cells_around() # May change for impossible resources # Capture and start mining any resource if more than 50 turns since creation and no mine # TODO - Improve this code snippet to mine, if in visible region and empty if robot.me.turn > constants.pilgrim_will_scavenge_closeby_mines_after_turns and robot.me.turn < constants.pilgrim_will_scavenge_closeby_mines_before_turns: for direction in random_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): return robot.move(direction[1], direction[0]) # Just move if unit_signal >= 6464: move_to = move_to_specified_mine(robot, unit_signal) if move_to != None: # robot.log("check") new_pos_x, new_pos_y = move_to return robot.move(new_pos_x - pos_x, new_pos_y - pos_y) # Random Movement when not enough time for direction in random_directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(direction[1], direction[0]) return 0
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_move(robot): if robot.fuel <= 2 : return 0 pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() # May change for impossible 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): return robot.move(direction[1], direction[0]) # Just move # move_to = move_to_nearest_mine(robot) # if move_to != None: # robot.log("check") # new_pos_x, new_pos_y = move_to # return robot.move(new_pos_x - pos_x, new_pos_y - pos_y) for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(direction[1], direction[0]) return 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 castle_build(robot, unit_type): pos_x = robot.me.x pos_y = robot.me.y occupied_map = robot.get_visible_robot_map() passable_map = robot.get_passable_map() directions = utility.cells_around() for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.build_unit(unit_type, direction[1], direction[0])
def pilgrim_full(robot): unit_church = SPECS['CHURCH'] pos_x = robot.me.x pos_y = robot.me.y 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() if karb_map[pos_y][pos_x] == 1 or fuel_map[pos_y][pos_x] == 1: if (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 1) ) and (karb_map[pos_y + 1][pos_x + 1] != 1 or fuel_map[pos_y + 1][pos_x + 1] != 1): store_x, store_y = 1, 1 # E elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 0) ) and (karb_map[pos_y + 0][pos_x + 1] != 1 or fuel_map[pos_y + 0][pos_x + 1] != 1): store_x, store_y = 1, 0 # NE elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x + 1] != 1 or fuel_map[pos_y - 1][pos_x + 1] != 1): store_x, store_y = 1, -1 # N elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x + 0] != 1 or fuel_map[pos_y - 1][pos_x + 0] != 1): store_x, store_y = 0, -1 # NW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x - 1] != 1 or fuel_map[pos_y - 1][pos_x - 1] != 1): store_x, store_y = -1, -1 # W elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y + 0) ) and (karb_map[pos_y + 0][pos_x - 1] != 1 or fuel_map[pos_y + 0][pos_x - 1] != 1): store_x, store_y = -1, 0 # SW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y) ) and (karb_map[pos_y + 1][pos_x - 1] != 1 or fuel_map[pos_y + 1][pos_x - 1] != 1): store_x, store_y = -1, 1 # S elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y + 1) ) and (karb_map[pos_y + 1][pos_x + 0] != 1 or fuel_map[pos_y + 1][pos_x + 0] != 1): store_x, store_y = 0, 1 robot.log("Drop a church like it's hot") return robot.build_unit(unit_church, store_x, store_y)
def prophet_move(robot): pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(direction[1], direction[0])
def neighbours(pos_intermediate): pos_x, pos_y = pos_intermediate result = [] for dirc in dirs: new_pos_x = pos_x + dirc[1] new_pos_y = pos_y + dirc[0] if not utility.is_cell_occupied( occupied_map, new_pos_x, new_pos_y) and passable_map[new_pos_y][new_pos_x]: result.append((new_pos_x, new_pos_y)) return result
def pilgrim_move(robot): if robot.fuel <= 2 : return 0 pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() occupied_map = robot.get_visible_robot_map() directions = utility.cells_around() # May change for impossible 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): return robot.move(direction[1], direction[0]) # Just move for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0])) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(direction[1], direction[0]) return 0
def church_build(robot, unit_type): pos_x = robot.me.x pos_y = robot.me.y occupied_map = robot.get_visible_robot_map() passable_map = robot.get_passable_map() directions = utility.random_cells_around() for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0]) ) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.build_unit(unit_type, direction[1], direction[0]) robot.log("No space to build units anymore for churches") return None
def neighbours(robot, pos_intermediate, passable_map, occupied_map): pos_x, pos_y = pos_intermediate dirs = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] result = [] for dirc in dirs: new_pos_x = pos_x + dirc[1] new_pos_y = pos_y + dirc[0] if not utility.is_cell_occupied( occupied_map, new_pos_x, new_pos_y) and passable_map[new_pos_y][new_pos_x]: result.append((new_pos_x, new_pos_y)) return result
def crusader_move(robot): pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.random_cells_around() crusader_is_attacking_or_aggressive_moving = combat_module.give_military_command( robot) if crusader_is_attacking_or_aggressive_moving != None: return crusader_is_attacking_or_aggressive_moving for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0]) ) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(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 = 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])
def prophet_move(robot): pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() occupied_map = robot.get_visible_robot_map() directions = utility.random_cells_around() prophet_attack_aggr_mode = combat_module.give_military_command(robot) if prophet_attack_aggr_mode != None: return prophet_attack_aggr_mode if utility.fuel_less_check(robot): return None for direction in directions: if (not utility.is_cell_occupied(occupied_map, pos_x + direction[1], pos_y + direction[0]) ) and passable_map[pos_y + direction[0]][pos_x + direction[1]] == 1: return robot.move(direction[1], direction[0])
def pilgrim_move(robot): pos_x = robot.me.x pos_y = robot.me.y passable_map = robot.get_passable_map() karb_map = robot.get_karbonite_map() fuel_map = robot.get_fuel_map() occupied_map = robot.get_visible_robot_map() # May change for impossible resources # SE if (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 1)) and ( karb_map[pos_y + 1][pos_x + 1] == 1 or fuel_map[pos_y + 1][pos_x + 1] == 1): return robot.move(1, 1) # E elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 0) ) and (karb_map[pos_y + 0][pos_x + 1] == 1 or fuel_map[pos_y + 0][pos_x + 1] == 1): return robot.move(1, 0) # NE elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x + 1] == 1 or fuel_map[pos_y - 1][pos_x + 1] == 1): return robot.move(1, -1) # N elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x + 0] == 1 or fuel_map[pos_y - 1][pos_x + 0] == 1): return robot.move(0, -1) # NW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y - 1) ) and (karb_map[pos_y - 1][pos_x - 1] == 1 or fuel_map[pos_y - 1][pos_x - 1] == 1): return robot.move(-1, -1) # W elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y + 0) ) and (karb_map[pos_y + 0][pos_x - 1] == 1 or fuel_map[pos_y + 0][pos_x - 1] == 1): return robot.move(-1, 0) # SW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y)) and ( karb_map[pos_y + 1][pos_x - 1] == 1 or fuel_map[pos_y + 1][pos_x - 1] == 1): return robot.move(-1, 1) # S elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y + 1) ) and (karb_map[pos_y + 1][pos_x + 0] == 1 or fuel_map[pos_y + 1][pos_x + 0] == 1): return robot.move(0, 1) else: # Just move if (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 1) ) and passable_map[pos_y + 1][pos_x + 1] == 1: return robot.move(1, 1) # E elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y + 0) ) and passable_map[pos_y + 0][pos_x + 1] == 1: return robot.move(1, 0) # SE elif (not utility.is_cell_occupied(occupied_map, pos_x + 1, pos_y - 1) ) and passable_map[pos_y - 1][pos_x + 1] == 1: return robot.move(1, -1) # S elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y - 1) ) and passable_map[pos_y - 1][pos_x + 0] == 1: return robot.move(0, -1) # SW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y - 1) ) and passable_map[pos_y - 1][pos_x - 1] == 1: return robot.move(-1, -1) # W elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y + 0) ) and passable_map[pos_y + 0][pos_x - 1] == 1: return robot.move(-1, 0) # NW elif (not utility.is_cell_occupied(occupied_map, pos_x - 1, pos_y + 1) ) and passable_map[pos_y + 1][pos_x - 1] == 1: return robot.move(-1, 1) # N elif (not utility.is_cell_occupied(occupied_map, pos_x + 0, pos_y + 1) ) and passable_map[pos_y + 1][pos_x + 0] == 1: return robot.move(0, 1) else: return 0