Exemple #1
0
def determineNextMove (mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :
    global MOVING
    global METAGRAPH
    global BESTPATHS
    global EATENCOINS
    global PATH
    
    EATENCOINS = updateCoins(METAGRAPH, EATENCOINS, opponentLocation)
    EATENCOINS = updateCoins(METAGRAPH, EATENCOINS, playerLocation)

    if MOVING :
        if not PATH :
            MOVING = False
    
    if not MOVING :
        nextCoin = chooseCoin(METAGRAPH, playerLocation, EATENCOINS)

        PATH = BESTPATHS[playerLocation][nextCoin]
        PATH.pop()
        
        MOVING = True
    
    nextPos = PATH.pop()

    return ut.convertPosesToDir(nextPos, playerLocation, mazeMap)
Exemple #2
0
def determineNextMove (mazeWidth, mazeHeight, mazeMap, timeAllowed, playerLocation, opponentLocation, coins) :
    global MOVING
    global METAGRAPH
    global BESTPATHS
    global EATENCOINS
    global PATH
    global CURRENTCOIN
    
    EATENCOINS = ut.updateCoins(METAGRAPH, EATENCOINS, coins)

    if MOVING :
        if not PATH :
            MOVING = False
        
        if opponentLocation == CURRENTCOIN and playerLocation != CURRENTCOIN:
            PATH = []
            PATH = th.findNearestCoin(mazeMap, playerLocation, coins)
    
    if not MOVING :
        CURRENTCOIN = chooseCoin(METAGRAPH, playerLocation, EATENCOINS)

        PATH = list(BESTPATHS[playerLocation][CURRENTCOIN])
        PATH.pop()
        
        MOVING = True
    
    nextPos = PATH.pop()

    return ut.convertPosesToDir(nextPos, playerLocation, mazeMap)
Exemple #3
0
def determineNextMove(mazeWidth, mazeHeight, mazeMap, timeAllowed,
                      playerLocation, opponentLocation, coins):
    global MOVING
    global METAGRAPH
    global BESTPATHS
    global EATENCOINS
    global PATH
    global CURRENTCOIN

    EATENCOINS = updateCoins(METAGRAPH, EATENCOINS, opponentLocation)
    EATENCOINS = updateCoins(METAGRAPH, EATENCOINS, playerLocation)

    if MOVING:
        if not PATH:
            MOVING = False

        if opponentLocation == CURRENTCOIN and playerLocation != CURRENTCOIN:
            PATH = []
            PATH = th.findNearestCoin(mazeMap, playerLocation, coins)

    if not MOVING:
        CURRENTCOIN = chooseCoin(METAGRAPH, playerLocation, EATENCOINS)

        PATH = BESTPATHS[playerLocation][CURRENTCOIN]
        PATH.pop()

        MOVING = True

    nextPos = PATH.pop()

    return ut.convertPosesToDir(nextPos, playerLocation, mazeMap)
Exemple #4
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)