Exemple #1
0
def nextYear():
    year, month = getParms('year')
    myNation = getParms('myNation')
    playerTech = techAssets.query.filter_by(active=1,
                                            country=myNation.country).first()
    DIALOGUE = db.session.query(dialogue).all()
    # Works the best
    movesToCheck = checkMoves(myNation, '^&')
    movesLeft = movesToCheck[0]

    message = ""
    displayFlag = ""
    infoFlag = ""

    if request.method == 'POST':
        if request.form.get('playerUpdates'):
            displayFlag = "playerUpdates"
        if request.form.get('AIUpdates'):
            displayFlag = "AIUpdates"
        if request.form.get('allUpdates'):
            displayFlag = "allUpdates"

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('nextYear.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesLeft,
                            playerTech=playerTech,
                            message=message,
                            displayFlag=displayFlag,
                            infoFlag=infoFlag,
                            DIALOGUE=DIALOGUE))
Exemple #2
0
def advanceEra(currentNation, db):

    # CHECK MAX MOVES
    returnCode = checkMoves(currentNation, 'advanceEra')[1]
    if returnCode > 0:
        return (0, 'already selected advance era')
    myTech = db.session.query(techAssets).filter_by(
        country=currentNation.country, era=currentNation.era).first()

    techOne = myTech.oneP
    techTwo = myTech.twoP
    techThree = myTech.threeP
    techFour = myTech.fourP
    techFive = myTech.fiveP

    # Only upgrade if AI has completed all tech streams 5 x 100% completion ==500
    total = int(techOne) + int(techTwo) + int(techThree) + int(techFour) + int(
        techFive)
    if total < 500:
        print(str(currentNation.country) + 'not enough to advance era')
        return (0, 'not enough to advance era')

    # Get Next era
    era = currentNation.era
    nextEraRow = db.session.query(techEras).filter_by(era=era).first()
    nextEra = nextEraRow.nextEra

    # Place Order
    currentNation.Nextmoves += 'advanceEra' + ':'
    db.session.commit()
    currentNation.notes = " "
    db.session.commit()
    print(currentNation.notes)

    return (0, 'success')
Exemple #3
0
def tradeMenu():
    year, month = getParms('year')
    myNation = getParms('myNation')
    myWealth = myNation.wealth
    PT = PTc.query.order_by(PTc.id).all()
    displayFlag = "main"
    movesChecked = checkMoves(myNation, 'gamble')

    if request.method == 'POST':
        if request.form.get('buy'):
            return redirect(url_for('buyMenu'))
        if request.form.get('sell'):
            return redirect(url_for('sellMenu'))

        if request.form.get('average'):
            displayFlag = "average"

        if request.form.get('historical'):
            displayFlag = "historical"

        if request.form.get('marketStock'):
            displayFlag = "stock"

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('tradeMenu.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesChecked[0],
                            PT=PT,
                            displayFlag=displayFlag))
Exemple #4
0
def investNation(currentNation, PRICE_TRACKER, db):

    # CHECK MAX MOVES
    returnCode = checkMoves(currentNation, 'investCountry')[1]
    if returnCode > 0:
        return (currentNation)

    # MORE LOGIC REQUIRED
    friendList = returnBestFriends(currentNation)
    friend = random.choice(friendList)
    if int(friend.level) < 30:
        print('no friends over 30 for ' + str(currentNation.country))
        return (0, 'drop out')

    # Pick a random value to invest
    returnCode, spendAmount = arbitrarySpendAmount(currentNation)
    if returnCode > 0:
        return (currentNation)

    # PLACE ORDER Decrement wealth now
    currentNation.wealth -= spendAmount
    friendsOriginalWealth = NATIONS.query.filter_by(
        country=friend.targetCountry).first().wealth
    wait = 4
    nextMove = str('Submitted' + ',' + 'investCountry' + ',' +
                   str(friend.targetCountry) + ',' + str(spendAmount) + ',' +
                   str(friendsOriginalWealth) + ',' + str(wait) + ':')
    currentNation.Nextmoves += nextMove
    return (0, 'success')
Exemple #5
0
def sellMenu():
    year, month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    myWealth = myNation.wealth
    PT = PTc.query.order_by(PTc.id).first()

    displayFlag = "main"
    purchaseFlag = ''
    global commodity
    global commodityFlag
    salesFlag = ""
    commodityFlag = ''
    message = ''

    movesChecked = checkMoves(myNation, 'sell')
    if movesChecked[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))

    if request.method == 'POST':

        # If user clicks a resource, display a form
        if request.form.get('selectCommodity'):
            commodity = request.form.get('selectCommodity')
            salesFlag = "sellCommodity"
            commodityFlag = str(commodity)

        if request.form.get('sellCommodity'):
            if commodity is not None:
                print('called')
                sellAmount = request.form.get('sellCommodity')
                sellResult = sellResource(myNation, sellAmount, commodity, PT,
                                          db)
                message = sellResult[1]
                print('message')
                print(message)

        if request.form.get('average'):
            displayFlag = "average"

        if request.form.get('historical'):
            displayFlag = "historical"

        if request.form.get('marketStock'):
            displayFlag = "stock"

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('sellMenu.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesChecked[0],
                            PT=PT,
                            displayFlag=displayFlag,
                            message=message,
                            salesFlag=salesFlag,
                            commodityFlag=commodityFlag))
Exemple #6
0
def weaponsMenu():
    year,month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    
    myWar    = db.session.query(warAssets).filter_by(country=myNation.country,era=myNation.era).first()
    lightForces = int(myWar.wOneAmount) + int(myWar.wTwoAmount)
    coreForces = int(myWar.wThreeAmount) + int(myWar.wFourAmount) + int(myWar.wFiveAmount)
    heavyForces = int(myWar.wSixAmount) + int(myWar.wSevenAmount)
    displayFlag = ""
    # Works the best
    movesToCheck = checkMoves(myNation,'&^')
    movesLeft = movesToCheck[0]
    if movesToCheck[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))


    
    if request.method == 'POST':
        if request.form.get('build'):
            return redirect(url_for('build'))
        if request.form.get('scrap'):
            return redirect(url_for('scrap'))

        if request.form.get('review'):
            displayFlag = 'combat'
        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return(render_template('weaponsMenu.html',year=year,month=month,myNation=myNation,movesLeft=movesLeft,displayFlag=displayFlag,lightForces=lightForces,coreForces=coreForces,heavyForces=heavyForces,myWar=myWar))
Exemple #7
0
def scrap():
    year, month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))

    myWar = db.session.query(warAssets).filter_by(country=myNation.country,
                                                  era=myNation.era).first()
    lightForces = int(myWar.wOneAmount) + int(myWar.wTwoAmount)
    coreForces = int(myWar.wThreeAmount) + int(myWar.wFourAmount) + int(
        myWar.wFiveAmount)
    heavyForces = int(myWar.wSixAmount) + int(myWar.wSevenAmount)
    warPricing = db.session.query(warDataBase).filter_by(
        era=myNation.era).all()

    displayFlag = ""
    scrapMessage = ""
    # Works the best
    movesToCheck = checkMoves(myNation, 'WeaponsScrap')
    movesLeft = movesToCheck[0]
    if movesToCheck[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))

    if request.method == 'POST':
        if request.form.get('scrap'):
            displayFlag = 'scrap'
            global unitSelected
            unitSelected = request.form.get('scrap')
            scrapMessage = unitSelected

        if request.form.get('scrapForm'):
            scrapAmount = request.form.get('scrapForm')
            unitSelected = unitSelected
            priceRow = db.session.query(warDataBase).filter_by(
                era=myNation.era, unit_name=unitSelected).first()
            scrapResult = scrapFunction(myNation, myWar, unitSelected,
                                        priceRow, scrapAmount, db)
            scrapMessage = scrapResult[1]

        if request.form.get('review'):
            displayFlag = 'review'

        if request.form.get('disposition'):
            displayFlag = 'disposition'

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('scrap.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesLeft,
                            displayFlag=displayFlag,
                            lightForces=lightForces,
                            coreForces=coreForces,
                            heavyForces=heavyForces,
                            myWar=myWar,
                            scrapMessage=scrapMessage,
                            warPricing=warPricing))
Exemple #8
0
def mainMenu():
    # Clear last years dialogue
    updateDialogue = db.session.query(dialogue).all()
    updates = []
    xcount = 0
    # Lazy coding
    for item in updateDialogue:
        if item.AIPrintLine is None:
            continue
        if 'The current country' in item.AIPrintLine: continue 
        if '------------------' in item.AIPrintLine: continue
        if '++++++++++++++++' in item.AIPrintLine: continue 
        if '--------END-------' in item.AIPrintLine: continue
        if 'Time Remaining' in item.AIPrintLine: continue
        updates.append(item.AIPrintLine)
        xcount +=1
        if xcount > 10: break

    dialogue.query.delete()
    db.session.commit()
    year,month = getParms('year')
    myNation = getParms('myNation')
    movesLeft = checkMoves(myNation,'%^')[0]
    displayFlag = ""
    notes = ""
    # If there are any updates, print and flush
    if len(myNation.notes) > 0:
        displayFlag = "notes"
        notes = myNation.notes
        notes = notes.split(':')
        myNation.notes = ""
        db.session.commit()

    if len(updates) < 1:
        updates = ['Welcome to Universe 237', 'This game is a work in progress and still not complete.' , 'For suggestions and queries email [email protected]']



    if request.method == 'POST':
        if request.form.get('LB'):
            return redirect(url_for('LB'))
        if request.form.get('FB'):
            return redirect(url_for('financeMenu'))
        if request.form.get('MW'):
            return redirect(url_for('warMenu'))
        if request.form.get('T'):
            return redirect(url_for('techMenu'))
        if request.form.get('N'):
            # Process Next year
            message = processRound(db,averageRPOne,AverageRPTwo,AverageRPThree)
            return redirect(url_for('nextYear'))




    return(render_template('mainMenu.html',year=year,month=month, myNation = myNation,movesLeft=movesLeft,notes=notes,displayFlag=displayFlag, updates=updates))
Exemple #9
0
def planning():
    year,month = getParms('year')
    # VARIABLES FOR CONDITIONS AND FUNCTIONS
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    nations = db.session.query(NATIONS).all()
    myWar    = db.session.query(warAssets).filter_by(country=myNation.country,era=myNation.era).first()
    lightForces = int(myWar.wOneAmount) + int(myWar.wTwoAmount)
    coreForces = int(myWar.wThreeAmount) + int(myWar.wFourAmount) + int(myWar.wFiveAmount)
    heavyForces = int(myWar.wSixAmount) + int(myWar.wSevenAmount)
    friends =db.session.query(friendship).filter_by(country=myNation.country).all()

    displayFlag = ""
    planningMessage = ""
    
    # Works the best
    movesToCheck = checkMoves(myNation,'espionage')
    movesLeft = movesToCheck[0]
    if movesToCheck[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))


    
    if request.method == 'POST':
        if request.form.get('espionage'):
            displayFlag = 'espionage'
            planningMessage = 'Pick a nation to sabotage'

        if request.form.get('select'):
            # Get User entered ID
            selectedID = request.form.get('select')
            global selected
            selected = NATIONS.query.get_or_404(int(selectedID))
            selectedOut = selected 
            #planningMessage = 'you selected ' + str(selectedOut.country)
            enemy =db.session.query(friendship).filter_by(country=myNation.country, targetCountry=selectedOut.country).first()
            friendshipLevel = enemy.level
            targetNation = selectedOut.country
            planningMessage = espionage(myNation,targetNation,friendshipLevel,db)
            planningMessage = planningMessage[1]

        if request.form.get('review'):
            displayFlag = 'review'

        if request.form.get('disposition'):
            displayFlag = 'disposition'

        if request.form.get('friendship'):
            displayFlag = 'friendship'
            

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return(render_template('planning.html',year=year,month=month,myNation=myNation,movesLeft=movesLeft,displayFlag=displayFlag,lightForces=lightForces,coreForces=coreForces,heavyForces=heavyForces,myWar=myWar,planningMessage=planningMessage,friends=friends,nations=nations))
Exemple #10
0
def investResource(currentNation, PRICE_TRACKER, db):

    # CHECK MAX MOVES
    returnCode = checkMoves(currentNation, 'investResource')[1]
    if returnCode > 0:
        return (0, 'duplicate')

    # Convert history string into list of numbers
    goldString = getattr(PRICE_TRACKER, 'goldHistory')
    rareMetalsString = getattr(PRICE_TRACKER, 'rareMetalsHistory')
    gemsString = getattr(PRICE_TRACKER, 'gemsHistory')
    oilString = getattr(PRICE_TRACKER, 'oilHistory')

    gold, rareMetals, gems, oil = [], [], [], []
    for item in goldString.split(','):
        gold.append(int(float(item)))
    for item in rareMetalsString.split(','):
        rareMetals.append(int(float(item)))
    for item in gemsString.split(','):
        gems.append(int(float(item)))
    for item in oilString.split(','):
        oil.append(int(float(item)))

    resource = 'N'
    if non_decreasing(gold) and len(gold) > 2:
        resource = 'gold'
    if non_decreasing(rareMetals) and len(rareMetals) > 2:
        resource = 'rareMetals'
    if non_decreasing(gems) and len(gems) > 2:
        resource = 'gems'
    if non_decreasing(oil) and len(oil) > 2:
        resource = 'oil'

    if resource == 'N':
        print('not yet, dropped out')
        return (0, 'dropped out')

    returnCode, spendAmount = arbitrarySpendAmount(currentNation)
    if returnCode > 0:
        print('not enough')
        return (0, 'not enough')

    # PLACE ORDER & Decrement wealth now
    currentNation.wealth -= spendAmount
    investedPrice = getattr(PRICE_TRACKER, str(str(resource) + 'Price'))
    wait = 4
    currentNation.Nextmoves += str('Submitted' + ',' + 'investResource' + ',' +
                                   str(resource) + ',' + str(spendAmount) +
                                   ',' + str(investedPrice) + ',' + str(wait) +
                                   ':')
    db.session.commit()
    return (0, 'success')
Exemple #11
0
def maneuvers():
    year, month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    myWar = db.session.query(warAssets).filter_by(country=myNation.country,
                                                  era=myNation.era).first()
    displayFlag = ""
    message = " "

    # Works the best
    movesToCheck = checkMoves(myNation, 'drill')
    movesLeft = movesToCheck[0]
    if movesToCheck[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))

    if request.method == 'POST':
        if request.form.get('drill'):
            displayFlag = 'drill'

        if request.form.get('division'):
            displayFlag = 'intensity'
            global division
            division = request.form.get('division')

        if request.form.get('intensity'):
            displayFlag = 'intensity'
            intensity = request.form.get('intensity')
            print(intensity)
            print(division)
            drillResult = drill(myNation, myWar, division, intensity, db)
            message = drillResult[1]
            print(message)

        if request.form.get('combat'):
            return redirect(url_for('mainMenu'))

        if request.form.get('review'):
            displayFlag = 'combat'
        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('maneuvers.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesLeft,
                            myWar=myWar,
                            displayFlag=displayFlag,
                            message=message))
Exemple #12
0
def investCountry():
    playerNation = gameTracker.query.get_or_404(1)
    nations = db.session.query(NATIONS).all()
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    selectedOut = ""
    message = ""
    infoMessage = ""
    nationSelectedFlag = ""

    # Check moves
    movesChecked = checkMoves(myNation, 'investCountry')
    if movesChecked[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))

    if request.method == 'POST':
        # If nation picked - display form
        if request.form.get('select'):
            # Get User entered ID
            selectedID = request.form.get('select')
            global selected
            selected = NATIONS.query.get_or_404(int(selectedID))
            selectedOut = selected
            nationSelectedFlag = "selected"

        if request.form.get('investForm'):
            if selected is not None:
                investAmount = request.form.get('investForm')
                investResult = investCountryFunction(myNation, investAmount,
                                                     selected, db)
                message = investResult[1]

    if request.form.get('mainMenu'):
        return redirect(url_for('mainMenu'))

    if request.form.get('information'):
        infoMessage = 'Investing in the growth of a country, helps boost friendship and earns money.'

    return (render_template('investCountry.html',
                            nations=nations,
                            myNation=myNation,
                            nationSelectedFlag=nationSelectedFlag,
                            selectedOut=selectedOut,
                            message=message,
                            infoMessage=infoMessage))
Exemple #13
0
def warMenu():
    year,month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    movesLeft = checkMoves(myNation,'%^')[0]

    
    if request.method == 'POST':
        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))
        if request.form.get('combat'):
            return redirect(url_for('maneuvers'))
        if request.form.get('weapons'):
            return redirect(url_for('weaponsMenu'))
        if request.form.get('offensive'):
            return redirect(url_for('planning'))

    return(render_template('warMenu.html',year=year,month=month,myNation=myNation,movesLeft=movesLeft))
Exemple #14
0
def gambleMenu():
    year, month = getParms('year')
    myNation = getParms('myNation')
    myWealth = myNation.wealth
    movesChecked = checkMoves(myNation, 'gamble')
    if movesChecked[1] > 0:
        print('Not enough moves or already carried this move out')
        return redirect(url_for('mainMenu'))

    message = "Enter a gamble amount.."

    if request.method == 'POST':
        if request.form.get('gamble'):
            gambleAmount = request.form['gamble']
            gambleAmount = int(gambleAmount)
            if isinstance(gambleAmount, int):
                if gambleAmount <= myWealth and gambleAmount > 0:
                    print('success')
                    print(gambleAmount)

                    #Deduct wealth & set next move
                    myNation.wealth -= gambleAmount
                    myNation.Nextmoves += str('gamble' + ',' +
                                              str(gambleAmount) + ':')
                    db.session.commit()
                    print(myNation)

                    return redirect(url_for('mainMenu'))
            else:
                print('caught')
                print(gambleAmount)
                print(type(gambleAmount))
                message = 'You entered an incorrect amount'

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('gambleMenu.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesChecked[0],
                            message=message))
Exemple #15
0
def financeMenu():
    year,month = getParms('year')
    myNation = getParms('myNation')
    movesLeft = checkMoves(myNation,'%^')[0]

    
    if request.method == 'POST':
        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))
        if request.form.get('Gamble'):
            return redirect(url_for('gambleMenu'))
        if request.form.get('Trade'):
            print('trade selected')
            return redirect(url_for('tradeMenu'))
        if request.form.get('invest'):
            print('invest selected')
            return redirect(url_for('investMenu'))

    return(render_template('financeMenu.html',year=year,month=month,myNation=myNation,movesLeft=movesLeft))
Exemple #16
0
def techMenu():
    year,month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    movesLeft = checkMoves(myNation,'%^')[0]
    displayFlag = ""

    
    if request.method == 'POST':
        if request.form.get('academia'):
            return redirect(url_for('mainMenu'))
        if request.form.get('research'):
            return redirect(url_for('researchMenu'))


        if request.form.get('techAssets'):
            displayFlag = tech

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return(render_template('techMenu.html',year=year,month=month,myNation=myNation,movesLeft=movesLeft))
Exemple #17
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')
Exemple #18
0
def investMenu():
    year, month = getParms('year')
    playerNation = gameTracker.query.get_or_404(1)
    myNation = NATIONS.query.get_or_404(int(playerNation.countryID))
    myWealth = myNation.wealth
    global PT
    PT = PTc.query.order_by(PTc.id).first()
    movesChecked = checkMoves(myNation, '^&')

    displayFlag = "main"
    global commodity
    global commodityToSubmit
    global commodityPrice
    commodity = ''
    formMessage = ''
    message = ''
    friends = db.session.query(friendship).filter_by(
        country=myNation.country).all()

    if request.method == 'POST':

        if request.form.get('countries'):
            movesChecked = checkMoves(myNation, 'investCountry')
            if movesChecked[1] > 0:
                print('Not enough moves or already carried this move out')
                return redirect(url_for('mainMenu'))

            return redirect(url_for('investCountry'))

        if request.form.get('gold'):
            commodity = 'gold'
            commodityPrice = PT.goldPrice
            commodityToSubmit = commodity
            displayFlag = "investCommodity"

        if request.form.get('rareMetals'):
            commodity = 'rareMetals'
            commodityPrice = PT.rareMetalsPrice
            commodityToSubmit = commodity
            displayFlag = "investCommodity"

        if request.form.get('gems'):
            commodity = 'gems'
            commodityPrice = PT.gemsPrice
            commodityToSubmit = commodity
            displayFlag = "investCommodity"

        if request.form.get('oil'):
            commodity = 'oil'
            commodityPrice = PT.oilPrice
            commodityToSubmit = commodity
            displayFlag = "investCommodity"

        if request.form.get('investResourceForm'):
            movesChecked = checkMoves(myNation, 'investResource')
            if movesChecked[1] > 0:
                print('Not enough moves or already carried this move out')
                return redirect(url_for('mainMenu'))

            investAmount = request.form.get('investResourceForm')
            investResult = investResourceFunction(myNation, investAmount,
                                                  commodityPrice,
                                                  commodityToSubmit, db)
            formMessage = investResult[1]

        if request.form.get('friendship'):
            displayFlag = "friendship"

        if request.form.get('resources'):
            displayFlag = "resources"

        if request.form.get('average'):
            displayFlag = "average"

        if request.form.get('historical'):
            displayFlag = "historical"

        if request.form.get('marketStock'):
            displayFlag = "stock"

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('investMenu.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesChecked[0],
                            PT=PT,
                            displayFlag=displayFlag,
                            message=message,
                            formMessage=formMessage,
                            commodity=commodity,
                            friends=friends))
Exemple #19
0
def gainResearchPoints(currentNation, averageRPOne, AverageRPTwo,
                       AverageRPThree, aggression, creativity, db):
    wealth = int(currentNation.wealth)
    era = currentNation.era
    rpOwned = int(currentNation.RP)

    # CHECK MAX MOVES
    returnCode = checkMoves(currentNation, 'gainResearch')[1]
    if returnCode > 0:
        #print(str(currentNation.country) + ' ALREADY GAINING RESEARCHING  ######')
        return (0, 'already researching')

    # Work out Average RP required for this Era
    rpAverageCost = int(
        averageRPCost(currentNation, averageRPOne, AverageRPTwo,
                      AverageRPThree))

    # CHECK WEALTH
    if wealth < 100:
        return (0, 'too poor to research')

    prob = 0

    if rpOwned < rpAverageCost: prob += 2

    if creativity > 80 and aggression > 60:
        prob += 4
    elif creativity > 70 and aggression > 50:
        prob += 3
    elif creativity > 60:
        prob += 2
    elif creativity > 60:
        prob += 1

    researchProbability = prob + random.randint(0, 2)
    #print('RESEARCH PROBABILITY: ' + str(researchProbability))
    # The two numbers are : INVESTMENT PERCENTAGE & WaitRounds
    if researchProbability > 6:  # far below average
        intensity = 'Overtime'
        amount = round((25 / 100) * wealth)
        researchOrder = 'submitted' + ',' + 'gainResearch' + ',' + 'overtime' + ',' + '25' + ',' + '8' + ',' + str(
            amount) + ':'
    elif researchProbability > 5:  # quite a bit below average
        intensity = 'Hard'
        amount = round((15 / 100) * wealth)
        researchOrder = 'submitted' + ',' + 'gainResearch' + ',' + 'hard' + ',' + '15' + ',' + '6' + ',' + str(
            amount) + ':'
    elif researchProbability > 4:  # just under average
        intensity = 'Medium'
        amount = round((10 / 100) * wealth)
        researchOrder = 'submitted' + ',' + 'gainResearch' + ',' + 'medium' + ',' + '10' + ',' + '4' + ',' + str(
            amount) + ':'
    elif researchProbability > 2:  # has double required
        intensity = 'Soft'
        amount = 0
        researchOrder = 'submitted' + ',' + 'gainResearch' + ',' + 'soft' + ',' + '0' + ',' + '2' + ',' + str(
            amount) + ':'
    else:
        return (currentNation)

    #Deduct in advance
    currentNation.wealth -= amount
    currentNation.Nextmoves += researchOrder
    print('##### RESEARCH ORDER SUBMITTED BY : ' + str(currentNation.country))
    db.session.commit()

    return (0, 'success')
Exemple #20
0
def researchTechnology(currentNation, era, creativity, averageRPOne,
                       AverageRPTwo, AverageRPThree, myTech, db):
    wealth = int(currentNation.wealth)
    era = currentNation.era
    rpOwned = currentNation.RP
    rpAverageCost = int(
        averageRPCost(currentNation, averageRPOne, AverageRPTwo,
                      AverageRPThree))

    # CHECK MAX MOVES
    returnCode = checkMoves(currentNation, 'research')[1]
    if returnCode > 0:
        #print(str(currentNation.country) + ' ALREADY RESEARCHING  ######')
        return (0, 'already researching')

    one = int(myTech.oneP)
    two = int(myTech.twoP)
    three = int(myTech.threeP)
    four = int(myTech.fourP)
    five = int(myTech.fiveP)

    # If AI is behind on development (say 30% of average) then do research
    myAverageCompletion = (one + two + three + four + five) / 5
    averageCompletionForAll = int(
        averageResearchCompletion(currentNation, era, db))

    # print('average Cost             : ' + str(rpAverageCost))
    # print('Rp Owned                 : ' + str(rpOwned))
    # print('myAverageCompletion      : ' + str(myAverageCompletion))
    # print('averageCompletionForAll  : ' + str(averageCompletionForAll))
    # print('one' + str(one))

    # Sum up probabilities
    researchTechProbability = 0
    if myAverageCompletion < (0.70 * averageCompletionForAll):
        researchTechProbability += 3

    if creativity > 80:
        researchTechProbability += 3

    if creativity > 67:
        researchTechProbability += 2
    if creativity > 50:
        researchTechProbability += 1
    if rpOwned > (0.1 * rpAverageCost):
        researchTechProbability += 2

    if rpOwned > (0.8 * rpAverageCost):
        researchTechProbability += 5

    researchTechProbability += random.randint(0, 2)

    if researchTechProbability > 2:
        # Get the index key for the lowest researched tech stream
        # This could no doubt be done in a loop...lazy coding but it works
        choiceArray = []
        if one < 100:
            choiceArray.append(['one', 'oneRp'])
        if two < 100:
            choiceArray.append(['two', 'twoRp'])
        if three < 100:
            choiceArray.append(['three', 'threeRp'])
        if four < 100:
            choiceArray.append(['four', 'fourRp'])
        if five < 100:
            choiceArray.append(['five', 'fiveRp'])

        if len(choiceArray) < 1:
            advanceMessage = advanceEra(currentNation, db)
            return (0, 'complete')

        # Sometimes wont always start from left to right
        targetTech = random.choice(choiceArray)
        techKey = targetTech[1]
        requiredRow = db.session.query(techEraCost).filter_by(era=era).first()
        required = getattr(requiredRow, techKey)
        techChoice = getattr(myTech, targetTech[0])
        nextMove = str('Submitted' + ',' + 'research' + ',' + str(era) + ',' +
                       str(techChoice) + ',' + str(techKey) + ',' +
                       str(required) + ':')
        #PLACE ORDER
        currentNation.Nextmoves += nextMove
        db.session.commit()

    return (0, 'complete')
Exemple #21
0
def researchMenu():
    year, month = getParms('year')
    myNation = getParms('myNation')
    playerTech = techAssets.query.filter_by(active=1,
                                            country=myNation.country).first()
    movesToCheck = checkMoves(myNation, '&^')
    movesLeft = movesToCheck[0]
    message = ""
    displayFlag = ""
    infoFlag = ""

    if request.method == 'POST':
        if request.form.get('advance'):
            advanceResult = advanceEra(playerTech, myNation, db)
            message = advanceResult[1]

        if request.form.get('develop'):
            # Works the best
            movesToCheck = checkMoves(myNation, 'research')
            movesLeft = movesToCheck[0]
            if movesToCheck[1] > 0:
                print('Ran out of moves')
                if movesToCheck[1] > 1:
                    print('Already carried this move out....')
                return redirect(url_for('mainMenu'))

            displayFlag = "tech"
            message = "Please pick a Technology to Research"

        if request.form.get('dev'):
            techResponse = request.form.get('dev')
            techChoice = str(techResponse).split(',')[0]
            techKey = str(techResponse).split(',')[1]

            techRow = techEraCost.query.filter_by(era=myNation.era).first()
            techCost = getattr(techRow, techKey)
            pointsEarned = getattr(playerTech, techKey)
            researchResult = researchTech(techChoice, techKey, techCost,
                                          pointsEarned, myNation, playerTech,
                                          db)
            message = researchResult[1]

        if request.form.get('grant'):
            # Works the best
            movesToCheck = checkMoves(myNation, 'gainResearch')
            movesLeft = movesToCheck[0]
            if movesToCheck[1] > 0:
                print('Ran out of moves')
                if movesToCheck[1] > 1:
                    print('Already carried this move out....')
                return redirect(url_for('mainMenu'))

            displayFlag = "grant"
            message = 'Please select a degree of commitment.'
        if request.form.get('intensity'):
            intensity = request.form.get('intensity')
            if intensity == 'info':
                displayFlag = "grant"
                infoFlag = 'info'

            grantsResponse = researchGrant(myNation, intensity, db)
            message = grantsResponse[1]

        if request.form.get('purchase'):
            return redirect(url_for('mainMenu'))

        if request.form.get('mainMenu'):
            return redirect(url_for('mainMenu'))

    return (render_template('researchMenu.html',
                            year=year,
                            month=month,
                            myNation=myNation,
                            movesLeft=movesLeft,
                            playerTech=playerTech,
                            message=message,
                            displayFlag=displayFlag,
                            infoFlag=infoFlag))
Exemple #22
0
def drill(currentNation, myWar, db):

    returnCode = checkMoves(currentNation, 'drill')[1]
    if returnCode > 0: return (0, 'already drilled')

    # BUILD PROBABILITY
    #-----------------
    averageMight, averageWealth, averageKnowledge, averageInfluence = getAverages(
    )
    might = int(currentNation.might)

    drillChance = 0
    if might < (0.5 * averageMight):
        drillChance += random.randint(0, 8)
    elif might < (0.8 * averageMight):
        drillChance += random.randint(0, 6)
    else:
        drillChance += random.randint(0, 4)

    # Warmongers gonna be warmongers
    if might > (2.5 * averageMight):
        drillChance += random.randint(0, 20)
    # Drop out if threshold not met
    if drillChance < 2:
        return (0, 'dropped')

    unitOne = int(myWar.wOneAmount)
    unitTwo = int(myWar.wTwoAmount)
    light = unitOne + unitTwo

    unitThree = int(myWar.wThreeAmount)
    unitFour = int(myWar.wFourAmount)
    unitFive = int(myWar.wFiveAmount)
    core = unitThree + unitFour + unitFive

    unitSix = int(myWar.wSixAmount)
    unitSeven = int(myWar.wSevenAmount)
    heavy = unitSix + unitSeven

    unitEight = int(myWar.wEightAmount)

    branchChoiceArray = []

    if light > 1:
        branchChoiceArray.append('light')
    if core > 1:
        branchChoiceArray.append('core')
    if heavy > 1:
        branchChoiceArray.append('heavy')

    # in the event there are no units
    if len(branchChoiceArray) < 1:
        return (0, 'dropped')

    branchChoice = random.choice(branchChoiceArray)

    # based upon selection
    # set up order form and clear out units for training
    if branchChoice == 'light':
        units = str(myWar.wOneAmount) + ',' + str(myWar.wTwoAmount) + ':'
        branch = 'Light Units'
        myWar.wOneAmount = 0
        myWar.wTwoAmount = 0
        db.session.commit()
    elif branchChoice == 'core':
        units = str(myWar.wThreeAmount) + ',' + str(
            myWar.wFourAmount) + ',' + str(myWar.wFiveAmount) + ':'
        branch = 'Core Division'
        myWar.wThreeAmount = 0
        myWar.wFourAmount = 0
        myWar.wFiveAmount = 0
        db.session.commit()
    elif branchChoice == 'heavy':
        units = str(myWar.wSixAmount) + ',' + str(myWar.wSevenAmount) + ':'
        branch = 'Heavy Forces'
        myWar.wSixAmount = 0
        myWar.wSevenAmount = 0
        db.session.commit()
    else:
        return (0, 'dropped')

    aggression = int(currentNation.aggression)
    augmentedAggresion = random.randint(0, (100 + aggression))

    # Ive tilted this a bit more towards harder drilling: can amend later
    if augmentedAggresion > 120:
        exposure = 'hard'
    elif augmentedAggresion > 85:
        exposure = 'medium'
    else:
        exposure = 'soft'

    drillOrder = 'drill' + ',' + str(branch) + ',' + str(
        exposure) + ',' + units
    # Place Order
    currentNation.Nextmoves += drillOrder
    db.session.commit()
    return (0, 'success')