Exemplo n.º 1
0
def initialisationTurn(mazeWidth, mazeHeight, maze_map, timeAllowed,
                       playerLocation, opponentLocation, coins):
    global dists_matrix, route_matrix, coins_probability, coins_to_get
    dists_matrix, route_matrix = u.dists_from_each(
        coins + [playerLocation, opponentLocation], maze_map)
    coins_probability = get_probability_coins(playerLocation,
                                              opponentLocation,
                                              coins,
                                              dists_matrix,
                                              tests=100)
    interface.debug(coins_probability)

    # First : we go to the 11 in the middle
    coins_phase1 = [
        coin for coin in coins if coins_probability[coin]['player1'] > .6
    ]
    sorted(coins_phase1,
           key=lambda x: coins_probability[x]['player1'],
           reverse=False)
    coins_to_get = coins_phase1[:10]

    coins_to_get = voyageur_commerce(playerLocation, coins_to_get,
                                     dists_matrix)

    # Then we get to the ones close to us :
    # coins_phase2 = coins_phase1[7:16]
    # coins_phase2 = voyageur_commerce(coins_phase1[-1], coins_phase2, dists_matrix)

    # coins_to_get += coins_phase2
    interface.debug(len(coins_to_get))
    interface.debug(coins_to_get)
Exemplo n.º 2
0
def initialisationTurn(mazeWidth, mazeHeight, maze_map, timeAllowed, playerLocation, opponentLocation, coins):
    global dists_matrix, route_matrix, coins_probability, coins_to_get
    dists_matrix, route_matrix = u.dists_from_each(coins + [playerLocation, opponentLocation], maze_map)
    coins_probability = get_probability_coins(playerLocation, opponentLocation, coins, dists_matrix, tests=100)
    interface.debug(coins_probability)

    # First : we go to the 11 in the middle
    coins_phase1 = [coin for coin in coins if coins_probability[coin]['player1'] > .6]
    sorted(coins_phase1, key=lambda x: coins_probability[x]['player1'], reverse=False)
    coins_to_get = coins_phase1[:10]

    coins_to_get = voyageur_commerce(playerLocation, coins_to_get, dists_matrix)


    # Then we get to the ones close to us :
    # coins_phase2 = coins_phase1[7:16]
    # coins_phase2 = voyageur_commerce(coins_phase1[-1], coins_phase2, dists_matrix)

    # coins_to_get += coins_phase2
    interface.debug(len(coins_to_get))
    interface.debug(coins_to_get)
Exemplo n.º 3
0
def fill_packages(coins):
    """Fill packages, also create the route table from any coin to any coin """
    global packages, route_table, dists
    used = []
    dists, route_table = u.dists_from_each(coins + [playerLocation], mazeMap)
    dists_list = sorted([d for di in dists for d in di])
    quart_dist = dists_list[len(dists_list) // 4]
    for c in coins:
        for k in coins:
            if dists[c][
                    k] < quart_dist and k not in used and c not in used and k != c:
                used.append(c)
                used.append(k)
                packages[c] = [c]
                packages[c].append(k)
    for c in coins:
        if c not in used:
            packages[c] = [c]
    packages = [packages[p] for p in packages]
    packages = sorted(packages,
                      key=lambda x: len(x) / dists[playerLocation][x[0]])
    api.debug(packages)
Exemplo n.º 4
0
def initialisationTurn(mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins):
    global route, dists_matrix, route_matrix
    # route = next_way(playerLocation, coins)
    dists_matrix, route_matrix = u.dists_from_each(coins + [playerLocation, opponentLocation], mazeMap)
Exemplo n.º 5
0
def initialisationTurn(mazeWidth, mazeHeight, mazeMap, timeAllowed,
                       playerLocation, opponentLocation, coins):
    global route, dists_matrix, route_matrix
    # route = next_way(playerLocation, coins)
    dists_matrix, route_matrix = u.dists_from_each(
        coins + [playerLocation, opponentLocation], mazeMap)
Exemplo n.º 6
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))

dist_matrix, route_matrix = u.dists_from_each(coins + [playerLocation], mazeMap)
coins_to_search = [opponentLocation]

api.startGameMainLoop(determineNextMove)
Exemplo n.º 7
0
    """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]]


dists_matrix, routes_matrix = u.dists_from_each(coins + [playerLocation],
                                                mazeMap)
old_dists = dists_matrix
initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime,
                   playerLocation, opponentLocation, coins)

api.startGameMainLoop(determineNextMove)