Exemplo n.º 1
0
def buyAction(nextMove, currentNation, PRICE_TRACKER, flag, db):
    nextMove = nextMove.split(',')
    commodity = nextMove[1]
    key = nextMove[2]
    amount = int(nextMove[3])
    price = getattr(PRICE_TRACKER, key)
    stock = getattr(PRICE_TRACKER, commodity)
    myStock = getattr(currentNation, commodity)
    cost = amount * int(price)

    printRow = printDialogue(
        flag, str(str('### ' + str(currentNation.country) + ' chose to buy ')),
        db)
    printRow = printDialogue(
        flag, str(str('Credits    : ' + str(currentNation.wealth))), db)
    printRow = printDialogue(
        flag, str(str(str(commodity) + ' purchased : ' + str(amount))), db)
    printRow = printDialogue(flag, str(str('Total Cost :' + str(cost))), db)

    # UPDATE Reduce stock and deliver goods to user
    setattr(PRICE_TRACKER, commodity, (int(stock) - amount))
    setattr(currentNation, commodity, (int(myStock) + amount))
    printRow = printDialogue(
        flag,
        str(str('New total : ' + str(getattr(currentNation, commodity)))), db)

    db.session.commit()
    return (0, 'Success')
Exemplo n.º 2
0
def processResearchReward(researchedItemName, currentNation, techPKey, flag,
                          db):

    printRow = printDialogue(
        flag,
        str(
            str('######' + str(researchedItemName) +
                ' Research Complete! #########')), db)
    printRow = printDialogue(flag, str(" "), db)
    techBonusRow = db.session.query(techEraBonus).filter_by(
        era=currentNation.era).first()
    bonusKey = techPKey[:-1]
    techBonus = getattr(techBonusRow, bonusKey)

    techBonus = techBonus.split(':')
    for item in techBonus:
        item = item.split(',')
        if item[0] == 'K':
            printRow = printDialogue(
                flag,
                str(str('Knowledge boosted by ' + str(item[1]) + ' points.')),
                db)
            currentNation.KP += round(int(item[1]))
        if item[0] == 'R':
            printRow = printDialogue(
                flag,
                str(str('Research boosted by ' + str(item[1]) + ' points.')),
                db)
            currentNation.RP += round(int(item[1]))
        if item[0] == 'W':
            printRow = printDialogue(
                flag, str(str('Wealth increased by $' + str(item[1]))), db)
            currentNation.wealth += round(int(item[1]))
    db.session.commit()
    return (0, 'success')
Exemplo n.º 3
0
def espionage(nextMove,currentNation,myWar,nextMoveIndex,flag,db):
    nextMove =  nextMove.split(',')
    nationChoice = nextMove[1]
    bonusPercent = random.randint(1,10)

    targetNation = db.session.query(NATIONS).filter_by(country=nationChoice).first()
    targetNation.Nextmoves = 'sabotaged' + ':'

    printRow = printDialogue(flag,str(str(str(targetNation.country) + ' has been infiltrated by an unknown advisary')),db)
    printRow = printDialogue(flag,str('==========================================='),db)
    printRow = printDialogue(flag,str(str(str(targetNation.country) + ' current actions sabotaged and will miss a round.')),db)
    
    printRow = printDialogue(flag,str(str(str(currentNation.country) + ' gained ' + str(bonusPercent) + '% might.' )),db)
    printRow = printDialogue(flag,str(str(str(currentNation.country) + ' original might value: ' + str(currentNation.might))),db)
      
    
    currentNation.might += round(int(currentNation.might) * (bonusPercent/100))
    printRow = printDialogue(flag,str(str(str(currentNation.country) + '      new might value: ' + str(currentNation.might))),db)
    
    discoverRisk = random.randint(0,5)
    if discoverRisk > -1:
        printRow = printDialogue(flag,str(str('### ' + str(targetNation.country) + ' captured the insurgent from ' + str(currentNation.country))),db)
        printRow = printDialogue(flag,str(str(str(targetNation.country) + ' friendship with ' + str(currentNation.country) + ' has decreased as a result.')),db)
        
        
        FrienshipBA = db.session.query(friendship).filter_by(country=targetNation.country,targetCountry=currentNation.country).first()
        printRow = printDialogue(flag,str(str(str(targetNation.country) + ' original friendship value: ' + str(FrienshipBA.level))),db)
        FrienshipBA.level -= random.randint(1,18)
        db.session.commit()

        printRow = printDialogue(flag,str(str(str(targetNation.country) + ' new friendship value: ' + str(int(FrienshipBA.level)))),db)


    return(0,'success')
Exemplo n.º 4
0
def build(nextMove,currentNation,myWar,nextMoveIndex,flag,db):
    print(nextMove)
    nextMove =  nextMove.split(',')
    pending    = nextMove[0]
    job        = nextMove[1]
    name       = nextMove[2]
    amount     = int(nextMove[3])
    wait       = int(nextMove[4])
    bonusMight = int(float(nextMove[5]))
    warKey     = nextMove[6]
    moveIndex = nextMoveIndex # Get position in country array



    # IF NOT YET READY
    # DECREMENT BUILD TIME 
    if wait > 1:
        wait = wait -1

        printRow = printDialogue(flag,str(str('### ' + str(currentNation.country) + ' chose to build ')),db)
        printRow = printDialogue(flag,str(str(str(name) + ' to build : ' + str(amount))),db)
        printRow = printDialogue(flag,str(str('Build Time Remaining : ' + str(wait))),db)

        # Find index nextmoves and update it
        nextMove = str('pending' + ',' + 'WeaponsBuild' + ',' + str(name) + ',' +  str(amount) + ',' +  str(wait) + ',' +  str(bonusMight) + ',' +  str(warKey) + ':')
        moveArray = updateMoveArray(currentNation,'WeaponsBuild',nextMove)
        currentNation.Nextmoves = moveArray
        db.session.commit()
        return(0,'success')

    #IF READY (currently at 2 cus lazy)
    if wait <= 1:
        # Reward Unit
        stockOwned = int(getattr(myWar, warKey))
        setattr(myWar, warKey, (stockOwned + amount))
        stockOwned = int(getattr(myWar, warKey))
        
        # Reward Mightg
        bonusAdjustment = round((currentNation.might * bonusMight) * (amount/2))
        if bonusAdjustment < 1: bonusAdjustment  = 1
        currentNation.might += bonusAdjustment
        
        printRow = printDialogue(flag,str(str('### ' + str(currentNation.country) + ' Build complete ')),db)
        printRow = printDialogue(flag,str(str(str(name) + ' units built: ' + str(amount))),db)
        printRow = printDialogue(flag,str(str(str(name) + ' total : ' + str(stockOwned))),db)
        printRow = printDialogue(flag,str(str('Might gained : ' + str(bonusAdjustment))),db)
        printRow = printDialogue(flag,str(str('Might total  : ' + str(currentNation.might))),db)


        # Clear out existing array element
        moveArray = updateMoveArray(currentNation,'WeaponsBuild'," ")
        currentNation.Nextmoves = moveArray

        db.session.commit()
        return(0,'success')

    return(0,'success')
Exemplo n.º 5
0
def sellAction(nextMove, currentNation, PRICE_TRACKER, flag, db):
    nextMove = nextMove.split(',')
    commodity = nextMove[1]
    amount = int(nextMove[2])
    value = nextMove[3]

    stock = getattr(PRICE_TRACKER, commodity)
    myStock = getattr(currentNation, commodity)

    printRow = printDialogue(
        flag, str(str('### ' + str(currentNation.country) + ' chose to sell')),
        db)
    printRow = printDialogue(
        flag, str(str('Credits    : ' + str(currentNation.country))), db)
    printRow = printDialogue(
        flag, str(str(str(commodity) + ' owned : ' + str(myStock))), db)
    printRow = printDialogue(
        flag, str(str(str(commodity) + ' sold  : ' + str(amount))), db)

    # UPDATE Increase stock and credit user
    setattr(PRICE_TRACKER, commodity, (int(stock) + amount))
    currentNation.wealth += int(value)
    printRow = printDialogue(
        flag, str(str(str(currentNation.country) + ' was paid ' + str(value))),
        db)
    printRow = printDialogue(
        flag, str(str('New Credits Total   : ' + str(currentNation.wealth))),
        db)

    db.session.commit()
    return (0, 'Success')
Exemplo n.º 6
0
def scrap(nextMove,currentNation,myWar,nextMoveIndex,flag,db):
    nextMove =  nextMove.split(',')
    pending       = nextMove[0]
    job           = nextMove[1]
    unit          = nextMove[2]
    amount        = int(nextMove[3])
    valuation     = int(nextMove[4])
    reducedMight  = int(float(nextMove[5]))
    name = unit

    printRow = printDialogue(flag,str(str('### ' + str(currentNation.country) + ' chose to scrap')),db)
    printRow = printDialogue(flag,str(str(str(name) + ' to scrap : ' + str(amount))),db)
    
    

    # Award Credits and reduce might
    currentNation.wealth +=  valuation
    Adjustment = round((currentNation.might * reducedMight) * (amount/5))
    currentNation.might -=  Adjustment
    
    printRow = printDialogue(flag,str(str('Might lost    : -' + str(Adjustment))),db)
    printRow = printDialogue(flag,str(str('Might total   : ' + str(currentNation.might))),db)
    printRow = printDialogue(flag,str(str(str(currentNation.country) + ' was paid ' + str(valuation))),db)
    printRow = printDialogue(flag,str(str('Credits total : ' + str(currentNation.wealth))),db)
    
    return(0,'success')
Exemplo n.º 7
0
def gambleAction(nextMove, currentNation, flag, db):
    nextMove = nextMove.split(',')

    printRow = printDialogue(flag, str(''), db)
    printRow = printDialogue(
        flag, str('### ' + str(currentNation.country) + ' chose to gamble '),
        db)

    amount = int(nextMove[1])
    originalFinanceScore = int(currentNation.wealth) + amount
    winnings = random.randint((round(0.3 * amount)), round(2.5 * amount))
    currentNation.wealth += winnings
    db.session.commit()

    difference = int(currentNation.wealth) - originalFinanceScore

    if difference > 0:
        printRow = printDialogue(
            flag,
            str(
                str(
                    str(currentNation.country) + ' gained  +' +
                    str(difference))), db)
    elif difference < 0:
        printRow = printDialogue(
            flag,
            str(str(str(currentNation.country) + ' lost  ' + str(difference))),
            db)
    else:
        printRow = printDialogue(
            flag,
            str(
                str(
                    str(currentNation.country) + ' broke even  ' +
                    str(difference))), db)

    printRow = printDialogue(flag,
                             str(str('Gambled         : ' + str(amount))), db)
    printRow = printDialogue(flag,
                             str(str('Winnings        : ' + str(winnings))),
                             db)
    printRow = printDialogue(
        flag, str(str('Finance credits : ' + str(currentNation.wealth))), db)

    return (0, 'Success')
Exemplo n.º 8
0
def processResearch(nextMove, currentNation, CURRENT_TECH_ASSETS,
                    nextMoveIndex, flag, db):
    nextMove = nextMove.split(',')
    pending = nextMove[0]
    job = nextMove[1]
    era = nextMove[2]
    choice = nextMove[3]
    techKey = nextMove[4]
    required = int(nextMove[5])
    earnedSoFar = getattr(CURRENT_TECH_ASSETS, techKey)

    #['Submitted', 'research', 'INDUSTRIAL REVOLUTION', 'Manufacturing Line', 'twoRp', '100']

    researchedItemName = choice
    remaining = required - int(earnedSoFar)
    pointsOwned = int(currentNation.RP)
    pointsToSpend = round(
        pointsOwned * 0.2
    )  # Test the last number, it may need reduced: spend = devcompletion speed

    #Skip this move if not enough points
    if pointsOwned < pointsToSpend:
        print('Not enough points')
        return (0, 'notEnough')
    # Skip if already max
    if remaining < 1:
        print(str(choice) + 'maxed out for ' + str(currentNation.country))
        return (0, 'Maxed out')

    # Deduct RP
    currentNation.RP -= pointsToSpend

    # UPDATE RESEARCH COMPLECTION
    newCompletionTotal = int(earnedSoFar) + pointsToSpend
    setattr(CURRENT_TECH_ASSETS, techKey, newCompletionTotal)
    db.session.commit()
    earnedSoFar = getattr(CURRENT_TECH_ASSETS, techKey)

    # UPDATE RESEARCH COMPLETION PERCENT
    techPKey = techKey[:-2] + 'P'
    completionPercent = (int(earnedSoFar) / required) * 100
    setattr(CURRENT_TECH_ASSETS, techPKey, round(completionPercent))
    db.session.commit()
    #Update remaining
    remaining = required - int(earnedSoFar)
    # Cap
    if remaining < 0: remaining = 0
    if completionPercent > 100: completionPercent = 100
    pointsOwned = int(currentNation.RP)

    printRow = printDialogue(
        flag, str(str(str(currentNation.country) + ' Research Update')), db)
    printRow = printDialogue(
        flag, str(str('Researched Item: ' + str(researchedItemName))), db)
    printRow = printDialogue(
        flag, str(str('Research points spent = ' + str(pointsToSpend))), db)
    printRow = printDialogue(
        flag,
        str(
            str('Research: remaining   = ' + str(remaining) +
                ' , completion ' + str(round(completionPercent, 2)) + '%')),
        db)
    printRow = printDialogue(flag, str('RP Owned = ' + str(pointsOwned)), db)
    printRow = printDialogue(flag, str(), db)

    # process reward
    if remaining < 1:
        setattr(CURRENT_TECH_ASSETS, techPKey, 100)
        moveArray = updateMoveArray(currentNation, 'research', " ")
        currentNation.Nextmoves = moveArray
        NATION_ARRAY = processResearchReward(researchedItemName, currentNation,
                                             techPKey, flag, db)
        db.session.commit()
    else:
        # Continue the move
        nextMove = str('pending' + ',' + 'research' + ',' + str(era) + ',' +
                       str(choice) + ',' + str(techKey) + ',' + str(required) +
                       ':')
        moveArray = updateMoveArray(currentNation, 'research', nextMove)
        currentNation.Nextmoves = moveArray
        db.session.commit()
        printRow = printDialogue(flag, str(), db)
        str('Completion ' + str(completionPercent) + '%')

    return (0, 'success')
Exemplo n.º 9
0
def gainResearch(nextMove, currentNation, nextMoveIndex, flag, db):
    nextMove = nextMove.split(',')
    pending = nextMove[0]
    job = nextMove[1]
    intensity = nextMove[2]
    investedPercent = int(nextMove[3])
    rounds = int(nextMove[4])
    invested = int(nextMove[5])
    RP = int(currentNation.RP)
    KP = int(currentNation.KP)

    if intensity == 'soft':
        bonusRP = round((0.1 * RP))
        if bonusRP < 25:
            bonusRP = 25
        bonusKP = 0
    elif intensity == 'medium':
        bonusRP = round((0.1 * RP) + (invested / 3))
        bonusKP = round((0.1 * KP) + (invested / 4))
    elif intensity == 'hard':
        bonusRP = round((0.2 * RP) + (invested / 5))
        bonusKP = round((0.2 * KP) + (invested / 6))
    elif intensity == 'overtime':
        bonusRP = round((0.3 * RP) + (invested / 7))
        bonusKP = round((0.3 * KP) + (invested / 8))

    # IF ROUNDS STILL TO GO, REWARD BONUS AND CONTINUE PENDING
    if rounds > 0:
        rounds = rounds - 1

        #ADD REWARDS
        currentNation.RP += round(bonusRP)
        currentNation.KP += round(bonusKP)
        print('UPDATING RESEARCH ARRAY ')
        print(currentNation.Nextmoves)
        nextMove = 'pending' + ',' + 'gainResearch' + ',' + str(
            intensity) + ',' + str(investedPercent) + ',' + str(
                rounds) + ',' + str(invested) + ':'
        moveArray = updateMoveArray(currentNation, 'gainResearch', nextMove)
        currentNation.Nextmoves = moveArray
        db.session.commit()
        print(currentNation.Nextmoves)
        printRow = printDialogue(
            flag, str(str(str(currentNation.country) + ' Research Grant')), db)
        printRow = printDialogue(flag, str(str('Level ' + str(intensity))), db)
        printRow = printDialogue(flag, str(str('RP Bonus : +' + str(bonusRP))),
                                 db)
        printRow = printDialogue(flag, str(str('KP Bonus : +' + str(bonusKP))),
                                 db)
        printRow = printDialogue(
            flag,
            str(
                str('RP increased from ' + str(RP) + ' to ' +
                    str(currentNation.RP))), db)
        printRow = printDialogue(
            flag,
            str(
                str('KP increased from ' + str(KP) + ' to ' +
                    str(currentNation.KP))), db)
        printRow = printDialogue(flag,
                                 str(str('Rounds Remaining : ' + str(rounds))),
                                 db)

        # Clear out nextmove
        if rounds < 1:
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) +
                        ' Research Grant Funding complete.')), db)
            moveArray = updateMoveArray(currentNation, 'gainResearch', " ")
            currentNation.Nextmoves = moveArray
            db.session.commit()
        return (0, 'success')

    else:
        moveArray = updateMoveArray(currentNation, 'gainResearch', " ")
        currentNation.Nextmoves = moveArray
        db.session.commit()
        return (0, 'success')

    return (0, 'success')
Exemplo n.º 10
0
def advanceEra(nextMove, currentNation, myWar, nextMoveIndex, flag, db):

    # Define Weapons bonus awards
    One = int(myWar.wOneAmount) * int(myWar.wOneLevel) * 1
    Two = int(myWar.wTwoAmount) * int(myWar.wTwoLevel) * 1
    Three = int(myWar.wThreeAmount) * int(myWar.wThreeLevel) * 2
    Four = int(myWar.wFourAmount) * int(myWar.wFourLevel) * 2
    Five = int(myWar.wFiveAmount) * int(myWar.wFiveLevel) * 3
    Six = int(myWar.wSixAmount) * int(myWar.wSixLevel) * 4
    Seven = int(myWar.wSevenAmount) * int(myWar.wSevenLevel) * 5
    Eight = int(myWar.wEightAmount) * int(myWar.wEightLevel) * 5

    totalBonus = One + Two + Three + Four + Five + Six + Seven + Eight

    upgradeOne = int(myWar.wTwoAmount)
    upgradeTwo = int(myWar.wThreeAmount)
    upgradeThree = (int(myWar.wFourAmount) * 2) + (
        int(myWar.wFiveAmount) * 10) + (int(myWar.wSixAmount) * 20) + (
            int(myWar.wSevenAmount) * 50) + (int(myWar.wEightAmount) * 200)

    # Update Era
    era = currentNation.era
    nextEraRow = db.session.query(techEras).filter_by(era=era).first()
    nextEra = nextEraRow.nextEra

    # Deactivate current era
    myTech = db.session.query(techAssets).filter_by(
        country=currentNation.country, era=era).first()
    myTech.active = 0
    db.session.commit()

    # Update era
    currentNation.era = nextEra
    db.session.commit()

    # Update latest Era
    myTech = db.session.query(techAssets).filter_by(
        country=currentNation.country, era=currentNation.era).first()
    myTech.active = 1
    db.session.commit()

    # REWARD KNOWLEDGE..
    knowledge = int(currentNation.KP)
    currentNation.KP += round((knowledge * 0.15))
    if int(currentNation.KP) < 2: currentNation.KP = 69
    db.session.commit()

    # DEACTIVATE PREVIOUS ERA IN WARARRAY
    myWar.active = 0
    db.session.commit()

    # ACTIVATE NEXT ERA AND REWARD UNITS
    myWar = db.session.query(warAssets).filter_by(
        country=currentNation.country, era=currentNation.era).first()
    myWar.active = 1
    myWar.wOneAmount = upgradeOne
    myWar.wTwoAmount = upgradeTwo
    myWar.wThreeAmount = upgradeThree
    db.session.commit()

    currentNation.might += totalBonus
    db.session.commit()

    printRow = printDialogue(flag,
                             str('++++++++++++++++++++++++++++++++++++++++++'),
                             db)
    printRow = printDialogue(
        flag,
        str(
            str(
                str(currentNation.country) + ' has advanced to the ' +
                str(nextEra))), db)
    printRow = printDialogue(flag,
                             str('++++++++++++++++++++++++++++++++++++++++++'),
                             db)
    printRow = printDialogue(
        flag, str(str(str(currentNation.country) + ' gained 10% knowledge.')),
        db)
    printRow = printDialogue(
        flag, str(str('Units converted to +' + str(totalBonus) + ' might.')),
        db)
    printRow = printDialogue(
        flag,
        str(
            str(
                str(currentNation.country) + ' now has ' + str(nextEra) +
                ' level military capabilities.')), db)

    return (0, 'complete')
Exemplo n.º 11
0
def processRound(db,averageRPOne,AverageRPTwo,AverageRPThree):
    # DEFINE PLAYER
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))


    # CONTAINS STATS FOR ALL NATIONS
    NATION_ASSETS = db.session.query(NATIONS).all()
    WAR_ASSETS    = db.session.query(warAssets).all()
    TECH_ASSETS   = db.session.query(techAssets).all()

    # FLUSH UPDATES FROM PREVIOUS ROUND 
    dialogue.query.delete()
    
    # REFERENCE DATABASES
    WAR_DATABASE   = db.session.query(warDataBase).all()
    TECH_COST_DB   = db.session.query(techEraCost).all()
    TECH_BONUS_DB  = db.session.query(techEraCost).all()
    PRICE_TRACKER  = db.session.query(PTc).first()
    FRIENDSHIP     = db.session.query(friendship).all()
    GAME_TRACKER   = db.session.query(gameTracker).first()
    year           = GAME_TRACKER.year
    month          = GAME_TRACKER.month

    # Nesting vars into a parm array to make it easier to pass between functions
    PARM_ARRAY = [NATION_ASSETS,WAR_ASSETS,TECH_ASSETS,WAR_DATABASE,TECH_COST_DB,TECH_BONUS_DB,PRICE_TRACKER,FRIENDSHIP,GAME_TRACKER,year]

    # UPDATE PRICE HISTORY
    historicalRow  = PTcHistory(goldPrice=PRICE_TRACKER.goldPrice, gold=PRICE_TRACKER.gold, goldPriceChange=PRICE_TRACKER.goldPriceChange, goldHistory=PRICE_TRACKER.goldHistory, goldAverage=PRICE_TRACKER.goldAverage,rareMetalsPrice= PRICE_TRACKER.rareMetalsPrice, rareMetals= PRICE_TRACKER.rareMetals, rareMetalsPriceChange= PRICE_TRACKER.rareMetalsPriceChange, rareMetalsHistory=PRICE_TRACKER.rareMetalsHistory,rareMetalsAverage=PRICE_TRACKER.rareMetalsAverage,gemsPrice= PRICE_TRACKER.gemsPrice, gems= PRICE_TRACKER.gems, gemsPriceChange= PRICE_TRACKER.gemsPriceChange, gemsHistory=PRICE_TRACKER.gemsHistory,gemsAverage=PRICE_TRACKER.gemsAverage, oilPrice= PRICE_TRACKER.oilPrice, oil= PRICE_TRACKER.oil, oilPriceChange= PRICE_TRACKER.oilPriceChange, oilHistory=PRICE_TRACKER.oilHistory,oilAverage=PRICE_TRACKER.oilAverage)
    db.session.add(historicalRow)
    db.session.commit()

    # Last row
    previousPrices = PTcHistory.query.order_by(-PTcHistory.id).first()

    # ITERATE FOR EACH COUNTRY ** THIS IS THE MAIN LOOP FOR UPDATING ** 
    for currentNation in NATION_ASSETS:
        index = currentNation.id
        if currentNation.country != myNation.country:
            flag = 'AI'
        else:
            flag = 'player'

        #AI TEAM DECISION
        if currentNation.country != myNation.country:
            AImessage = AI.setAIMoves(PARM_ARRAY,db,currentNation,averageRPOne,AverageRPTwo,AverageRPThree,index,flag)
            printRow = printDialogue(flag,str('________________________'),db)
            printRow = printDialogue(flag,str('\n \n \n'),db)

        # ACTION CARRIED OUT FOR ALL USERS
        actionMessage = action(PARM_ARRAY,db,currentNation,index,flag)

        # BRANCH PROMOTIONS
        currentNation  = financeFunction.promotion(currentNation,flag,db)
        #currentNation  = warFunction.promotion(currentNation,p,index,playerNationIndex)
        #currentNation = financeFunction.promotion(currentNation,p,index,playerNationIndex)
        #currentNation = financeFunction.promotion(currentNation,p,index,playerNationIndex)


    # Only talling scores at the end....masy need to change
    print('-------Tallying scores------')
    message = tallyScores(NATION_ASSETS,db)
    
    nextStepsMessage = defaultNextStep(NATION_ASSETS,db)

    
    # UPDATE PRICE 
    updateMessage = updatePrice(PRICE_TRACKER,previousPrices,db)
    # UPDATE WAR 
    # UPDATE TECH 

    #myNation = menu(myNation,PRICE_TRACKER,previousPrices,p,year)
 
    # INCREMENT THE YEARS
    month = int(month) + 1
    if month > 12:
        month = 1
        year = int(year) + 1
    GAME_TRACKER.month = month
    GAME_TRACKER.year = year
    db.session.commit()


    return('Year processed')
Exemplo n.º 12
0
def drill(nextMove,currentNation,myWar,nextMoveIndex,flag,db):
    nextMove =  nextMove.split(',')
    move      = nextMove[0]
    branch    = nextMove[1]
    intensity = nextMove[2]
    units     = nextMove[3:]
    might     = int(currentNation.might)
    credits   = int(currentNation.wealth)



    printRow = printDialogue(flag,str(str('### ' + str(currentNation.country) + ' chose to train their ' + str(branch))),db)
    printRow = printDialogue(flag,str(str('Intensity: ' + str(intensity) )),db)
    
    

    # RETURN UNITS
    if branch == 'Light Units':
        myWar.wOneAmount = int(units[0])
        myWar.wTwoAmount  = int(units[1])
    if branch == 'Core Division':
        myWar.wThreeAmount = int(units[0])
        myWar.wFourAmount  = int(units[1])
        myWar.wFiveAmount  = int(units[2])
    if branch == 'Heavy Forces':
        myWar.wSixAmount = int(units[0])
        myWar.wSevenAmount  = int(units[1])



    if intensity == 'soft':
        bonusMight = round((random.randint(1,8) / 100) * might)
        currentNation.might += bonusMight
        printRow = printDialogue(flag,str(str('Might gained    : ' + str(bonusMight))),db)
        printRow = printDialogue(flag,str(str('New Might Total : ' + str(currentNation.might))),db)
        db.session.commit()
        return(0,'soft complete')

    if intensity == 'medium':

        # WIN MIGTH
        bonusMight = round((random.randint(8,14) / 100) * might)
        currentNation.might +=  bonusMight
        # WIN CREDITS
        bonusCredits = round((random.randint(1,5) / 100) * credits)
        currentNation.wealth +=   bonusCredits

        printRow = printDialogue(flag,str(str(str(currentNation.country) + ' impressed the top leadership and won financial backing.')),db)
        printRow = printDialogue(flag,str('Credits gained    : ' + str(bonusCredits) ),db)
        
        

        # LOSE A PORTION OF UNITS 
        lossProbability = random.randint(0,8)
        lossAmount = 0.25
        flag = 'True'
        if lossProbability == 3:
            # RETURN UNITS
            if branch == 'Light Units':
                myWar.wOneAmount    = round(int(units[0]) * (random.randint(0,25)/100))
                myWar.wTwoAmount    = round(int(units[1]) * (random.randint(0,25)/100))
            if branch == 'Core Division':
                myWar.wThreeAmount  = round(int(units[0]) * (random.randint(0,25)/100))
                myWar.wFourAmount   = round(int(units[1]) * (random.randint(0,25)/100))
                myWar.wFiveAmount   = round(int(units[2]) * (random.randint(0,25)/100))
            if branch == 'Heavy Forces':
                myWar.wSixAmount    = round(int(units[1]) * (random.randint(0,25)/100))
                myWar.wSevenAmount  = round(int(units[2]) * (random.randint(0,25)/100))
            printRow = printDialogue(flag,str(str('**Units lost** Accidents in training drill has resulted in losses.')),db)
            db.session.commit()

        printRow = printDialogue(flag,str('Might gained    : ' + str(bonusMight)),db)
        printRow = printDialogue(flag,str(str('New Might Total : ' + str(currentNation.might))),db)
        
        db.session.commit()
        return(0,'medium complete')

    if intensity == 'hard':

        # WIN MIGTH
        bonusMight = round((random.randint(14,20) / 100) * might)
        currentNation.might +=  bonusMight
        # WIN CREDITS
        bonusCredits = round((random.randint(5,10) / 100) * credits)
        currentNation.wealth +=   bonusCredits

        printRow = printDialogue(flag,str(str(str(currentNation.country) + ' impressed the top leadership and won financial backing.')),db)
        printRow = printDialogue(flag,str(str('Credits gained    : ' + str(bonusCredits))),db)
        
        # LOSE A PORTION OF UNITS 
        lossProbability = random.randint(0,8)
        flag = 'True'
        if lossProbability == 3:
            # RETURN UNITS
            if branch == 'Light Units':
                myWar.wOneAmount    = round(int(units[0]) * (random.randint(0,40)/100))
                myWar.wTwoAmount    = round(int(units[1]) * (random.randint(0,40)/100))
            if branch == 'Core Division':
                myWar.wThreeAmount  = round(int(units[0]) * (random.randint(0,40)/100))
                myWar.wFourAmount   = round(int(units[1]) * (random.randint(0,40)/100))
                myWar.wFiveAmount   = round(int(units[2]) * (random.randint(0,40)/100))
            if branch == 'Heavy Forces':
                myWar.wSixAmount    = round(int(units[1]) * (random.randint(0,40)/100))
                myWar.wSevenAmount  = round(int(units[2]) * (random.randint(0,40)/100))
            printRow = printDialogue(flag,str(str('**Units lost** Accidents in training drill has resulted in losses.')),db)
            db.session.commit()

        printRow = printDialogue(flag,str(str('Might gained    : ' + str(bonusMight))),db)
        printRow = printDialogue(flag,str(str('New Might Total : ' + str(currentNation.might))),db)
        
        db.session.commit()
        return(0,'medium complete')

    return(0,'Complete')
Exemplo n.º 13
0
def action(PARM_ARRAY,db,currentNation,index,flag):
    NATION_ASSETS = PARM_ARRAY[0]
    WAR_ASSETS    = PARM_ARRAY[1]
    TECH_ASSETS   = PARM_ARRAY[2]
    WAR_DATABASE  = PARM_ARRAY[3]
    TECH_COST_DB  = PARM_ARRAY[4]
    TECH_BONUS_DB = PARM_ARRAY[5]
    PRICE_TRACKER = PARM_ARRAY[6]
    FRIENDSHIP    = PARM_ARRAY[7]
    GAME_TRACKER  = PARM_ARRAY[8]
    year          = PARM_ARRAY[9]


    currentNation = currentNation
    CURRENT_TECH_ASSETS = db.session.query(techAssets).filter_by(country=currentNation.country,era=currentNation.era).first()
    myWar    = db.session.query(warAssets).filter_by(country=currentNation.country,era=currentNation.era).first()


    # PROCESS PASS
    nextMoveIndex = 0

    printRow = printDialogue('AI',str('The current country is ' + str(currentNation.country)),db)

    nextMoves = currentNation.Nextmoves.split(":")
    for nextMove in nextMoves:
        if len(nextMove) == 0:
            continue
        # print(currentNation.Nextmoves)
        # REMEMBER TO UPDATE NATION ARRAY (NOT CURRENT NATION)
        # if 'pass' in nextMove:
        #     preferencePrint(str(str(currentNation[1]) + ' chose to pass'),p,index,playerNationIndex)
        if 'sabotaged' in nextMove:
            printRow = printDialogue(flag,str(str(currentNation.country) + ' sabotaged, skipping round.'),db)
            currentNation.Nextmoves = " "
            db.session.commit()
            return(0,'complete')

        if 'gamble' in nextMove:
            gambleResult = financeFunction.gambleAction(nextMove,currentNation,flag,db)

        if 'buy' in nextMove:
            financeMessage = financeFunction.buyAction(nextMove,currentNation,PRICE_TRACKER,flag,db)

        if 'sell' in nextMove:
            sellResult = financeFunction.sellAction(nextMove,currentNation,PRICE_TRACKER,flag,db)

        if 'investResource' in nextMove:
            investResult = financeFunction.investResource(nextMove,currentNation,PRICE_TRACKER,flag,nextMoveIndex,db)

        if 'investCountry' in nextMove:
            #print('current nation' + str(currentNation[1]))
            investResult = financeFunction.investCountry(nextMove,currentNation,PRICE_TRACKER,flag,nextMoveIndex,db)
    
        if 'drill' in nextMove:
            drillResult = warFunction.drill(nextMove,currentNation,myWar,nextMoveIndex,flag,db)

        # Even if prices change, you get it for the order you placed
        if 'WeaponsBuild' in nextMove:
            buildResult = warFunction.build(nextMove,currentNation,myWar,nextMoveIndex,flag,db)

        if 'WeaponsScrap' in nextMove:
            scrapMessage = warFunction.scrap(nextMove,currentNation,myWar,nextMoveIndex,flag,db)

        if 'espionage' in nextMove:
            espionageMessage = warFunction.espionage(nextMove,currentNation,myWar,nextMoveIndex,flag,db)

        if 'research' in nextMove:
            researchMessage = scienceFunction.processResearch(nextMove,currentNation,CURRENT_TECH_ASSETS,nextMoveIndex,flag,db)

        if 'gainResearch' in nextMove:
            grantMessage = scienceFunction.gainResearch(nextMove,currentNation,nextMoveIndex,flag,db)

        if 'advanceEra' in nextMove:
            advanceMessage = scienceFunction.advanceEra(nextMove,currentNation,myWar,nextMoveIndex,flag,db)        

        if 'pass'  in nextMove:
            printRow = printDialogue(flag,str(str(currentNation.country) + ' chose to pass.'),db)

        nextMoveIndex = nextMoveIndex + 1

    return(0,'complete')
Exemplo n.º 14
0
def setAIMoves(PARM_ARRAY, db, currentNation, averageRPOne, AverageRPTwo,
               AverageRPThree, index, flag):
    NATION_ASSETS = PARM_ARRAY[0]
    WAR_ASSETS = PARM_ARRAY[1]
    TECH_ASSETS = PARM_ARRAY[2]
    WAR_DATABASE = PARM_ARRAY[3]
    TECH_COST_DB = PARM_ARRAY[4]
    TECH_BONUS_DB = PARM_ARRAY[5]
    PRICE_TRACKER = PARM_ARRAY[6]
    FRIENDSHIP = PARM_ARRAY[7]
    GAME_TRACKER = PARM_ARRAY[8]
    year = PARM_ARRAY[9]

    # Capping AI at one for now
    moveLimit = int(currentNation.moveLimit)
    aggression = int(currentNation.aggression)
    creativity = int(currentNation.creativity)
    materialism = int(currentNation.materialism)
    prudence = int(currentNation.prudence)
    wealth = int(currentNation.wealth)
    era = currentNation.era
    myTech = db.session.query(techAssets).filter_by(
        country=currentNation.country, era=currentNation.era).first()
    myWar = db.session.query(warAssets).filter_by(
        country=currentNation.country, era=currentNation.era).first()
    notes = str(currentNation.notes)
    #print('########' + str(currentNation.country) + '  ' + str(notes))

    moveCounter = 0
    while checkMoves(currentNation, '%^')[0] > 1:
        #Ensure no countries take more moves than the limit
        if moveCounter > 3: break
        # Returns index 0 = finance, 1 = war, 2 science, 3 politics
        bias = calculateBias(currentNation, wealth, materialism, aggression,
                             creativity, prudence)

        #HAS FinanceNANCE BIAS
        if bias == 0:
            choice = [1, 2, 3, 4, 5]
            choice = random.choice(choice)
            if choice == 1: gambleMessage = gamble(currentNation, db)  # GAMBLE

            if choice == 2:
                buyMessage = aiBuy(PRICE_TRACKER, currentNation, materialism,
                                   aggression, db)  # BUY

            if choice == 3:
                sellMessage = aiSell(PRICE_TRACKER, currentNation, materialism,
                                     aggression, db)  # SELL

            if choice == 4:
                investMessage = investResource(currentNation, PRICE_TRACKER,
                                               db)  # Invest Resource

            if choice == 5:
                invCmessage = investNation(currentNation, PRICE_TRACKER,
                                           db)  # Invest in nation

        # HAS BIAS TOWARDS WAR
        if bias == 1:
            choice = [1, 2, 3, 4, 5]
            choice = random.choice(choice)
            # DRILL
            if choice == 1: drillMessage = drill(currentNation, myWar, db)
            # BUILD
            if choice == 2:
                buildMessage = build(currentNation, WAR_DATABASE, aggression,
                                     materialism, myTech, db)
            # SCRAP
            if choice == 3:
                scrapMessage = scrap(currentNation, myWar, aggression, db)
            # ESPIONAGE~
            if choice == 4:
                espionageMessage = espionage(currentNation, aggression,
                                             prudence, db)

        #HAS BIAS TOWARDS SCIENCE
        if bias == 2:
            if '1' in notes.split(':'):
                #print('#####TRYING TO LEVEL UP')
                advanceMessage = advanceEra(currentNation, db)
            grantMessage = gainResearchPoints(currentNation, averageRPOne,
                                              AverageRPTwo, AverageRPThree,
                                              aggression, creativity, db)
            completeTech = researchTechnology(currentNation, era, creativity,
                                              averageRPOne, AverageRPTwo,
                                              AverageRPThree, myTech, db)

        moveCounter += 1

    # If No moves, then pass
    if len(currentNation.Nextmoves) == 0:
        print(str(currentNation.country) + ' chose to pass')
        currentNation.Nextmoves = 'pass:'******'XXXXXXXENDROUND XXXXXXXXX ')
    print(str(currentNation.country) + ' moves: ' + str(moveTotal))
    print(str(currentNation.country) + ' moves: ' + str(moveTotal))
    printRow = printDialogue(
        'all',
        str(str(str(currentNation.country) + ' moves: ' + str(moveTotal))), db)
    printRow = printDialogue('all', str(str('----------------')), db)
    print('XXXXXXXENDROUND XXXXXXXXX ')

    return (0, 'pass')
Exemplo n.º 15
0
def promotion(currentNation, flag, db):
    financeRank = [
        'PickPocket', 'Penny Pusher', 'Assistant', 'gambler', 'accountant',
        'huslter', 'business magnate'
    ]
    wealth = int(currentNation.wealth)
    rank = currentNation.fLevel
    if wealth > 5100 and rank == financeRank[0]:
        currentNation.fLevel = financeRank[1]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()

    if wealth > 10000 and rank == financeRank[1]:
        currentNation.fLevel = financeRank[2]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()
    if wealth > 15000 and rank == financeRank[2]:
        currentNation.fLevel = financeRank[3]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()
    if wealth > 20000 and rank == financeRank[3]:
        currentNation.fLevel = financeRank[4]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()

    if wealth > 30000 and rank == financeRank[4]:
        currentNation.fLevel = financeRank[5]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()
    if wealth > 40000 and rank == financeRank[5]:
        currentNation.fLevel = financeRank[6]
        rank = currentNation.fLevel
        currentNation.notes = str(
            str(currentNation.country) + ' levelled up! New Finance rank is ' +
            str(rank) + ':')
        printRow = printDialogue(
            flag,
            str(
                str(currentNation.country) +
                ' levelled up! New Finance rank is ' + str(rank) + ':'), db)
        db.session.commit()

    return (0, 'success')
Exemplo n.º 16
0
def investResource(nextMove, currentNation, PRICE_TRACKER, flag, nextMoveIndex,
                   db):
    nextMove = nextMove.split(',')

    pending = nextMove[0]
    job = nextMove[1]
    resource = nextMove[2]
    spendAmount = int(float(nextMove[3]))
    investedPrice = int(float(nextMove[4]))
    wait = int(nextMove[5])
    moveIndex = nextMoveIndex  # Get position in country array

    if resource == "gold":
        key = 'goldPrice'
    if resource == "rareMetals":
        key = 'rareMetalsPrice'
    if resource == 'gems':
        key = 'gemsPrice'
    if resource == 'oil':
        key = 'oilPrice'

    # IF NOT YET READY
    if wait > 0:
        wait = wait - 1

        printRow = printDialogue(
            flag,
            str(
                str('### ' + str(currentNation.country) +
                    ' chose to Invest in ' + str(resource))), db)
        printRow = printDialogue(flag,
                                 str(str('Time Remaining : ' + str(wait))), db)

        adjustedMove = 'pending' + ',' + str(job) + ',' + str(
            resource) + ',' + str(spendAmount) + ',' + str(
                investedPrice) + ',' + str(wait) + ',' + str(key) + ':'

        moveArray = updateMoveArray(currentNation, 'investResource',
                                    adjustedMove)
        currentNation.Nextmoves = moveArray
        db.session.commit()

    if wait < 1:
        currentPrice = getattr(PRICE_TRACKER, key)
        priceDiff = int(currentPrice) - investedPrice
        original = currentNation.wealth

        if priceDiff > 0:
            bonus = round(priceDiff * spendAmount *
                          (random.randint(1, 300) / 100))
            currentNation.wealth += bonus
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) + ' made a profit of $' +
                        str(bonus))), db)

        if priceDiff < 0:
            priceDiff = -priceDiff
            token = round((priceDiff / investedPrice) * investedPrice)
            loss = round(spendAmount - token)
            currentNation.wealth += loss
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) +
                        ' made a loss, but recouped $' + str(loss))), db)

        if priceDiff == 0:
            token = round(investedPrice + (investedPrice *
                                           (random.randint(1, 18) / 100)))
            currentNation.wealth += (token + spendAmount)
            str(
                str(currentNation.country) +
                ' made no profit, but gained token interest of $' + str(token))

        printRow = printDialogue(
            flag,
            str(
                str('Credits changed from $' + str(original) + ' to $' +
                    str(currentNation.wealth))), db)

        # Find this index in nextmove array and blank it out
        moveArray = updateMoveArray(currentNation, 'investResource', " ")
        currentNation.Nextmoves = moveArray
        db.session.commit()

    return (0, 'complete')
Exemplo n.º 17
0
def investCountry(nextMove, currentNation, PRICE_TRACKER, flag, nextMoveIndex,
                  db):
    nextMove = nextMove.split(',')
    pending = nextMove[0]
    job = nextMove[1]
    thereNation = nextMove[2]
    spendAmount = int(nextMove[3])
    nationsOriginalWealth = int(nextMove[4])
    wait = int(nextMove[5])

    myNation = currentNation.country
    originalWealth = currentNation.wealth

    #allies = db.session.query(friendship).filter_by(country='USA',targetCountry='UK').first()
    FriendshipAB = db.session.query(friendship).filter_by(
        country=myNation, targetCountry=thereNation).first().level
    FrienshipBA = db.session.query(friendship).filter_by(
        country=thereNation, targetCountry=myNation).first().level
    originalFriendshipAB = int(FriendshipAB)
    originalFrienshipBA = int(FrienshipBA)
    # # IF NOT YET READY
    if wait > 0:
        wait = wait - 1

        printRow = printDialogue(
            flag,
            str(
                str('### ' + str(currentNation.country) + ' investing in ' +
                    str(thereNation))), db)
        printRow = printDialogue(flag,
                                 str(str('Time Remaining : ' + str(wait))), db)

        mextMove = str('pending' + ',' + 'investCountry' + ',' +
                       str(thereNation) + ',' + str(spendAmount) + ',' +
                       str(nationsOriginalWealth) + ',' + str(wait))
        moveArray = updateMoveArray(currentNation, 'investCountry', mextMove)

        currentNation.Nextmoves = moveArray
        db.session.commit()

    if wait < 1:
        currentWealth = int(
            db.session.query(NATIONS).filter_by(
                country=thereNation).first().wealth)
        wealthDiff = currentWealth - nationsOriginalWealth
        myOriginalCredits = int(currentNation.wealth)

        if wealthDiff > 0:
            bonus = round(wealthDiff * 0.2) + round(
                wealthDiff * 0.05 * spendAmount / 100) + (spendAmount * 1.5)
            bonus = round(bonus)
            currentNation.wealth += +bonus
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) + ' made a profit of $' +
                        str(bonus))), db)

        if wealthDiff < 0:
            loss = 0.8 * spendAmount
            currentNation.wealth += round(currentNation.wealth + loss)
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) +
                        ' made a loss, but recouped $' + str(loss))), db)

        if wealthDiff == 0:
            token = round(nationsOriginalWealth +
                          (nationsOriginalWealth *
                           (random.randint(1, 10) / 100)))
            token = round(token)
            currentNation.wealth = round(currentNation.wealth + token +
                                         spendAmount)
            printRow = printDialogue(
                flag,
                str(
                    str(
                        str(currentNation.country) +
                        ' made no profit, but gained token interest of $' +
                        str(token))), db)

        # BOOST FRIENDSHIP
        FriendshipAB += int(originalFriendshipAB) + random.randint(1, 15)
        FrienshipBA += int(originalFrienshipBA) + random.randint(8, 25)

        printRow = printDialogue(
            flag,
            str(
                str(
                    str(thereNation) +
                    ' greatly appreciates the investment from ' +
                    str(myNation))), db)
        printRow = printDialogue(
            flag,
            str(
                str('New friendship between ' + str(thereNation) + ' and ' +
                    str(myNation) + ' has increased from ' +
                    str(originalFriendshipAB) + ' to ' + str(FriendshipAB))),
            db)
        printRow = printDialogue(
            flag,
            str(
                str('New friendship between ' + str(myNation) + ' and ' +
                    str(thereNation) + ' has increased from ' +
                    str(originalFrienshipBA) + ' to ' + str(FrienshipBA))), db)
        printRow = printDialogue(
            flag,
            str(
                str('Credits changed from $' + str(originalWealth) + ' to $' +
                    str(currentNation.wealth))), db)

        moveArray = updateMoveArray(currentNation, 'investCountry', " ")
        currentNation.Nextmoves = moveArray
        db.session.commit()
        print('complete')
        print(currentNation)

    return (0, 'success')