Exemplo n.º 1
0
def updateDirectionOfOthersTowardsLineOnly(PARAMS, GLOBALVARS):
    for keyID, mySquaresDict in PARAMS.allMySquares.items():
        if mySquaresDict['expanding_Distance'] == 0 and mySquaresDict[
                'currentsquare'].strength > GLOBALVARS.minSquareStrengthBeforeMovingMiddleINITLine:

            if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, keyID,
                                               GLOBALVARS.directions):
                if GLOBALVARS.directions[keyID] == None:
                    GLOBALVARS.initExpand = False
                else:
                    # PARAMS.allMySquares[keyID]['direction'] = DIR.getDirection(GLOBALVARS,mySquaresDict['currentsquare'], GLOBALVARS.directions[keyID])

                    #####Get direction of our closest square towards the final target
                    square = mySquaresDict['currentsquare']
                    sortedSquaresList = reversed(
                        copy.copy(GLOBALVARS.bestLineOfAttackList))
                    for neighbor in sortedSquaresList:
                        neighborID = FUNC.getID(neighbor)
                        if FUNC.getIsTargetMine(
                                PARAMS,
                                neighborID) and FUNC.getIsTargetANeighbor(
                                    PARAMS, GLOBALVARS, square, neighborID):
                            PARAMS.allMySquares[keyID][
                                'direction'] = DIR.getDirection(
                                    GLOBALVARS, square, neighbor)

                            #####check if it has enemy next to target
                            hasEnemy, enemyList, numOfenemies = FUNC.hasEnemyNeighbor(
                                PARAMS, GLOBALVARS, neighbor)
                            if hasEnemy:
                                GLOBALVARS.hasEnemyBeenDetected = True
                                PARAMS.allMySquares[keyID]['direction'] = STILL
                            break
Exemplo n.º 2
0
def setDirectionsForExpandingTargetLine(PARAMS, GLOBALVARS):
    for targetID, dictionary in PARAMS.neutralExpandingTargets.items():
        if dictionary['moveSquareWithDistance'] == 0:
            doing = None
        else:
            moveSquareWithDistanceID = dictionary['moveSquareWithDistance']

            for distanceID, squareList in dictionary['expandingSquares'].items(
            ):
                if distanceID == moveSquareWithDistanceID:
                    for square in squareList:

                        ID = FUNC.getID(square)
                        if FUNC.getIsTargetMine(PARAMS, ID):
                            targetSquare = PARAMS.allMySquares[ID][
                                'expanding_NextSquare']

                            if PARAMS.allMySquares[ID][
                                    'currentsquare'].strength == 0:
                                PARAMS.allMySquares[ID]['direction'] = STILL

                            else:
                                directionMovement = DIR.getDirection(
                                    GLOBALVARS, square, targetSquare)
                                PARAMS.allMySquares[ID][
                                    'direction'] = directionMovement

                                #####check if it has enemy next to target
                                hasEnemy, enemyList, numOfenemies = FUNC.hasEnemyNeighbor(
                                    PARAMS, GLOBALVARS, targetSquare)
                                if hasEnemy:
                                    GLOBALVARS.hasEnemyBeenDetected = True
                                    PARAMS.allMySquares[ID][
                                        'direction'] = STILL
Exemplo n.º 3
0
def copyPreviousNeutralTargets(PARAMS, GLOBALVARS, mainTargetID, mainTarget):
    takeOldData = False
    numOldSquaresAccounted = 0
    #####see if it exist in previous data
    if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, mainTargetID, GLOBALVARS.OLDPARAMS.neutralExpandingTargets):
        oldDict = GLOBALVARS.OLDPARAMS.neutralExpandingTargets[mainTargetID]
        if oldDict['moveSquareWithDistance'] == 0 or oldDict['moveSquareWithDistance'] == 1:
            doing = None
        else:
            lostExpandingSquares = checkIfAnyExpandingSquaresTaken(PARAMS,GLOBALVARS,oldDict['expandingSquares'])

            if lostExpandingSquares == False:
                #####Copy previous data minus 1
                takeOldData = True
                newMoveSquareDistance = oldDict['moveSquareWithDistance'] - 1
                neutralTemplate = D.NeutralTargetTemplate(mainTargetID,mainTarget,newMoveSquareDistance)
                PARAMS.neutralExpandingTargets[mainTargetID] = neutralTemplate.dict

                #####Copy Old Attacking Squares minus the one that moved before
                for distanceID, listOfSquares in oldDict['expandingSquares'].items():
                    if int(distanceID) <= newMoveSquareDistance:
                        PARAMS.neutralExpandingTargets[mainTargetID]['expandingSquares'][distanceID] = []

                        for square in listOfSquares:
                            squareID = FUNC.getID(square)
                            PARAMS.neutralExpandingTargets[mainTargetID]['expandingSquares'][distanceID].append(square)
                            numOldSquaresAccounted = numOldSquaresAccounted + 1
                            PARAMS.allMySquares[squareID]["expanding_Distance"] = copy.copy(int(distanceID))
                            PARAMS.allMySquares[squareID]["expanding_NextSquare"] = copy.copy(GLOBALVARS.OLDPARAMS.allMySquares[squareID]["expanding_NextSquare"])
                            PARAMS.allMySquares[squareID]["expanding_TargetSquare"] = copy.copy(mainTarget)

    return takeOldData, numOldSquaresAccounted
Exemplo n.º 4
0
def setDirectionsInParamsOpening(PARAMS,GLOBALVARS):
    for targetID, dictionary in PARAMS.neutralExpandingTargets.items():
        if dictionary['moveSquareWithDistance'] == 0:
            doing = None
        else:
            moveSquareWithDistanceID = dictionary['moveSquareWithDistance']

            for distanceID, squareList in dictionary['expandingSquares'].items():
                if distanceID == moveSquareWithDistanceID:
                    for square in squareList:

                        ID = FUNC.getID(square)
                        if FUNC.getIsTargetMine(PARAMS, ID):
                            targetSquare = PARAMS.allMySquares[ID]['expanding_NextSquare']

                            if PARAMS.allMySquares[ID]['currentsquare'].strength == 0:
                                PARAMS.allMySquares[ID]['direction'] = STILL

                            elif PARAMS.allMySquares[ID]['enemy_Distance'] > 0 or PARAMS.allMySquares[ID]['enemy_Distance-1'] > 0:
                                #####Do not change its direction, handled by attack direction
                                doing = None
                            elif PARAMS.allMySquares[ID]['fakeEnemy_Distance'] > 0:
                                #####Do not change its direction, handled by attack direction
                                doing = None
                            else:
                                targetSquare = PARAMS.allMySquares[ID]['expanding_NextSquare']
                                directionMovement = DIR.getDirection(GLOBALVARS,square,targetSquare)
                                PARAMS.allMySquares[ID]['direction'] = directionMovement
Exemplo n.º 5
0
def setExpandingTarget(PARAMS, GLOBALVARS, mainTarget, Target, distanceNum, numOfSquares):
    mainTargetID = FUNC.getID(mainTarget)
    if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, mainTargetID, PARAMS.neutralExpandingTargets):
        #####exist already
        return 0
    else:
        #####doesnt exist yet
        moveDistance = 0
        neutralTemplate = D.NeutralTargetTemplate(mainTargetID, mainTarget, moveDistance)
        PARAMS.neutralExpandingTargets[mainTargetID] = neutralTemplate.dict
        numSqueresAccounted = setDistanceFromNeutral(PARAMS, GLOBALVARS,mainTarget, mainTargetID, Target, distanceNum,numOfSquares)
        return numSqueresAccounted
Exemplo n.º 6
0
def manageOverStrengthDirectionSelfTargets(PARAMS):
    newOneJustSet = False
    sortedList = reversed(
        sorted(PARAMS.allMySquaresList, key=lambda x: x.strength))

    for sq in sortedList:
        origID = FUNC.getID(sq)
        mySquaresDict = PARAMS.allMySquares[origID]

        if mySquaresDict['temp_selftarget'] == True:
            mySquaresDict['temp_selftarget'] = False
            origSquare = mySquaresDict['currentsquare']
            totalStrength = copy.copy(mySquaresDict['currentsquare'].strength)
            neighbors = mySquaresDict['neighbors']

            #####find all that have the same target
            for directionKey, neighborDict in neighbors.items():
                neighborID = FUNC.getID(neighborDict['square'])

                if FUNC.getIsTargetMine(PARAMS, neighborID):
                    #####if neighbor's target is origID
                    if PARAMS.allMySquares[neighborID][
                            'temp_selftarget'] == False and PARAMS.allMySquares[
                                neighborID]['actual_TowardID'] == origID:
                        neighborTargetStrength = PARAMS.allMySquares[
                            neighborID]['currentsquare'].strength
                        targetID = PARAMS.allMySquares[neighborID][
                            'actual_TowardID']

                        if (totalStrength +
                                neighborTargetStrength) <= PARAMS.maxStrength:
                            #####not going over, leave it alone
                            totalStrength = totalStrength + neighborTargetStrength
                            #####to prevent swapping in the future
                            PARAMS.managedDontSwapAnymoreID.append(targetID)
                        else:
                            #####Going over, change neighbors direction to STILL
                            PARAMS.allMySquares[neighborID][
                                'direction'] = STILL
                            PARAMS.allMySquares[neighborID][
                                'possibleSwap'] = True
                            PARAMS.allMySquares[neighborID][
                                'temp_selftarget'] = True

                            PARAMS.allMySquares[neighborID][
                                'actual_TowardID'] = copy.copy(neighborID)
                            newOneJustSet = True

    #####if new one was set above, need to run again
    if newOneJustSet == True:
        manageOverStrengthDirectionSelfTargets(PARAMS)
Exemplo n.º 7
0
def setDistanceForExpandingTargetLine(PARAMS, GLOBALVARS,
                                      totalNumSquaresAccounted):
    #####Iterate through neutrals, highest priority first, until all our squares are accounted for
    squaresList = copy.copy(GLOBALVARS.bestLineOfAttackList)
    for square in squaresList:
        if totalNumSquaresAccounted < len(PARAMS.allMySquares):
            id = FUNC.getID(square)
            if FUNC.getIsTargetNeutral(PARAMS, id):
                neutralList = [square]
                mainTarget = neutralList[0]
                distanceNum = 1
                numOfSquares = 0
                totalNumSquaresAccounted = totalNumSquaresAccounted + EXP.setExpandingTarget(
                    PARAMS, GLOBALVARS, mainTarget, neutralList, distanceNum,
                    numOfSquares)
Exemplo n.º 8
0
def manageOverStrengthDirectionSwapPosition(PARAMS, GLOBALVARS):
    sortedList = reversed(
        sorted(PARAMS.allMySquaresList, key=lambda x: x.strength))

    for sq in sortedList:
        origID = FUNC.getID(sq)
        mySquaresDict = PARAMS.allMySquares[origID]
        origSquare = mySquaresDict['currentsquare']
        origDesiredTargetID = mySquaresDict['desired_TowardID']

        if FUNC.getIsTargetMine(PARAMS, origDesiredTargetID):
            desiredTargetSquare = PARAMS.allMySquares[origDesiredTargetID][
                "currentsquare"]
            #####not yet swapped
            #####only swap full strength

            #####removing check of if its max strength
            if mySquaresDict['possibleSwap'] == True \
                    and origID not in PARAMS.managedDontSwapAnymoreID \
                    and origDesiredTargetID not in PARAMS.managedDontSwapAnymoreID:

                if desiredTargetSquare.strength < origSquare.strength:
                    #####sometimes production doesnt show up in strength even though strength is that
                    if (desiredTargetSquare.strength +
                            desiredTargetSquare.production) + (
                                origSquare.strength +
                                origSquare.production) > 255:
                        #####swap position
                        #####add id to swappedSquaresID list
                        PARAMS.managedDontSwapAnymoreID.append(origID)
                        PARAMS.managedDontSwapAnymoreID.append(
                            origDesiredTargetID)
                        PARAMS.allMySquares[origID][
                            'direction'] = DIR.getDirection(
                                GLOBALVARS, origSquare, desiredTargetSquare)
                        PARAMS.allMySquares[origDesiredTargetID][
                            'direction'] = DIR.getDirection(
                                GLOBALVARS, desiredTargetSquare, origSquare)
                    else:
                        #####combine
                        PARAMS.managedDontSwapAnymoreID.append(origID)
                        PARAMS.managedDontSwapAnymoreID.append(
                            origDesiredTargetID)
                        PARAMS.allMySquares[origID][
                            'direction'] = DIR.getDirection(
                                GLOBALVARS, origSquare, desiredTargetSquare)
                        PARAMS.allMySquares[origDesiredTargetID][
                            'direction'] = STILL
Exemplo n.º 9
0
def reachedLastSquareInLine(PARAMS, GLOBALVARS):
    for keyID, mySquaresDict in PARAMS.allMySquares.items():
        if mySquaresDict['expanding_Distance'] == 0:
            if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, keyID,
                                               GLOBALVARS.directions):
                if GLOBALVARS.directions[keyID] == None:
                    GLOBALVARS.initExpand = False
Exemplo n.º 10
0
def getSquaresInfo(PARAMS, GLOBALVARS):
    #####get all your squares data including:
    #####neighbors, neighbors priority, and neutrals in front line
    for square in GLOBALVARS.game_map:
        id = FUNC.getID(square)

        if square.owner == PARAMS.myID:
            PARAMS.allMySquaresList.append(square)
            mySquares = D.MySquaresTemplate()
            PARAMS.allMySquares[id] = mySquares.dict
            PARAMS.allMySquares[id]['currentsquare'] = square
            PARAMS.allMySquares[id][
                'neighbors'] = getNeutralSquaresInTheBorderWithPriority(
                    PARAMS, GLOBALVARS, square)

        elif square.owner == 0:
            PARAMS.allNeutralSquaresList.append(square)
            neutralSquare = D.NeutralTemplate()
            PARAMS.allNeutralSquares[id] = neutralSquare.dict
            PARAMS.allNeutralSquares[id]['currentsquare'] = square
            try:
                PARAMS.allNeutralSquares[id][
                    'ratio'] = square.production / square.strength
            except:
                #####if strength = 0
                PARAMS.allNeutralSquares[id]['ratio'] = square.production / 1.0

        else:
            #####Enemy Squares
            doing = None
Exemplo n.º 11
0
def getSquaresInfo(GLOBALVARS, myID):
    for square in GLOBALVARS.game_map:
        id = FUNC.getID(square)
        #####Getting info of all squares
        neutralSquare = D.StartingNeutralTemplate()
        GLOBALVARS.starting_AllSquares[id] = neutralSquare.dict
        GLOBALVARS.starting_AllSquares[id]['currentsquare'] = square
        try:
            GLOBALVARS.starting_AllSquares[id][
                'ratio'] = square.production / square.strength
        except:
            #####strength = 0
            GLOBALVARS.starting_AllSquares[id][
                'ratio'] = square.production / 1.0
        GLOBALVARS.starting_AllSquares[id]['areaRatio'] = getAreaRatio(
            GLOBALVARS, square, myID)

        if square.owner == 0:
            neutralSquare = D.StartingNeutralTemplate()
            GLOBALVARS.starting_NeutralSquares[id] = neutralSquare.dict
            GLOBALVARS.starting_NeutralSquares[id]['currentsquare'] = square
            GLOBALVARS.starting_NeutralSquares[id]['ratio'] = copy.copy(
                GLOBALVARS.starting_AllSquares[id]['ratio'])
            GLOBALVARS.starting_NeutralSquares[id]['areaRatio'] = copy.copy(
                GLOBALVARS.starting_AllSquares[id]['areaRatio'])
        elif square.owner == myID:
            GLOBALVARS.starting_MySquare = square
        else:
            GLOBALVARS.starting_EnemySquares[id] = square
Exemplo n.º 12
0
def getAreaRatio(PARAMS, GLOBALVARS, currentsquare):
    if GLOBALVARS.useINITAreaRatio == True:
        #####New way, just get from initialized value
        currentsquareID = FUNC.getID(currentsquare)
        return GLOBALVARS.starting_AllSquares[currentsquareID]['areaRatio']
    else:
        #####Old way, calculated per turn
        nextNeighbors = GLOBALVARS.game_map.neighbors(
            currentsquare, n=PARAMS.neutralRatioArea, include_self=True)
        numSquares = 0
        totalRatio = 0
        for neighbor in nextNeighbors:
            if neighbor.owner == 0 or neighbor.owner != PARAMS.myID:
                numSquares = numSquares + 1
                try:
                    #newRatio = ((neighbor.production) / neighbor.strength) + (neighbor.production/250)
                    newRatio = ((neighbor.production) / neighbor.strength)
                except:
                    #####if strength = 0
                    newRatio = (neighbor.production) / 1
                totalRatio = totalRatio + newRatio

        areaRatio = totalRatio / numSquares

        return areaRatio
Exemplo n.º 13
0
def getDirectionNotOurSquare3(PARAMS, GLOBALVARS, currentsquare):
    closestNeutralDistance = min(GLOBALVARS.game_map.width,
                                 GLOBALVARS.game_map.height) / 2
    closestEnemyDistance = min(GLOBALVARS.game_map.width,
                               GLOBALVARS.game_map.height) / 2
    directionToEnemy = None
    directionToNeutral = None
    neutralList = []
    NeutralSquare = namedtuple('NeutralSquare',
                               'currentsquare areaRatio direction')

    for direction in (NORTH, EAST, SOUTH, WEST):
        distanceToNeutral = 0
        distanceToEnemy = 0
        currentSquareForNeutral = copy.copy(currentsquare)
        currentSquareForEnemy = copy.copy(currentsquare)

        #####Will never reach enemy since it'll be neutral with 0 first
        while (currentSquareForNeutral.owner == PARAMS.myID and distanceToNeutral < closestNeutralDistance) or \
                ((currentSquareForEnemy.owner == PARAMS.myID or (currentSquareForEnemy.owner ==  0 and currentSquareForEnemy.strength == 0)) and distanceToEnemy < closestEnemyDistance):
            if currentSquareForNeutral.owner == PARAMS.myID and distanceToNeutral < closestNeutralDistance:
                distanceToNeutral = distanceToNeutral + 1
                currentSquareForNeutral = GLOBALVARS.game_map.get_target(
                    currentSquareForNeutral, direction)
            if (currentSquareForEnemy.owner == PARAMS.myID or
                (currentSquareForEnemy.owner == 0
                 and currentSquareForEnemy.strength
                 == 0)) and distanceToEnemy < closestEnemyDistance:
                distanceToEnemy = distanceToEnemy + 1
                currentSquareForEnemy = GLOBALVARS.game_map.get_target(
                    currentSquareForEnemy, direction)

        if currentSquareForNeutral.owner == 0:
            #####Found neutral
            currentSquareForNeutralID = FUNC.getID(currentSquareForNeutral)
            areaRatio = GLOBALVARS.starting_AllSquares[
                currentSquareForNeutralID]['areaRatio']
            newSquare = NeutralSquare(currentSquareForNeutral, areaRatio,
                                      direction)
            neutralList.append(newSquare)

        if currentSquareForEnemy.owner != 0 and currentSquareForEnemy.owner != PARAMS.myID and distanceToEnemy < closestEnemyDistance:
            #####Found Enemy
            directionToEnemy = direction
            closestEnemyDistance = distanceToEnemy

    if directionToEnemy is not None:
        finalDirection = directionToEnemy
    elif neutralList != []:
        highTolow = reversed(sorted(neutralList, key=lambda x: x.areaRatio))

        for item in highTolow:
            finalDirection = item.direction
            break
    else:
        finalDirection = random.choice((NORTH, EAST))

    return finalDirection
Exemplo n.º 14
0
def setPreviousDistanceFromEnemy(PARAMS, GLOBALVARS, key, mySquaresDict):
    square = mySquaresDict['currentsquare']
    id = FUNC.getID(square)
    try:
        PARAMS.allMySquares[id][
            'enemy_Distance-1'] = GLOBALVARS.OLDPARAMS.allMySquares[id][
                'enemy_Distance']
    except:
        #####That id didnt exist in oldparams
        PARAMS.allMySquares[id]['enemy_Distance-1'] = 0
Exemplo n.º 15
0
def checkIfAnyExpandingSquaresTaken(PARAMS,GLOBALVARS,attackingDict):
    takenSomewhereElse = False

    for distanceID, listOfSquares in attackingDict.items():
        for sq in listOfSquares:
            sqID = FUNC.getID(sq)
            if sqID in PARAMS.deletedFromExpandingSquaresID:
                takenSomewhereElse = True
                return takenSomewhereElse
    return takenSomewhereElse
Exemplo n.º 16
0
def setDirections(GLOBALVARS):
    allSquaresList = copy.copy(GLOBALVARS.bestLineOfAttackList)
    itemNum = 0
    for squares in allSquaresList:
        squaresID = FUNC.getID(squares)
        try:
            nextSquare = allSquaresList[itemNum + 1]
        except:
            nextSquare = None
        GLOBALVARS.directions[squaresID] = nextSquare
        itemNum = itemNum + 1
Exemplo n.º 17
0
def setDistanceFromEnemy(PARAMS, GLOBALVARS, neutralFrontLine, distanceNum):
    _distanceNum = copy.copy(distanceNum)
    _neutralFrontLine = copy.copy(neutralFrontLine)

    for sq in _neutralFrontLine:
        ####get enemy square
        nextNeighbors1 = GLOBALVARS.game_map.neighbors(sq,
                                                       n=1,
                                                       include_self=False)
        enemySquare = None

        for _neighbor in nextNeighbors1:
            if _neighbor.owner != PARAMS.myID and _neighbor.owner != 0:
                enemySquare = copy.copy(_neighbor)
                break

        newNeutralFrontLine = []
        nextNeighbors2 = GLOBALVARS.game_map.neighbors(sq,
                                                       n=1,
                                                       include_self=False)

        for neighbor in nextNeighbors2:
            if neighbor.owner == PARAMS.myID:
                id = FUNC.getID(neighbor)
                if PARAMS.allMySquares[id][
                        "enemy_Distance"] == 0 or PARAMS.allMySquares[id][
                            "enemy_Distance"] > _distanceNum:
                    #####lower enemy distance found
                    PARAMS.allMySquares[id]["enemy_Distance"] = _distanceNum
                    PARAMS.allMySquares[id]["enemy_NextSquare"] = sq
                    PARAMS.allMySquares[id]["enemy_TargetSquare"] = copy.copy(
                        enemySquare)
                    newNeutralFrontLine.append(neighbor)

                    if id not in PARAMS.accountedIDsToAttack:
                        PARAMS.accountedIDsToAttack.append(copy.copy(id))

                    if id not in PARAMS.deletedFromExpandingSquaresID:
                        PARAMS.deletedFromExpandingSquaresID.append(
                            copy.copy(id))

            elif neighbor.owner == 0 and neighbor.strength == 0:
                newNeutralFrontLine.append(neighbor)
            else:
                doing = None

        if _distanceNum == copy.copy(PARAMS.callForBackupNum):
            return
        else:
            setDistanceFromEnemy(PARAMS, GLOBALVARS, newNeutralFrontLine,
                                 _distanceNum + 1)
Exemplo n.º 18
0
def swap2with1(PARAMS, GLOBALVARS):
    for origID, mySquaresDict in PARAMS.allMySquares.items():

        if mySquaresDict['enemy_Distance'] == 2:
            nextSquare = mySquaresDict['enemy_NextSquare']
            nextSquareID = FUNC.getID(nextSquare)
            nextSquareIsOurs = FUNC.getIsTargetMine(PARAMS, nextSquareID)

            if nextSquareIsOurs \
                    and PARAMS.allMySquares[nextSquareID]['pushedForEvading'] == False \
                    and nextSquareID not in PARAMS.managedDontSwapAnymoreID \
                    and PARAMS.allMySquares[nextSquareID]['accountedForEvading'] == False \
                    and PARAMS.allMySquares[origID]['currentsquare'].strength > 100 \
                    and PARAMS.allMySquares[nextSquareID]['currentsquare'].strength < PARAMS.minSquareStrengthBeforeMoving  \
                    and PARAMS.allMySquares[nextSquareID]['attackPower'] - PARAMS.allMySquares[nextSquareID]['currentsquare'].strength + PARAMS.allMySquares[origID]['currentsquare'].strength < PARAMS.maxStrength:

                #####swap 2 with 1
                PARAMS.managedDontSwapAnymoreID.append(origID)
                PARAMS.managedDontSwapAnymoreID.append(nextSquareID)
                PARAMS.allMySquares[origID]['direction'] = DIR.getDirection(
                    GLOBALVARS, mySquaresDict['currentsquare'], nextSquare)
                PARAMS.allMySquares[nextSquareID][
                    'direction'] = DIR.getDirection(
                        GLOBALVARS, nextSquare, mySquaresDict['currentsquare'])
Exemplo n.º 19
0
def getPriorityForNeighborsDictArea(PARAMS, GLOBALVARS, neighbor):
    if neighbor.owner == 0:
        if neighbor.strength == 0:
            #####neutral with no strength, check its neighbors
            nextNeighbors = GLOBALVARS.game_map.neighbors(neighbor,
                                                          n=1,
                                                          include_self=False)
            enemies = 0
            neutrals = 0
            allies = 0
            for sq in nextNeighbors:
                if sq.owner == 0:
                    neutrals = neutrals + 1
                elif sq.owner == PARAMS.myID:
                    allies = allies + 1
                else:
                    neighborID = FUNC.getID(neighbor)
                    #####its an enemy square, this neutral is in the front line
                    PARAMS.neutralSquaresInFrontLine.append(neighbor)
                    PARAMS.neutralSquaresInFrontLineIDs.append(neighborID)
                    GLOBALVARS.hasEnemyBeenEngaged = True
                    enemies = enemies + 1

            if enemies == 3:
                return (40 + getAreaRatio(PARAMS, GLOBALVARS, neighbor))
            elif enemies == 2:
                return (30 + getAreaRatio(PARAMS, GLOBALVARS, neighbor))
            elif enemies == 1:
                return (20 + getAreaRatio(PARAMS, GLOBALVARS, neighbor))
            else:
                if neighbor.production > 0:
                    return (10 + getAreaRatio(PARAMS, GLOBALVARS, neighbor))
                else:
                    return -0.75

        else:
            priority = getAreaRatio(PARAMS, GLOBALVARS, neighbor)
            # priority = getBestLineRatio(params, neighbor)
            if priority == 0:
                return -0.75
            else:
                return float(priority)

    else:
        #####Can only be our square
        return -1.00
Exemplo n.º 20
0
def setDistanceFromNeutral(PARAMS, GLOBALVARS, mainTarget, mainTargetID, Target, distanceNum, numOfSquares):
    currentDistance = copy.copy(distanceNum)
    _Target = copy.copy(Target)
    PARAMS.neutralExpandingTargets[mainTargetID]['expandingSquares'][currentDistance] = []
    isEnough = False
    almostEnough = False

    for sq in _Target:
        newTarget = []
        noneLeft = True
        nextNeighbors = GLOBALVARS.game_map.neighbors(sq, n=1, include_self=False)
        for neighbor in nextNeighbors:
            if neighbor.owner == PARAMS.myID:
                id = FUNC.getID(neighbor)
                if PARAMS.allMySquares[id]["expanding_Distance"] == 0 and PARAMS.allMySquares[id]['enemy_Distance'] == 0 and PARAMS.allMySquares[id]['fakeEnemy_Distance'] == 0:

                    if PARAMS.allMySquares[id]['currentsquare'].strength < PARAMS.forceMinStrengthForExpanding:
                        #####Dont take into account, skip
                        doing = None
                    else:
                        #####If distance is not 0, this square has been taken into account already
                        PARAMS.allMySquares[id]["expanding_Distance"] = currentDistance
                        PARAMS.allMySquares[id]["expanding_NextSquare"] = sq
                        PARAMS.allMySquares[id]["expanding_TargetSquare"] = mainTarget
                        newTarget.append(neighbor)
                        numOfSquares = numOfSquares + 1
                        noneLeft = False
                        PARAMS.neutralExpandingTargets[mainTargetID]['expandingSquares'][currentDistance].append(neighbor)
                        isEnough, almostEnough = checkIfAttackingUnitsAreEnough(PARAMS, GLOBALVARS, mainTarget, mainTargetID,numOfSquares, currentDistance)

                        if isEnough == True:
                            PARAMS.neutralExpandingTargets[mainTargetID]['moveSquareWithDistance'] = copy.copy(currentDistance)
                            break
                        elif almostEnough == True:
                            #####This ID (distance) wont have any attacking squares, but will be moved next turn
                            PARAMS.neutralExpandingTargets[mainTargetID]['moveSquareWithDistance'] = (currentDistance+1)
                            break
                        else:
                            doing = None

    if isEnough == False and noneLeft == False:
        numOfSquares = setDistanceFromNeutral(PARAMS,GLOBALVARS, mainTarget, mainTargetID, newTarget, currentDistance + 1,numOfSquares)

    return numOfSquares
Exemplo n.º 21
0
def getDirectionFromPriority(square_dict, PARAMS):

    priority = -10.000
    direction_id = None

    for direction, neighborsDict in square_dict["neighbors"].items():
        #####loop through the neighbors of the current square
        if neighborsDict["neighborPriority"] == -1:
            #####if neighbor priority is -1, its an ally
            #####check its request help priority (which should be its highest neighbor priority)
            neighborSquare = neighborsDict["square"]
            id = FUNC.getID(neighborSquare)
            realneighborSquare = copy.copy(PARAMS.allMySquares[id])
            if realneighborSquare["requestHelpPriority"] > priority:
                priority = copy.copy(
                    PARAMS.allMySquares[id]["requestHelpPriority"])
                direction_id = copy.copy(direction)
        elif neighborsDict["neighborPriority"] > priority:
            priority = copy.copy(neighborsDict["neighborPriority"])
            direction_id = copy.copy(direction)
        else:
            doing = None

    if direction_id == "north":
        _direction = NORTH
    elif direction_id == "east":
        _direction = EAST
    elif direction_id == "south":
        _direction = SOUTH
    else:
        _direction = WEST

    #####If highest priority is a neutral, check if it has stronger strength
    neighborSquare = square_dict["neighbors"][direction_id]["square"]
    currentsquare = copy.copy(square_dict["currentsquare"])

    if neighborSquare.owner == 0:
        if currentsquare.strength <= neighborSquare.strength and neighborSquare.strength != 255:
            _direction = STILL

    return _direction
Exemplo n.º 22
0
def setDistanceFromFakeEnemy(PARAMS, GLOBALVARS, neutralFrontLine,
                             distanceNum):
    _distanceNum = copy.copy(distanceNum)
    _neutralFrontLine = copy.copy(neutralFrontLine)

    for sq in _neutralFrontLine:
        ####No enemy square
        targetSquare = copy.copy(sq)
        newNeutralFrontLine = []
        nextNeighbors = GLOBALVARS.game_map.neighbors(sq,
                                                      n=1,
                                                      include_self=False)

        for neighbor in nextNeighbors:
            if neighbor.owner == PARAMS.myID:
                id = FUNC.getID(neighbor)
                if (PARAMS.allMySquares[id]["enemy_Distance"] == 0 and (PARAMS.allMySquares[id]["fakeEnemy_Distance"] == 0) \
                        or PARAMS.allMySquares[id]["fakeEnemy_Distance"] > _distanceNum):
                    PARAMS.allMySquares[id][
                        "fakeEnemy_Distance"] = _distanceNum
                    PARAMS.allMySquares[id][
                        "fakeEnemy_NextSquare"] = copy.copy(sq)
                    PARAMS.allMySquares[id][
                        "fakeEnemy_TargetSquare"] = copy.copy(targetSquare)
                    newNeutralFrontLine.append(neighbor)

                    if id not in PARAMS.accountedIDsToAttack:
                        PARAMS.accountedIDsToAttack.append(id)

                    if id not in PARAMS.deletedFromExpandingSquaresID:
                        PARAMS.deletedFromExpandingSquaresID.append(id)

        if _distanceNum == copy.copy(PARAMS.poweringBackUpNum):
            #####reached max distance allowed
            return
        else:
            #####get next distance
            setDistanceFromFakeEnemy(PARAMS, GLOBALVARS, newNeutralFrontLine,
                                     _distanceNum + 1)
Exemplo n.º 23
0
def setDirectionsInParamsFake(PARAMS, GLOBALVARS, key, mySquaresDict):
    currentProduction = mySquaresDict['currentsquare'].production
    minSquareStrengthBeforeMovingTime = PARAMS.turnsToStayBeforeMoving * currentProduction
    square = mySquaresDict['currentsquare']
    nextSquare = mySquaresDict["fakeEnemy_NextSquare"]
    id = FUNC.getID(square)
    hasNeutral0, neutral0 = FUNC.hasNeutralNeighborWithStrength0(
        PARAMS, GLOBALVARS, square)

    if hasNeutral0 and square.strength > 0:
        directionMovement = DIR.getDirection(GLOBALVARS, square, neutral0)
    elif mySquaresDict['fakeEnemy_Distance'] == 1 and mySquaresDict[
            'currentsquare'].strength < PARAMS.minSquareStrengthPoweringUp_1:
        #####check if next to neutral neighbor
        directionMovement = STILL
    elif mySquaresDict['fakeEnemy_Distance'] > 1 and mySquaresDict[
            'currentsquare'].strength < PARAMS.minSquareStrengthPoweringUp:
        directionMovement = STILL
    elif mySquaresDict[
            'currentsquare'].strength <= nextSquare.strength and nextSquare.owner == 0:
        #####Not strong enough to take the neutral
        directionMovement = STILL
    else:
        #####Next square is neutral
        if PARAMS.preventAttackingFirst == True:
            if square.strength > PARAMS.minStrengthToAttackNeutralEnemyDetected:
                directionMovement = DIR.getDirection(GLOBALVARS, square,
                                                     nextSquare)
            else:
                #####get best priority excluding ones towards the enemy
                excludeList = []
                for direction in (NORTH, EAST, SOUTH, WEST):
                    newNextSquare = GLOBALVARS.game_map.get_target(
                        square, direction)
                    hasEnemy, enemyList, numOfenemies = FUNC.hasEnemyNeighbor(
                        PARAMS, GLOBALVARS, newNextSquare)
                    if hasEnemy == True:
                        excludeList.append(direction)

                if excludeList == []:
                    #directionMovement = DIR.getDirectionFromPriorityExcluding(mySquaresDict, PARAMS, excludeList)
                    directionMovement = DIR.getDirection(
                        GLOBALVARS, square, nextSquare)
                    targetSquare = GLOBALVARS.game_map.get_target(
                        square, directionMovement)
                    targetSquareID = FUNC.getID(targetSquare)

                    if GLOBALVARS.OLDPARAMS is not None:
                        if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, id,GLOBALVARS.OLDPARAMS.mySquaresAlongEnemyBorder) \
                                and targetSquareID == GLOBALVARS.OLDPARAMS.mySquaresAlongEnemyBorder[id]:
                            excludeList.append(directionMovement)
                            directionMovement = (max(excludeList) + 1) % 4
                        else:
                            directionMovement = DIR.getDirection(
                                GLOBALVARS, square, nextSquare)

                else:
                    #####since NORTH == 0, will not be the max
                    if WEST in excludeList and NORTH in excludeList and EAST not in excludeList:
                        directionMovement = EAST
                    elif WEST in excludeList and NORTH in excludeList and EAST in excludeList:
                        directionMovement = SOUTH
                    else:
                        directionMovement = (max(excludeList) + 1) % 4
                    targetSquare = GLOBALVARS.game_map.get_target(
                        square, directionMovement)
                    targetSquareID = FUNC.getID(targetSquare)
                    PARAMS.mySquaresAlongEnemyBorder[
                        targetSquareID] = copy.copy(id)

                    if GLOBALVARS.OLDPARAMS is not None:
                        if FUNC.checkIfIDExistInDictionary(PARAMS, GLOBALVARS, id, GLOBALVARS.OLDPARAMS.mySquaresAlongEnemyBorder) \
                            and targetSquareID == GLOBALVARS.OLDPARAMS.mySquaresAlongEnemyBorder[id]:
                            excludeList.append(directionMovement)
                            directionMovement = (max(excludeList) + 1) % 4

                #####Make sure square is strong enough to take if its a neutral
                newTargetSquare = GLOBALVARS.game_map.get_target(
                    square, directionMovement)
                if mySquaresDict[
                        'currentsquare'].strength <= newTargetSquare.strength and newTargetSquare.owner == 0:
                    #####Not strong enough to take the neutral
                    directionMovement = STILL

        else:
            #####Not preventing first attack, just get best priority excluding help priority
            excludeList = []
            directionMovement = DIR.getDirectionFromPriorityExcluding(
                mySquaresDict, PARAMS, excludeList)

            targetSquare = GLOBALVARS.game_map.get_target(
                square, directionMovement)
            if targetSquare.owner == PARAMS.myID:
                #####just take the neutral square next to enemy, instead of going back and forth
                directionMovement = DIR.getDirection(GLOBALVARS, square,
                                                     nextSquare)

    PARAMS.allMySquares[key]['direction'] = directionMovement
Exemplo n.º 24
0
def setDirectionsInParams(PARAMS, GLOBALVARS, key, mySquaresDict):
    currentProduction = mySquaresDict['currentsquare'].production
    minSquareStrengthBeforeMovingTime = PARAMS.turnsToStayBeforeMoving * currentProduction
    square = mySquaresDict['currentsquare']
    id = FUNC.getID(square)
    hasNeutral0, neutral0 = FUNC.hasNeutralNeighborWithStrength0(
        PARAMS, GLOBALVARS, square)

    if hasNeutral0 and mySquaresDict['enemy_Distance'] != 1 and mySquaresDict[
            'enemy_Distance'] != 2 and square.strength > 0:
        directionMovement = DIR.getDirection(GLOBALVARS, square, neutral0)
    elif mySquaresDict[
            'currentsquare'].strength < PARAMS.minSquareStrengthBeforeMoving:
        directionMovement = STILL
    elif (mySquaresDict['enemy_Distance'] == 2):
        #####prevent splash damage
        if mySquaresDict[
                'currentsquare'].strength > PARAMS.strengthToForceMove_2:
            #####go to 1 position
            directionMovement = DIR.getDirection(
                GLOBALVARS, square, mySquaresDict['enemy_NextSquare'])
        else:
            directionMovement = STILL
    elif (mySquaresDict['enemy_Distance'] == 4):
        #####prevent splash damage
        if mySquaresDict[
                'currentsquare'].strength > PARAMS.strengthToForceMove_4:
            #####go to 3 position
            directionMovement = DIR.getDirection(
                GLOBALVARS, square, mySquaresDict['enemy_NextSquare'])
        else:
            directionMovement = STILL
    elif (mySquaresDict['enemy_Distance']
          == 0) and (mySquaresDict['enemy_Distance-1'] == 2):
        #####number 1 before won, move forward
        directionMovement = DIR.getDirection(
            GLOBALVARS, square, mySquaresDict['enemy_NextSquare-1'])
    elif (mySquaresDict['enemy_Distance']
          == 1) and mySquaresDict['enemy_Distance-1'] == 2:
        #####number 1 before lost, move forward
        directionMovement = DIR.getDirection(GLOBALVARS, square,
                                             mySquaresDict['enemy_NextSquare'])
    elif (mySquaresDict['enemy_Distance'] == 1):
        #directionMovement = DIR.getDirectionFromPriority(mySquaresDict, PARAMS)
        directionMovement = DIR.getDirectionFromPriorityExcluding(
            mySquaresDict, PARAMS, [])
    elif mySquaresDict[
            'enemy_Distance'] == PARAMS.createOpeningDistanceFromEnemy and square.strength > PARAMS.minStrengthCreateOpening:
        #####has to have neutrals around it
        hasNeutral, neutralSq = FUNC.hasNeutralNeighbor(
            PARAMS, GLOBALVARS, square)
        if hasNeutral == True:
            #directionMovement = DIR.getDirectionFromPriority(mySquaresDict, PARAMS)
            directionMovement = DIR.getDirection(GLOBALVARS, square, neutralSq)
        else:
            #####else go with direction of enemy distance
            id = FUNC.getID(square)
            directionMovement = getDirectionFromEnemyDistance(
                PARAMS, GLOBALVARS, id)
    else:
        directionMovement = getDirectionFromEnemyDistance(
            PARAMS, GLOBALVARS, id)

    PARAMS.allMySquares[key]['direction'] = directionMovement
Exemplo n.º 25
0
    logging.basicConfig(filename='1example.log', level=logging.DEBUG)

    #INIT.initialize(GLOBALVARS,myID)
    hlt.send_init("En3rG_v2.46")

    while True:

        GLOBALVARS.game_map.get_frame()

        moves = []
        PARAMS = D.Parameters(myID, GLOBALVARS.maxturns)
        D.updateParamsPerMap(PARAMS, GLOBALVARS)

        GD.getSquaresInfo(PARAMS, GLOBALVARS)

        FUNC.setRequestHelpPriority(PARAMS, GLOBALVARS)

        GD.getNeutralSquaresDetectedEnemy(PARAMS, GLOBALVARS)

        if GLOBALVARS.hasEnemyBeenEngaged == False \
                and GLOBALVARS.hasEnemyBeenDetected == False \
                and GLOBALVARS.initExpand == True:
            INIT.expand(PARAMS,GLOBALVARS)
        else:
            FUNC.attackAndExpand(PARAMS,GLOBALVARS)
            DIR.updateDirectionOfMiddleSquares(PARAMS, GLOBALVARS)

        EV.evadeTowardsEnemy(PARAMS, GLOBALVARS)
        #EV.evadeAndPushBack(PARAMS, GLOBALVARS)

        FUNC.setTarget(PARAMS, GLOBALVARS)
Exemplo n.º 26
0
def manageOverStrengthDirection(PARAMS, GLOBALVARS):
    sortedList = reversed(
        sorted(PARAMS.allMySquaresList, key=lambda x: x.strength))

    for sq in sortedList:
        origID = FUNC.getID(sq)
        mySquaresDict = PARAMS.allMySquares[origID]
        origSquare = copy.copy(mySquaresDict['currentsquare'])
        origTargetID = copy.copy(mySquaresDict['actual_TowardID'])
        isTargetNeutral = FUNC.getIsTargetNeutral(PARAMS, origTargetID)
        isTargetMine = FUNC.getIsTargetMine(PARAMS, origTargetID)

        #####target square is yours
        #####target ID not managed yet
        #####target ID not orig ID
        if origTargetID not in PARAMS.managedTargetIDs and isTargetMine == True and origTargetID != origID:
            PARAMS.managedTargetIDs.append(origTargetID)
            totalStrength = 0
            origTargetSquare = copy.copy(
                PARAMS.allMySquares[origTargetID]["currentsquare"])
            targetTargetID = copy.copy(
                PARAMS.allMySquares[origTargetID]['actual_TowardID'])

            #####see if orig target targets itself
            if targetTargetID == origTargetID:
                totalStrength = copy.copy(PARAMS.allMySquares[origTargetID]
                                          ['currentsquare'].strength)

            neighborsLowToHigh = FUNC.getNeighborsLowToHighStrength(
                GLOBALVARS, origTargetSquare)
            neighborsLowToHigh0 = copy.copy(neighborsLowToHigh)

            #####If there is a 255, make everyone going there still so this square can swap
            for neighbor in reversed(neighborsLowToHigh0):
                neighborID = FUNC.getID(neighbor)
                if FUNC.getIsTargetMine(PARAMS, neighborID):
                    neighborTargetID = copy.copy(
                        PARAMS.allMySquares[neighborID]['actual_TowardID'])

                    #####has the same target
                    if neighborTargetID == origTargetID and neighbor.strength == PARAMS.maxStrength:
                        #####if there is a max strength, this is to prevent the rest from going there so max strength can swap
                        totalStrength = PARAMS.maxStrength

            #####first will be the lowest strength because you want to combine as much as possible
            for neighbor in reversed(neighborsLowToHigh):
                neighborID = FUNC.getID(neighbor)

                if FUNC.getIsTargetMine(PARAMS, neighborID):
                    neighborTargetID = copy.copy(
                        PARAMS.allMySquares[neighborID]['actual_TowardID'])
                    #####has the same target

                    if neighborTargetID == origTargetID:
                        neighborTargetStrength = copy.copy(
                            PARAMS.allMySquares[neighborID]
                            ['currentsquare'].strength)
                        if (totalStrength +
                                neighborTargetStrength) > PARAMS.maxStrength:
                            #####keep neighbor at still, make orig square not to move here
                            PARAMS.allMySquares[neighborID][
                                'direction'] = STILL
                            PARAMS.allMySquares[neighborID][
                                'possibleSwap'] = True
                            PARAMS.allMySquares[neighborID][
                                'temp_selftarget'] = True
                            PARAMS.allMySquares[neighborID][
                                'actual_TowardID'] = copy.copy(neighborID)
                        else:
                            #####both neighbor and orig square can go to the target
                            totalStrength = totalStrength + neighborTargetStrength
                            #####to prevent swapping in the future
                            PARAMS.managedDontSwapAnymoreID.append(
                                origTargetID)

        #####target square is a Neutral
        #####target ID not managed yet
        #####target ID not orig ID
        elif origTargetID not in PARAMS.managedTargetIDs and isTargetNeutral == True and origTargetID != origID:
            PARAMS.managedTargetIDs.append(origTargetID)
            totalStrength = 0
            origTargetSquare = copy.copy(
                PARAMS.allNeutralSquares[origTargetID]['currentsquare'])
            neutralStrength = copy.copy(PARAMS.allNeutralSquares[origTargetID]
                                        ['currentsquare'].strength)
            totalStrength = totalStrength - neutralStrength
            #####get lowest neighbor first to attack neutral
            neighborsLowToHigh = FUNC.getNeighborsLowToHighStrength(
                GLOBALVARS, origTargetSquare)
            neighborsLowToHigh0 = copy.copy(neighborsLowToHigh)

            #####first will be highest, you want highest to go to direction-1 and attack
            for neighbor in reversed(neighborsLowToHigh0):
                neighborID = FUNC.getID(neighbor)
                #####origID already taken into account

                if FUNC.getIsTargetMine(PARAMS, neighborID):
                    neighborTargetID = copy.copy(
                        PARAMS.allMySquares[neighborID]['actual_TowardID'])
                    if neighborTargetID == origTargetID:
                        neighborTargetStrength = copy.copy(
                            PARAMS.allMySquares[neighborID]
                            ['currentsquare'].strength)
                        #####will be overstrength
                        #####neutral strength already subtracted from total strength
                        if (totalStrength +
                                neighborTargetStrength) > PARAMS.maxStrength:
                            PARAMS.allMySquares[neighborID][
                                'direction'] = STILL
                            PARAMS.allMySquares[neighborID][
                                'possibleSwap'] = True
                            PARAMS.allMySquares[neighborID][
                                'temp_selftarget'] = True
                            PARAMS.allMySquares[neighborID][
                                'actual_TowardID'] = copy.copy(neighborID)
                        else:
                            totalStrength = totalStrength + neighborTargetStrength

        else:
            doing = None
Exemplo n.º 27
0
def manageOverStrengthPushed(PARAMS, GLOBALVARS):
    for keyID, mySquaresDict in PARAMS.allMySquares.items():
        #####take squares going to the first square pushed into account
        if mySquaresDict['pushedForEvadingNum'] == 1:
            PARAMS.managedTargetIDs.append(keyID)
            origSquare = mySquaresDict['currentsquare']
            origSquareID = FUNC.getID(origSquare)
            neighbors = GLOBALVARS.game_map.neighbors(origSquare,
                                                      n=1,
                                                      include_self=False)

            for neighbor in neighbors:
                neighborID = FUNC.getID(neighbor)
                isTargetMine = FUNC.getIsTargetMine(PARAMS, neighborID)
                if isTargetMine == True:
                    neighborTargetSquare = GLOBALVARS.game_map.get_target(
                        neighbor, PARAMS.allMySquares[neighborID]['direction'])
                    neighborTargetSquareID = FUNC.getID(neighborTargetSquare)

                    if neighborTargetSquareID == origSquareID:
                        #####same target
                        PARAMS.allMySquares[neighborID]['direction'] = STILL

        #####take other squares pushed into account
        if mySquaresDict['pushedForEvading'] == True:
            origSquare = mySquaresDict['currentsquare']
            origSquareID = keyID
            origTargetSquare = GLOBALVARS.game_map.get_target(
                origSquare, mySquaresDict['direction'])
            origTargetID = FUNC.getID(origTargetSquare)
            totalStrength = origSquare.strength
            PARAMS.managedTargetIDs.append(origTargetID)
            #####check neighbors of target, see if any has same target as origTargetSquare
            targetNeighbors = GLOBALVARS.game_map.neighbors(origTargetSquare,
                                                            n=1,
                                                            include_self=False)

            for neighbor in targetNeighbors:
                neighborID = FUNC.getID(neighbor)
                #####same as original ID or also pushed for evading, dont change directions
                isTargetMine = FUNC.getIsTargetMine(PARAMS, neighborID)
                if isTargetMine == True:
                    if neighborID == origSquareID or PARAMS.allMySquares[
                            neighborID]['pushedForEvading'] == True:
                        doing = None
                    else:
                        neighborTargetSquare = GLOBALVARS.game_map.get_target(
                            neighbor,
                            PARAMS.allMySquares[neighborID]['direction'])
                        neighborTargetSquareID = FUNC.getID(
                            neighborTargetSquare)

                        if neighborTargetSquareID == origTargetID:
                            #####same target
                            if totalStrength + neighbor.strength > 255:
                                #####change direction of neighbor to still
                                PARAMS.allMySquares[neighborID][
                                    'direction'] = STILL
                            else:
                                #####increase total strength for next neighbor
                                totalStrength = totalStrength + neighbor.strength