Exemplo n.º 1
0
 def mark_borders_and_get_potential_territory(self, gamemap: GameMap):
     grow_from_to_squares = []
     for square in gamemap.my_locations_list():
         # for neighbour in gamemap.neighbours(square[0], square[1]):
         for move in [(0, -1), (1, 0), (0, 1), (-1, 0)]:
             # [(y + dy) % self.height][(x + dx) % self.width]
             neighbour = ((square[0] + move[0]) % gamemap.height, (square[1] + move[1]) % gamemap.width)
             if not gamemap.is_mine(neighbour):
                 grow_from_to_squares.append((square, neighbour))
                 self.step_distances[square] = 0
                 self.square_stati[square] = self.Status.MY_BOUNDARY
                 self.square_stati[neighbour] = self.Status.NEW_BOUNDARY
     return grow_from_to_squares
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    def calculate_best_moves(self, gamemap: GameMap):
        moves = []
        my_total_str = gamemap.my_total_strength()
        my_locations_list = gamemap.my_locations_list()
        num_my_location = len(my_locations_list)
        for square in my_locations_list:
            my_str = gamemap.strength[square]
            if my_str <= 0:
                moves.append((square, STILL))
                continue

            # gamemap.log("calculating best move for square: " + str(square) + '\n')
            # do inner area differently, but only if strength is less than half the max (if bigger, just gogo!)
            # also check for insignificance str of this square (compare it to average str)
            if self.step_distances[square] < 0 and my_str < 256 / 2 and my_str < my_total_str / num_my_location:
                moves.append((square, STILL))
                continue

            if my_str > 256 / 2:
                best_move = STILL
                optimal_score = -9999
                for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                    neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                    # moving outward? if yes, then check for scores
                    if (self.step_distances[neighbour] > self.step_distances[square] \
                            and self.score[neighbour] > optimal_score
                            and my_str >= gamemap.strength[neighbour]):
                        # moving outward, great!
                        gamemap.log("finding move for strong square")
                        best_move = move
                        optimal_score = self.score[neighbour]

                if best_move == STILL:
                    gamemap.log("\nwtf. best move not yet found!\n")
                    gamemap.log_myself()
                    optimal_score = -9999
                    for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                        neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                        # moving outward? if yes, then check for scores
                        if self.step_distances[neighbour] > self.step_distances[square] and self.score[neighbour] > optimal_score:
                            # moving outward, great!
                            best_move = move
                            optimal_score = self.score[neighbour]
                moves.append((square, best_move))
                continue

            best_move = STILL
            optimal_score = -9999
            for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                # next commented section NEVER HAPPENS as neighbours cannot be enemies because of rules
                # if gamemap.owners[neighbour] != 0 and gamemap.owners[neighbour] != gamemap.playerID: # neighbour is enemy
                #     optimal_score = self.score[neighbour] + 100 # just add some score for enemy locations
                #     best_move = move
                if self.score[neighbour] > optimal_score and my_str >= gamemap.strength[neighbour]:
                    # only move if target has better score or target isn't mine
                    if gamemap.owners[neighbour] != gamemap.playerID or self.score[square] < self.score[neighbour]:
                        optimal_score = self.score[neighbour]
                        best_move = move
                        # gamemap.log("updating best move to score " + str(optimal_score) + ", move: " + MOVES_STRINGS[move] + '\n')
            moves.append((square, best_move))
        return moves