コード例 #1
0
def determineNextMove(playerLocation, opponentLocation, coins):
    global route, old_coins, playerScore, enemyScore
    u.update_dists_from_each(dists_matrix, route_matrix, playerLocation, mazeMap, coins)
    u.update_dists_from_each(dists_matrix, route_matrix, opponentLocation, mazeMap, coins + [playerLocation])

    # Calculate our score and en score :
    if playerLocation in old_coins and playerLocation not in coins:
        playerScore += 1
    if opponentLocation in old_coins and opponentLocation not in coins:
        enemyScore += 1

    if len(route) == 0 or route[-1] not in coins or 1==1:
        winning_value, en_best_path, pl_best_path = minmax(coins, playerScore, 0, playerLocation, enemyScore, 0, opponentLocation)
        interface.debug("------------")
        interface.debug(pl_best_path)
        interface.debug(en_best_path)
        interface.debug("score of : " + str(winning_value))
        route = route_matrix[playerLocation][pl_best_path[0]]

    # coins_which_are_close = coins_close(playerLocation, coins, dists_matrix, limit=2)
    # closest_coin = None
    # for coin in coins_which_are_close:
    #     # If we don't already go there, and the enemy is not going there
    #     if dists_matrix[playerLocation][coin] < dists_matrix[opponentLocation][coin]:  # TODO : magic number, same : with the enemy
    #         if closest_coin is None or dists_matrix[playerLocation][coin] < dists_matrix[playerLocation][closest_coin]:
    #             closest_coin = coin
    # if closest_coin is not None:
    #     pass
    #     # route = route_matrix[playerLocation][closest_coin]
    #     # interface.debug("NEAR : " + str(closest_coin))

    old_coins = coins
    next_pos = route.pop(0)
    return u.direction(playerLocation, next_pos)
コード例 #2
0
def determineNextMove(playerLocation, opponentLocation, coins):
    """Function called at each turn, must return the next move of the player"""
    global packages, dists, route_table, best_path, best_weight, current_package

    if playerLocation in current_package:
        current_package.remove(playerLocation)

    i1, i2, j1, j2 = find_players(packages, opponentLocation, playerLocation)
    if i1 >= 0:
        packages[i1].remove(packages[i1][i2])
        if len(packages[i1]) == 0:
            packages.remove(packages[i1])
    if j1 >= 0:
        api.debug(packages[j1])
        packages[j1].remove(packages[j1][j2])
        if len(packages[j1]) == 0:
            packages.remove(packages[j1])

    if opponentLocation in current_package:
        dists, route_table = u.update_dists_from_each(dists, route_table,
                                                      playerLocation, mazeMap,
                                                      coins)
        if len(current_package) > 1:
            current_package.remove(opponentLocation)
        else:
            current_package = packages.pop(0)
        best_weight = float("inf")
        best_path = []
        exhaustive(current_package, playerLocation, [], 0,
                   (route_table, dists))

    if len(best_path) == 0:
        packages = list(
            reversed(
                sorted(
                    packages,
                    key=lambda x:
                    (len(x) + 3) / min([dists[playerLocation][c]
                                        for c in x]))))
        best_weight = float("inf")
        best_path = []
        current_package = packages.pop(0)
        if len(current_package) == 1 and packages != []:
            current_package = current_package + packages.pop(0)
        exhaustive(current_package, playerLocation, [], 0,
                   (route_table, dists))
    return u.direction(playerLocation, best_path.pop(0))
コード例 #3
0
def fill_packages(coins, mazeMap):
    """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]
    api.debug(quart_dist)
    visited = [coins[0]]
    left_coins = coins[:]

    while len(left_coins) != 0:
        meta_current_node = left_coins.pop(0)
        packages[meta_current_node] = [meta_current_node]
        visited.append(meta_current_node)
        while len(visited) != 0:
            current_node = visited.pop(0)
            for c in left_coins:
                if dists[c][current_node] < quart_dist:
                    packages[meta_current_node].append(c)
                    left_coins.remove(c)
                    visited.append(c)

    packages = [packages[p] for p in packages]
    packages = list(
        reversed(
            sorted(packages,
                   key=lambda x:
                   (len(x) + 3) / min([dists[playerLocation][c] for c in x]))))
    for k in range(len(packages)):
        n = len(packages[k])
        if n > 5:
            p1 = packages[k][:n // 2]
            p2 = packages[k][n // 2:]
            if len(p1) > 5:
                p1prime = p1[:len(p1) // 2]
                p1sec = p1[len(p1) // 2:]
                p2prime = p2[:len(p2) // 2]
                p2sec = p2[len(p2) // 2:]
                packages[k] = p1prime
                packages.insert(k + 1, p1sec)
                packages.insert(k + 2, p2prime)
                packages.insert(k + 3, p2sec)
            else:
                packages[k] = p1
                packages.insert(k + 1, p2)
コード例 #4
0
ファイル: packagev2.py プロジェクト: dimtion/jml
def fill_packages(coins, mazeMap):
    """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]
    api.debug(quart_dist)
    visited =[coins[0]]
    left_coins = coins[:]
    
    while len(left_coins) != 0:
        meta_current_node = left_coins.pop(0)
        packages[meta_current_node] = [meta_current_node]
        visited.append(meta_current_node) 
        while len(visited) !=0:
            current_node = visited.pop(0)
            for c in left_coins:
                if dists[c][current_node] < quart_dist:
                    packages[meta_current_node].append(c)
                    left_coins.remove(c)
                    visited.append(c)
                    
    packages = [packages[p] for p in packages]
    packages = list(reversed(sorted(packages, key=lambda x: (len(x)+3)/min([dists[playerLocation][c] for c in x]))))
    for k in range(len(packages)):
        n = len(packages[k])
        if n > 5:
            p1 = packages[k][:n//2]
            p2 = packages[k][n//2:]
            if len(p1)> 5:
                p1prime = p1[:len(p1)//2]
                p1sec = p1[len(p1)//2:]
                p2prime = p2[:len(p2)//2]
                p2sec = p2[len(p2)//2:]
                packages[k] = p1prime
                packages.insert(k+1,p1sec)
                packages.insert(k+2,p2prime)
                packages.insert(k+3,p2sec)   
            else:
                packages[k] = p1
                packages.insert(k+1,p2)              
コード例 #5
0
ファイル: packagev2.py プロジェクト: dimtion/jml
def determineNextMove(playerLocation, opponentLocation, coins):
    """Function called at each turn, must return the next move of the player"""
    global packages, dists, route_table, best_path, best_weight, current_package
    
    if playerLocation in current_package:
        current_package.remove(playerLocation)
        
    i1,i2,j1,j2  = find_players(packages, opponentLocation, playerLocation)
    if i1 >= 0:
        packages[i1].remove(packages[i1][i2])
        if len(packages[i1]) == 0:
            packages.remove(packages[i1])
    if j1 >= 0:
        api.debug(packages[j1])
        packages[j1].remove(packages[j1][j2])
        if len(packages[j1]) == 0:
            packages.remove(packages[j1])
                           
    if opponentLocation in current_package:
        dists, route_table = u.update_dists_from_each(dists, route_table, playerLocation, mazeMap, coins)
        if len(current_package) > 1:
            current_package.remove(opponentLocation)
        else:
            current_package = packages.pop(0)
        best_weight = float("inf")
        best_path = []
        exhaustive(current_package, playerLocation, [], 0, (route_table, dists))
           
    if len(best_path) == 0:
        packages = list(reversed(sorted(packages, key=lambda x: (len(x)+3)/min([dists[playerLocation][c] for c in x]))))
        best_weight = float("inf")
        best_path = []
        current_package = packages.pop(0)
        if len(current_package) == 1 and packages != []:
            current_package = current_package + packages.pop(0)
        exhaustive(current_package, playerLocation, [], 0, (route_table, dists))
    return u.direction(playerLocation, best_path.pop(0))