def loan(current_player): # clients = get_clients() current_player.player_amount += 100000 print("{} {}".format(current_player.player_name, ' loaned.')) broadcast(current_player.player_name + ' loaned some money.') print_name_amt_shares(current_player) card_discard(current_player, 'Loan')
def debenture(current_player, company): # clients = get_clients() if company.company_current_price == 0 and current_player.player_shares[ company.company_name]: current_player.player_amount += \ current_player.player_shares[company.company_name] * company.company_starting_price current_player.player_shares[company.company_name] = 0 company.company_total_buy_shares += current_player.player_shares[ company.company_name] print("{} {}".format(current_player.player_name, ' debenture')) broadcast(current_player.player_name + ' played debenture.') print_name_amt_shares(current_player) card_discard(current_player, 'Debenture')
def player_choice(current_player, lp): clients = get_clients() com_name_list = get_cnl() current_turn = get_current_turn() global list_of_players list_of_players = lp choice = current_player.player_connection.recv(1024).decode().split(',') try: if choice[0] in ['pass', '']: print("{} {}".format(current_player.player_name, choice[0])) broadcast(current_player.player_name + " passed.") time.sleep(1) return elif choice[0] in ['buy', 'sell', 'sbuy', 'ssell']: company = com_name_list[int(choice[1]) - 1] if choice[0] == 'buy': buy(clients, current_player, company, int(choice[2])) elif choice[0] == 'sell': sell(clients, current_player, company, int(choice[2])) elif choice[0] == 'ssell': ssell(clients, current_player, company, int(choice[2])) else: sbuy(clients, current_player, company, int(choice[2])) return elif choice[0] == 'loan' and card_check(current_player, choice[0]): loan(current_player) elif choice[0] == 'debenture' and card_check(current_player, choice[0]): company = com_name_list[int(choice[1]) - 1] debenture(current_player, company) elif choice[0] == 'rights' and card_check(current_player, choice[0]): company = com_name_list[int(choice[1]) - 1] print("Current player before rights {}".format( current_player.player_name)) rights(company, lp, current_turn, current_player) print("Current player after rights {}".format( current_player.player_name)) print("{} {}".format(current_player.player_name, choice)) for player in lp: if player == current_player: continue else: print_name_amt_shares(player) return except Exception as e: print(str(e)) current_player.player_connection.send(str.encode('play')) time.sleep(1) player_choice(current_player, lp)
def sbuy(clients, current_player, company, shares): if current_player.player_shares.get(company.company_name, 0) <= shares: current_player.player_shares[company.company_name] = \ current_player.player_shares.get(company.company_name,0) + shares current_player.player_amount += shares * company.company_current_price * 2 company.company_total_sell_shares += shares broadcast(current_player.player_name + ',' + ','.join(["does not short sell ",\ company.company_name, str(shares)])) print_name_amt_shares(current_player) print("{} {}".format(current_player.player_name, 'buys short sold')) else: current_player.player_connection.send( str.encode("Not enough shares to buy. \n")) time.sleep(1) current_player.player_connection.send(str.encode('play')) time.sleep(1) player_choice(current_player, list_of_players)
def sell(clients, current_player, company, shares): if current_player.player_shares.get(company.company_name, 0) >= shares: current_player.player_amount += shares * company.company_current_price company.company_total_buy_shares += shares current_player.player_shares[company.company_name] = \ current_player.player_shares.get(company.company_name,0) - shares broadcast(', '.join([ current_player.player_name, "sold", company.company_name, str(shares) ])) print_name_amt_shares(current_player) print("{} {}".format(current_player.player_name, 'sells')) else: current_player.player_connection.send( str.encode("Not enough shares to sell. \n")) time.sleep(1) current_player.player_connection.send(str.encode('play')) time.sleep(1) player_choice(current_player, list_of_players)
def buy(clients, current_player, company, shares): if current_player.player_amount >= shares * company.company_current_price and \ shares <= company.company_total_buy_shares: current_player.player_amount -= shares * company.company_current_price company.company_total_buy_shares -= shares current_player.player_shares[company.company_name] = \ current_player.player_shares.get(company.company_name,0) + shares broadcast(', '.join([ current_player.player_name, "bought", company.company_name, str(shares) ])) print_name_amt_shares(current_player) print("{} {}".format(current_player.player_name, 'buys')) else: current_player.player_connection.send(str.encode("Not enough money to"\ " buy the shares or not enough shares available. \n")) time.sleep(1) current_player.player_connection.send(str.encode('play')) time.sleep(1) player_choice(current_player, list_of_players)
def ssell(clients, current_player, company, shares): cost = shares * company.company_current_price * 2 if current_player.player_shares.get(company.company_name,0) <= 0 and \ current_player.player_amount >= cost: current_player.player_amount -= cost current_player.player_shares[company.company_name] = \ current_player.player_shares.get(company.company_name,0) - shares company.company_total_sell_shares -= shares broadcast(', '.join([ current_player.player_name, "shorts", company.company_name, str(shares) ])) print_name_amt_shares(current_player) print("{} {}".format(current_player.player_name, 'shorts')) else: current_player.player_connection.send(str.encode("Not enough shares to sell or not "\ + "enough money. \n")) time.sleep(1) current_player.player_connection.send(str.encode('play')) time.sleep(1) player_choice(current_player, list_of_players)
def rights(company, lp, name, cp): # clients = get_clients() broadcast(', '.join( [cp.player_name, " invoked rights in ", company.company_name])) for _ in range(len(lp)): available_shares = min((cp.player_shares.get(company.company_name)//2000) * \ 1000, company.company_total_buy_shares) check_amount = cp.player_amount - available_shares * 10 if check_amount < 0: max_shares = (cp.player_amount // 10000) cp.player_shares[company.company_name] = cp.player_shares.get(company.company_name) \ + max_shares * 1000 cp.player_amount -= max_shares * 10000 company.company_total_buy_shares -= max_shares * 1000 print(cp.player_name, cp.player_amount, cp.player_shares) else: cp.player_shares[company.company_name] += available_shares cp.player_amount = check_amount company.company_total_buy_shares -= available_shares print_name_amt_shares(cp) cp = lp[next(name)] card_discard(cp, 'Rights') return