def attack(gameState, playerId):
    # Goal: Chase around the opponent, always minimizing the distance between the player and the opponent
    # Use ecl

    from isolation import DebugState  #steal the dbug functions to make math easier

    #Ideally these would be imported somehow
    WIDTH = 11
    HEIGHT = 9

    player_loc = gameState.locs[playerId]
    opp_loc = gameState.locs[1 - playerId]

    #Get locations
    player_xy = DebugState.ind2xy(player_loc)
    opp_xy = DebugState.ind2xy(opp_loc)

    #Calculate the distance
    distance = (player_xy[0] - opp_xy[0])**2 + (player_xy[1] - opp_xy[1])**2

    #Compute a normalization factor
    max_dist = (WIDTH)**2 + (HEIGHT)**2

    #For attack we want to maximize score when distance is minimized
    return ((max_dist - distance) / max_dist
            )  # returns 1 when we are as close as possible to opponent
 def distance(self, state):
     if None in state.locs: return 0
     own_xy = DebugState.ind2xy(state.locs[self.player_id])
     opp_xy = DebugState.ind2xy(state.locs[1 - self.player_id])
     manhattan_distance = abs(own_xy[0] - opp_xy[0]) + abs(own_xy[1] -
                                                           opp_xy[1])
     euclidean_distance = math.sqrt((own_xy[0] - opp_xy[0])**2 +
                                    (own_xy[1] - opp_xy[1])**2)
     return euclidean_distance
def centeredness(gameState, playerId):
    # Goal: Maximize self-centeredness while preferring opponents at the edge
    # Reasoning: In the middle of the board you are more flexible then at the edges
    from isolation import DebugState  #steal the dbug functions to make math easier

    player_loc = gameState.locs[playerId]
    opp_loc = gameState.locs[1 - playerId]

    #Process player location
    player_xy = DebugState.ind2xy(player_loc)
    x_centeredness = 5 - abs(5 - player_xy[0])
    y_centeredness = 4 - abs(4 - player_xy[1])
    player_centeredness = x_centeredness + y_centeredness

    #Process opponent location
    opp_xy = DebugState.ind2xy(opp_loc)
    opp_x_cent = 5 - abs(5 - opp_xy[0])
    opp_y_cent = 4 - abs(4 - opp_xy[1])
    opp_centeredness = opp_x_cent + opp_y_cent

    return player_centeredness - opp_centeredness
def verbose_callback(game_state, action, active_player, active_idx, match_id,
                     time_taken):
    if game_state.ply_count % 2 == 0 or game_state.terminal_test(
    ):  # print every other move, plus endgame
        summary = "\nmatch: {} | move: {} | {:.2f}s | {}({}) => {}".format(
            match_id, game_state.ply_count, time_taken,
            active_player.__class__.__name__, active_idx,
            DebugState.ind2xy(action))
        board = str(DebugState.from_state(game_state))
        print(summary)
        logger.info(summary)
        print(board)
        logger.info(board)
def coward(gameState, playerId):
    from isolation import DebugState  #steal the dbug functions to make math easier

    #Ideally these would be imported somehow
    WIDTH = 11
    HEIGHT = 9

    player_loc = gameState.locs[playerId]
    opp_loc = gameState.locs[1 - playerId]

    #Get locations
    player_xy = DebugState.ind2xy(player_loc)
    opp_xy = DebugState.ind2xy(opp_loc)

    #Calculate the distance
    distance = (player_xy[0] - opp_xy[0])**2 + (player_xy[1] - opp_xy[1])**2

    #Compute a normalization factor
    max_dist = (WIDTH)**2 + (HEIGHT)**2

    #For attack we want to maximize score when distance is minimized
    return ((distance) / max_dist
            )  # returns 1 when we are as far as possible to opponent
			def custom_heuristic(state):
				x1, y1 = DebugState.ind2xy(state.locs[self.player_id])
				#x2, y2 = DebugState.ind2xy(state.locs[1-self.player_id])
				x2, y2 = DebugState.ind2xy(57)
				return -((x2-x1)**2 + (y2-y1)**2)**(1/2)