Ejemplo n.º 1
0
t = time()
t0 = t
locs = [playerLocation] + coins
if opponentLocation != (-1, -1):
    locs.append(opponentLocation)

dists_matrix, routes_matrix = dists_from_each(locs, mazeMap)
api.debug("Time : " + str(time() - t))

api.debug("Calc init route...")
t = time()
meta_route, meta_route_len = path_from_nearest(playerLocation,
                                               opponentLocation, coins,
                                               dists_matrix)
next_coin = meta_route.pop(0)

api.debug("Time : " + str(time() - t))
api.debug(meta_route_len)

api.debug("Optimising route...")
t = time()
for _ in range(100000):
    meta_route, meta_route_len = opt_algorithm(meta_route, meta_route_len,
                                               dists_matrix)
api.debug("Time : " + str(time() - t))

api.debug("\nTotal : " + str(time() - t0))
api.debug("GO")

api.startGameMainLoop(determineNextMove)
Ejemplo n.º 2
0
            next_coin = coins_to_get.pop(0)

        interface.debug(coins_to_get)
        # coins_to_get.remove(next_coin)

        route = route_matrix[playerLocation][next_coin]

    # In case we pass not far from a coin :
    # Il y a des pièces que l'on pourrait récuperer maintenant ?
    # Une sorte de système de packets
    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 coin not in coins_to_get and 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:
        coins_to_get.insert(0, route[-1])
        route = route_matrix[playerLocation][closest_coin]
        interface.debug("Finally go to : " + str(closest_coin))

    next_pos = route.pop(0)
    return u.direction(playerLocation, next_pos)

# Init our AI
initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime, playerLocation, opponentLocation, coins)

# Starts the game
interface.startGameMainLoop(determineNextMove)
Ejemplo n.º 3
0
    # Il y a des pièces que l'on pourrait récuperer maintenant ?
    # Une sorte de système de packets
    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 coin not in coins_to_get and 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:
        coins_to_get.insert(0, route[-1])
        route = route_matrix[playerLocation][closest_coin]
        interface.debug("Finally go to : " + str(closest_coin))

    next_pos = route.pop(0)
    return u.direction(playerLocation, next_pos)


# Init our AI
initialisationTurn(mazeWidth, mazeHeight, mazeMap, preparationTime,
                   playerLocation, opponentLocation, coins)

# Starts the game
interface.startGameMainLoop(determineNextMove)
Ejemplo n.º 4
0
    all_good_dists, all_good_routes = dists_from_each(coins + [playerLocation], maze_map)
    api.debug(time.time() - t)
    api.debug("Population...")
    population = generate_population(playerLocation, coins, all_good_dists)
    for i in range(TURNS + 1):
        population = update_pop(population, coins, all_good_dists)
        score, route = population[0]
        if i % 100 == 0:
            api.debug("%s : %s" % (i, score))
    api.debug("Start...")
    # return location_list_to_route(route, all_good_routes)


def location_list_to_route(locations, routes_list):
    route = []
    for i in range(len(locations) - 1):
        l1, l2 = locations[i], locations[i+1]
        route += routes_list[l1][l2]
    return route


def determineNextMove(playerLocation, opponentLocation, coins):
    global route
    if len(route) == 0:
        pick_good_coin(playerLocation, coins, coins_dists)
    return u.direction(playerLocation, route.pop(0))

route = init_game(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation, opponentLocation, coins)
# route.pop(0)
api.startGameMainLoop(determineNextMove)