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)
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)
def initialisationTurn(mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins): global route, dists_matrix, route_matrix dists_matrix, route_matrix = u.dists_from_each(coins + [playerLocation, opponentLocation], mazeMap)