Пример #1
0
def buystock_ask(context):  
    '''Prompts current player to choose whether to buy stock this turn'''

    stock_prices = {}

    for h in constants.hotels:
        if infos.chainsize(context, h) > 0:
            stock_prices[h] = infos.price(context, h)
    
    if len(stock_prices) == 0:
        return

    print "Player " + str(context['cp']) + ", you have " + str(context['player'][context['cp']]['cash']) + " dollars."

    if context['player'][context['cp']]['cash'] < min(stock_prices.values()):
        print "You cannot afford any available shares."
        return
    else: print "Would you like to buy stock?"

    buy = inputs.buystock_ask_input(context)

    if buy == 'Y':
        dataction.buystock(context)
    elif buy == 'N':
        print "Player " + str(context['cp']) + " does not purchase stock this turn."   
        return
    else: raise NameError("buystock_ask_input() returned something other than 'Y' or 'N'...")
Пример #2
0
def sell_stock(context, p, chain):
    '''shareholder chooses how much stock to sell when a chain is liquidated'''
    print "Player "  + str(p) + ", you have " + str(context['player'][p]['stock'][chain]) + " shares of " + chain + " stock."
    print "Do you want to sell any stock for $" + str(infos.price(context, chain)) + " per share?"

    sell = inputs.sell_stock_ask_input(context, p, chain)
    if sell == "Y":
        
        print "How many shares would you like to sell?"
        sell_shares = inputs.sell_stock_shares_input(context, p, chain)
    
        context['player'][p]['stock'][chain] -= sell_shares
        context['player'][p]['cash'] += (sell_shares * infos.price(context, chain))
        context['stock'][chain] += sell_shares
        print "Player " + str(p) + " sells " + str(sell_shares) + " shares of " + chain + " for a total of $" + str(sell_shares * infos.price(context, chain)) + "."
        
    else: #Player chooses not to sell stock this turn
        print "Player " + str(p) + " does not sell any " + chain + " stock."
Пример #3
0
def buystock_amt_input(context, buy_chain, shares_bought):
    '''raw input function for buystock()'''
    buy_shares = -1

    while buy_shares == -1:
        buy_shares = int(raw_input("How many shares of " + buy_chain + " would you like to buy?"))                      

        if (shares_bought + buy_shares) > 3:
            print "Maximum 3 shares per turn."
            buy_shares = -1
        elif (buy_shares * infos.price(context, buy_chain)) > context['player'][context['cp']]['cash']:
            print "You don't have enough money!"
            buy_shares = -1
        else: return buy_shares
Пример #4
0
def sell_stock_ask_input(context, p, chain):
    '''raw input function for sell_stock()'''
    "Tells player how many shares of the chain they have and asks if they want to sell any"
    print "Player "  + str(p) + ", you have " + str(context['player'][p]['stock'][chain]) + " shares of " + chain + " stock."
    sell = 0
    while sell == 0:
        sell = raw_input("Do you want to sell any stock for $" + str(infos.price(context, chain)) + " per share? (Y/N):")
        if sell in ["Y", 'y', 'Yes', "yes"]:
            return 'Y'
            break
        elif sell in ['n', 'N', 'no', 'No']:
            return 'N'
            break
        else:
            print "Bad Input."
            sell = 0
Пример #5
0
def buystock(context):
    '''Current player buys up to three shares of stock at the end of the turn''' 
    shares_bought = 0
    while 1 == 1:
        print "Available purchases are:"
        for h in infos.avail_stock(context).keys():
            print h + ": " + str(infos.avail_stock(context)[h]) + " shares available at $" + str(infos.price(context, h)) + " per share."
        buy_chain = inputs.buystock_chain_input(context)
        print "You have " + str(context['player'][context['cp']]['cash']) + " dollars."   
        buy_shares = inputs.buystock_amt_input(context, buy_chain, shares_bought)
        context['player'][context['cp']]['cash'] -= (buy_shares * infos.price(context, buy_chain))
        context['player'][context['cp']]['stock'][buy_chain] += buy_shares
        context['stock'][buy_chain] -= buy_shares
        shares_bought += buy_shares
        if shares_bought > 2:
                return
        else:
            done = inputs.done_input()
            if done == "N":
                return
Пример #6
0
def final_selloff(context):
    '''Automatically liquidates (with no player input) all existing chains, and awards shareholder bonuses and stock sale earnings'''
    chains_left = []
    for h in constants.hotels:
        if infos.chainsize(context, h)>1:
            chains_left.append(h)

    for h in chains_left:
        print "Liquidating " + h + ":"
        shareholders = {}
        for p in context['player'].keys():
            if context['player'][p]['stock'][h] > 0:
                shareholders[p] = context['player'][p]['stock'][h]
        
        if len(shareholders.keys()) == 0: #No shareholders
            print "No one owns stock in " + h + "? Tragic!"
            continue

        max_held =  max(set(shareholders.values()))

        if len(shareholders.keys()) == 1: # Only one shareholder
            big_winner = shareholders.keys()[0]
            print "Player " + str(big_winner) + " is the only shareholder in " + h + "."
            context['player'][big_winner]['cash'] += infos.sole_bonus(context, h)
            print "Player " + str(big_winner) + ' earns the mega-bonus of $' + str(infos.sole_bonus(context, h)) 
        elif shareholders.values().count(max_held) > 1: #Tie for max shareholder
            tied_holders = []
            for p in shareholders.keys():
                if shareholders[p] == max_held:
                    tied_holders.append(p)

            tied_bonus = (infos.maj_bonus(context, h) + infos.min_bonus(context, h)) / len(tied_holders)

            for th in tied_holders:
                print "Player " + str(th) + " is a tied max shareholder in " + h + "."
                context['player'][th]['cash'] += (tied_bonus)
                print "Player " + str(th) + " gets his split of the bounus: $" + str(tied_bonus) + "."

        else: #one max shareholder
            maj_holder = infos.find_key(shareholders, max_held)
            print "Player " + str(maj_holder) + " is the Majority Shareholder in " + h +"."
            context['player'][maj_holder]['cash'] += infos.maj_bonus(context, h)
            print "Player " + str(maj_holder) + " receives the Majority bonus of $" + str(infos.maj_bonus(context, h)) + "."

            # find the minority shareholder(s)...
            minority_holders = shareholders
            del minority_holders[maj_holder]
            max2_held = max(set(minority_holders.values()))
            
            if minority_holders.values().count(max2_held) == 1:  #There is one winning minority shareholder
                min_holder = minority_holders.keys()[0]
                print "Player " + str(min_holder) + " is the Minority Shareholder in " + h +"."
                context['player'][min_holder]['cash'] += infos.min_bonus(context, h)
                print "Player " + str(min_holder) + " receives the Minority bonus of $" + str(infos.min_bonus(context, liquid)) + "."

            else: #there is a tie for winning minority holder
                print "There is a tie for minority shareholder in " + liquid + '.'
                tied_holders = []
                for p in minority_holders.keys():
                    if minority_holders[p] == max2_held:
                        tied_holders.append(p)

                tie_min_bonus = infos.min_bonus(context, liquid)/minority_holders.values().count(max2_held)

                for th in tied_holders:
                    print "Player " + str(th) + " is a tied minority shareholder in " + h + "."
                    context['player'][th]['cash'] += (tie_min_bonus)
                    print "Player " + str(th) + " gets a split of the bounus, $:" + str(tie_min_bonus) + "."

        #Sell off all stock in chain
        for p in shareholders:
            context['player'][p]['cash'] += (context['player'][p]['stock'][h] * infos.price(context, h))
            print "Player " + str(p) + " earns $" + str((context['player'][p]['stock'][h] * infos.price(context, h))) + " from the sale of " + str(context['player'][p]['stock'][h]) + " shares of " + h + " stock."
            context['player'][p]['stock'][h] = 0