def prevent_colliding_high_impact_moves(gamemap_original: GameMap, moves): """Find all moves that move unto a square such that I lose str. First algo: update map with all moves, then find all squares with max str, then find the squares that moved into these squares and make the square with lowest str that did it, not move into this square However, if the originating square has close to max str, then we should probably just move so check if originating str > max - prod, if so, just move """ gamemap = gamemap_original.__deepcopy__() origin_target_and_moves = gamemap.evolve_assuming_no_enemy_and_get_origin_and_target_and_move(moves) target_set_with_origin_and_moves = dict() for origin, target, move in origin_target_and_moves: if target in target_set_with_origin_and_moves: target_set_with_origin_and_moves[target] += [(origin, move)] else: target_set_with_origin_and_moves[target] = [(origin, move)] # target_set_with_origin_and_moves = dict((target, (origin, move)) for origin, target, move in origin_target_and_moves) my_locations_list = gamemap.my_locations_list() problematic_target_squares = [] for square in my_locations_list: my_str = gamemap.strength[square] if my_str == 255: problematic_target_squares.append(square) new_moves = [] for problem_site in problematic_target_squares: if problem_site not in target_set_with_origin_and_moves: continue origins_and_moves = target_set_with_origin_and_moves[problem_site] max_str = -1 max_move = None max_location = None for origin_move in origins_and_moves: origin, move = origin_move my_str = gamemap_original.strength[origin] if my_str > 255 - gamemap.prod[origin]: # TODO this doesn't work. Make something that maybe moves OUTWARD instead, when str is high? Now high str squares collide... continue if my_str > max_str: # TODO make it better: if two sites move unto one, and both would have breached 255 # then obviously BOTH should have moved somewhere else/stand still! max_str = my_str max_move = move max_location = origin if max_location: new_moves.append((max_location, STILL)) moves_dict = dict(moves) new_moves_dict = dict(new_moves) moves_dict.update(new_moves_dict) return [[k, v] for k, v in moves_dict.items()]
def find_optimal_moves_for_this_turn(start_game_map: GameMap): """' Returns the pair best_moves, score. best_moves is a tuple of ((x,y), direction) pairs""" max_score = 0 best_moves = None # for moves in create_all_next_moves(start_game_map.my_sites()): for moves in create_all_next_moves(start_game_map.my_locations_list()): game_map = start_game_map.__deepcopy__() # print(game_map) game_map.evolve_assuming_no_enemy(moves) # print(game_map) score = game_map.my_total_production() + game_map.my_total_strength() * 0.5 if score > max_score: best_moves = moves max_score = score return [best_moves], max_score
def play_range_of_games(gamemap: array_hlt.GameMap): res = [] for prod_to_str_ratio in range(1, 20): prods, strs = play_game(gamemap.__deepcopy__(), 100, prod_to_str_ratio) res.append((prod_to_str_ratio, prods, strs)) return res