예제 #1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import interface as api
import utils as u
import algorithms as algo

from time import time
from random import randrange

IAName = "OPT OPTIMISATION"
(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation,
 opponentLocation, coins, gameIsOver) = api.initGame(IAName)
coinsNumber = len(coins) + 1
route = []
old_coins = [playerLocation]


def dists_from_each(locations, maze_map):
    """ Return the dists and routes from each locations
    TODO :
    - Cache routes and dists
    """
    dists_matrix = {l: {} for l in locations}
    routes_matrix = {l: {} for l in locations}

    for i in range(len(locations)):
        l1 = locations[i]
        routing_table, dists_table = algo.dijkstra(maze_map, l1)

        for j in range(i + 1, len(locations)):
예제 #2
0
파일: probas.py 프로젝트: dimtion/jml
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import interface
import utils as u
# import algorithms as algo
import random

# Version 1
# This version is only based on instant distances, doesn't take account 
# for the enemy future movements

IAName = "probas"

(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation, opponentLocation, coins, gameIsOver) = interface.initGame(IAName)
route = []
dists_matrix, route_matrix = [], []
coins_probability = {}
coins_to_get = []
best_weight = float('inf')
best_path = []
def closer_probability(player_location, enemy_location, coins, dists_matrix):
    """Return the probability that the player will get a coin based only on
    the player distance to the coin and the enemy distance to the coin
    return a dictionary coin : probability """
    probabilities = {}
    for coin in coins:
        coin_value = dists_matrix[enemy_location][coin] / float(dists_matrix[enemy_location][coin] + dists_matrix[player_location][coin])
        probabilities[coin] = coin_value
    return probabilities
예제 #3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import interface
import utils as u
# import algorithms as algo
import random

# Version 1
# This version is only based on instant distances, doesn't take account
# for the enemy future movements

IAName = "probas"

(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation,
 opponentLocation, coins, gameIsOver) = interface.initGame(IAName)
route = []
dists_matrix, route_matrix = [], []
coins_probability = {}
coins_to_get = []
best_weight = float('inf')
best_path = []


def closer_probability(player_location, enemy_location, coins, dists_matrix):
    """Return the probability that the player will get a coin based only on
    the player distance to the coin and the enemy distance to the coin
    return a dictionary coin : probability """
    probabilities = {}
    for coin in coins:
        coin_value = dists_matrix[enemy_location][coin] / float(
예제 #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import interface as api
import utils as u
# import algorithms as algo

IAName = "Improved closest"
(mazeWidth, mazeHeight, mazeMap, preparationTime, turnTime, playerLocation, opponentLocation, coins, gameIsOver) = api.initGame(IAName)
coinsNumber = len(coins) + 1
route = []

best_weight = float("inf")
best_path = []
currentcoin = "gfdsf"


def get_n_shortest(n, coins, playerLocation, dist_matrix):
    sorted(coins, key=lambda x: dist_matrix[playerLocation][x])
    return coins[:n]


def exhaustive(left, node, path, weight, coins_graph):
    global best_weight, best_path

    if len(left) == 0:
        if weight < best_weight:
            best_weight = weight
            best_path[:] = path

    else: