Exemple #1
0
def determineNextMove(player_location, opponentLocation, coins):
    """Return the next direction"""
    global route, currentcoin, meta_route, best_weight, best_path, coins_to_search
    #the second test prevents the player from going to coins which have been taken by the opponent
    if currentcoin == player_location or opponentLocation in coins_to_search:
        dists_matrix, routes_matrix = u.update_dists_from_each(
            dist_matrix, route_matrix, player_location, mazeMap, coins)

        coins_to_search = get_n_shortest(3, coins, player_location,
                                         dist_matrix)
        ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
        may_be_lost_coins = []
        # Remove from coins_to_search the first coin which is closer to the opponent than to the player
        for c in coins_to_search:
            if len(coins_to_search) >= 2 and ennemy_dists[1][c] < dists_matrix[
                    player_location][c]:
                may_be_lost_coins.append(c)
        if len(may_be_lost_coins) != 0:
            coins_to_search.remove(may_be_lost_coins[0])

        best_weight = float("inf")
        best_path = []
        exhaustive(coins_to_search, player_location, [], 0, dist_matrix)
        meta_route = [player_location] + best_path
        route = u.location_list_to_route(meta_route, route_matrix)
        currentcoin = meta_route[1]

    return u.direction(player_location, route.pop(0))
Exemple #2
0
def determineNextMove(player_location, opponentLocation, coins):
    """Return the next direction"""
    global route, currentcoin, meta_route, best_weight, best_path, coins_to_search
    #the second test prevents the player from going to coins which have been taken by the opponent
    if currentcoin == player_location or opponentLocation in coins_to_search:
        dists_matrix, routes_matrix = u.update_dists_from_each(dist_matrix, route_matrix, player_location, mazeMap, coins)

        coins_to_search = get_n_shortest(3, coins, player_location, dist_matrix)
        ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
        may_be_lost_coins = []
        # Remove from coins_to_search the first coin which is closer to the opponent than to the player
        for c in coins_to_search:
            if len(coins_to_search) >= 2 and ennemy_dists[1][c] < dists_matrix[player_location][c]:
                may_be_lost_coins.append(c)
        if len(may_be_lost_coins) != 0:
            coins_to_search.remove(may_be_lost_coins[0]) 
   
        best_weight = float("inf")
        best_path = []
        exhaustive(coins_to_search, player_location, [], 0, dist_matrix)
        meta_route = [player_location]+best_path
        route = u.location_list_to_route(meta_route, route_matrix)
        currentcoin = meta_route[1]

    return u.direction(player_location, route.pop(0))
Exemple #3
0
def initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, player_location, opponentLocation, coins) :
    """Initialize some variables during the preparation time"""
    global route, currentcoin, meta_route, best_weight, best_path, coins_to_search, index
	#dists_matrix, routes_matrix = u.dists_from_each(coins + [playerLocation], mazeMap)
    coins_to_search = get_n_shortest(5, coins, player_location, dists_matrix)
    best_weight = float("inf")
    best_path = []
    exhaustive(coins_to_search, player_location, [], 0, dists_matrix)
    meta_route = [player_location] + best_path
    route = u.location_list_to_route(meta_route, routes_matrix)
    index = 1
    currentcoin = meta_route[1]
Exemple #4
0
def initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime,
                       turnTime, player_location, opponentLocation, coins):
    """Initialize some variables during the preparation time"""
    global route, currentcoin, meta_route, best_weight, best_path, coins_to_search, index
    #dists_matrix, routes_matrix = u.dists_from_each(coins + [playerLocation], mazeMap)
    coins_to_search = get_n_shortest(5, coins, player_location, dists_matrix)
    best_weight = float("inf")
    best_path = []
    exhaustive(coins_to_search, player_location, [], 0, dists_matrix)
    meta_route = [player_location] + best_path
    route = u.location_list_to_route(meta_route, routes_matrix)
    index = 1
    currentcoin = meta_route[1]
Exemple #5
0
def change_way(coins, opponentLocation, player_location):
    """Return the new coin to search, coin sequence, route and the distance from the player to the first coin of the route"""
    global best_weight, best_path
    dist_matrix, route_matrix = u.update_dists_from_each(dists_matrix, routes_matrix, player_location, mazeMap, coins)
    coins_to_search = get_n_shortest(5, coins, player_location, dists_matrix)
    ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
    for c in coins_to_search:
        if len(coins_to_search) >= 2 and ennemy_dists[1][c] < dists_matrix[player_location][c]:
            coins_to_search.remove(c)
            break
    best_weight = float("inf")
    best_path = []
    api.debug(coins_to_search)
    exhaustive(coins_to_search, player_location, [], 0, dist_matrix)
    meta_route = [player_location] + best_path
    api.debug(meta_route)
    route = u.location_list_to_route(meta_route, route_matrix)
          
    return coins_to_search, meta_route, route, dist_matrix[player_location][meta_route[1]]
Exemple #6
0
def determineNextMove(playerLocation, opponentLocation, coins):
    
    global route, currentcoin, acc
    u.update_dists_from_each(dist_matrix, route_matrix, playerLocation, mazeMap, coins)
    if currentcoin == playerLocation:
        best_weight = float("inf")
        best_path = []
        coins_to_search = get_n_shortest(7, coins, playerLocation, dist_matrix)
        if playerLocation in coin_to_search:
            api.debug(coin_to_search)
            api.debug(playerLocation)
        meta_route = exhaustive(coins_to_search, playerLocation, [] ,0 ,dist_matrix)
        route = u.location_list_to_route(meta_route, route_matrix)
        currentcoin = meta_route[0]
        #if currentcoin == playerLocation:
            #api.debug(meta_route)
            #api.debug(route)
            #acc+=1
            #api.debug(acc)
    return u.direction(playerLocation, route.pop(0))
Exemple #7
0
def change_way(coins, opponentLocation, player_location):
    """Return the new coin to search, coin sequence, route and the distance from the player to the first coin of the route"""
    global best_weight, best_path
    dist_matrix, route_matrix = u.update_dists_from_each(
        dists_matrix, routes_matrix, player_location, mazeMap, coins)
    coins_to_search = get_n_shortest(5, coins, player_location, dists_matrix)
    ennemy_dists = algo.dijkstra(mazeMap, opponentLocation)
    for c in coins_to_search:
        if len(coins_to_search) >= 2 and ennemy_dists[1][c] < dists_matrix[
                player_location][c]:
            coins_to_search.remove(c)
            break
    best_weight = float("inf")
    best_path = []
    api.debug(coins_to_search)
    exhaustive(coins_to_search, player_location, [], 0, dist_matrix)
    meta_route = [player_location] + best_path
    api.debug(meta_route)
    route = u.location_list_to_route(meta_route, route_matrix)

    return coins_to_search, meta_route, route, dist_matrix[player_location][
        meta_route[1]]