Example #1
0
def initializationCode (mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :
    t0 = time.time()

    # First we protect ourself from killing
    connard.preventFromKilling ()

    
    # We add global variables
    global METAGRAPH
    global BESTPATHES
    global FORMICMETAGRAPH

    global GLOBALPATH
    global ACTUALPATH
    global GOALLOCATION


    # Let's define global variables
    METAGRAPH, BESTPATHES = th.generateMetaGraph(mazeMap, playerLocation, coins)
    GOALLOCATION = playerLocation
    
    t1 = time.time()
#    ut.timeline ("Computed meta-graph and best pathes", t0, t0, t1)

    # Now let's send a looooot of ants
    FORMICMETAGRAPH = aco.generateFormicMetaGraph (METAGRAPH, playerLocation, (timeAllowed-(t1-t0))*PERCENTTIMEALLOWEDFORANTSBEGINNING)

    
    t2 = time.time()
Example #2
0
def determineNextMove (mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :

    t0 = time.time ()

    # Travel heuristics variables
    global METAGRAPH
    global FORMICMETAGRAPH
    global BESTPATHES

    # Pathes variables
    global GLOBALPATH
    global ACTUALPATH
    global GOALLOCATION

    # General variables
    global MOVING    
    global EATENCOINS

    
    # We update eatenCoins except playerLocation
    EATENCOINS = ut.updateCoinsWoPlayerLoc (METAGRAPH, EATENCOINS, coins, playerLocation)

    if GOALLOCATION in EATENCOINS:
        ACTUALPATH = th.findNearestCoin(mazeMap, playerLocation, coins)
        GOALLOCATION = ACTUALPATH[0]
        api.debug("Thief ! We go there : "+str(GOALLOCATION))
        ACTUALPATH.pop ()

    newMetaGraph = ut.metaGraphWithoutEaten (METAGRAPH, EATENCOINS)


    # Let's send some ant. Not too much
    t1 = time.time ()
    FORMICMETAGRAPH = aco.generateFormicMetaGraph (newMetaGraph, GOALLOCATION, (timeAllowed-(t1-t0)-ESTIMATEDTIMEMAIN)*PERCENTTIMEALLOWEDFORANTS, FORMICMETAGRAPH)

    if MOVING :
        # Plus de chemin ou pièce bouffée, on s'arrete.
        if not ACTUALPATH :
            MOVING = False
            EATENCOINS.append (playerLocation)
    
    if not MOVING :
        # We choose the next coin with aco :
        GOALLOCATION = chooseNextCoins(FORMICMETAGRAPH, playerLocation)[0][0]
        
        # Get next path
        try :
            ACTUALPATH = list (BESTPATHES[playerLocation][GOALLOCATION])
        except KeyError: # The path doesn't exist, let's calculate one:
            ACTUALPATH = sp.shortestWay (mazeMap, playerLocation, GOALLOCATION)
         

        ACTUALPATH.pop () # Get rid of the first position wich should be actualPosition
        MOVING = True

    # Let's go !
    nextPos = ACTUALPATH.pop()
    return ut.convertPosesToDir(nextPos, playerLocation, mazeMap)