def __init__(self,playerCount): print ("Starting Game...") self.deck = deck() #If the game has a bunch of people, we need more cards, so we creat a double deck if playerCount >= 4: deck2 = deck() self.deck.cards.extend(deck2.cards) #Once we have all the cards, we shuffle them self.deck.shuffle() print ("Starting Deck Length: "+str(self.getDeckLength())) #Time to create players self.players = [] for x in range(0,playerCount): print ("Loading Player "+str(x)+"...") #Draw 5 cards for each player and insert them into our player list newPlayerHand = self.deck.drawCard(13) newPlayer = player(self,x,newPlayerHand) self.players.append(newPlayer) #We pick a starting card with onlyNumerical = true so we dont start with an action card self.currentCard = self.deck.drawCard(1,True) #index of current player (players list) self.currentPlayer = 0; #which direction the flow is going self.rotationManager = 1
def __init__(self, name = "nukes", deckfile = None): self.__name = name self.__state = GAME_STATE_INIT self.__popcards = deck("population") self.__deck = deck("main") self.__players = {} self.__turn = [] self.cur = None # Population the population cards...heh self.__popcards.add_card(12, int, [1]) self.__popcards.add_card(10, int, [2]) self.__popcards.add_card(8, int, [5]) self.__popcards.add_card(6, int, [10]) self.__popcards.add_card(4, int, [25]) if deckfile == None: return # Now for the main deck... try: self.__deck.load_file( open(deckfile, 'r'), {"warhead":warhead, "missile":missile, "bomber":bomber, "propaganda":propaganda}) except IOError, e: raise GameLogicError(self, (e.strerror == None) \ and e.message or e.strerror)
def __init__(self, cards): self.cards : deck = deck(cards) self.deck : deck = deck(self.cards) self.hand : deck = deck(self.deck.draw(5)) self.discard : deck = deck([]) self.actions : int = 1 self.buys : int = 1 self.treasure: int = 0 self.victory: int = 0
def __init__(self): self.deck = deck() self.pot = [] self.curentPot = [] self.playerActions = [] self.board = [] self.firstPlayerInd = 0
def multiprocess_simulator(num_deck, batch, queue): '''Puts the results of hand in a queue Parameters: num_deck (int): total number of decks required batch (int): total number of batches to run queue (multiprocessing.queues.Queue): queue to put the hand results in ''' player_won = 0 tie = 0 dealer_won = 0 for _ in range(0, batch): outcome = hand(deck(num_deck)) if outcome == 1: player_won += 1 if outcome == 0: tie += 1 if outcome == -1: dealer_won += 1 queue.put([player_won, tie, dealer_won])
def __init__(self): # initial board state stuff self.hints = 8 self.bombs = 3 self.played = [0] * len(COLORS) self.played_features = np.zeros([NUM_COLORS, NUM_VALUES]) # set up deck self.deck = deck() # set up discard pile self.discarded = [] self.discarded_features = np.zeros([NUM_COLORS, NUM_VALUES]) # set up each of the players' hands self.hands = [] for i in range(NUM_PLAYERS): self.hands.append(self.deck.deal()) # set up player states self.players = [] for i in range(NUM_PLAYERS): # cards you see in others' hands known = self.total_known_cards(self.get_known_in_hand(i), self.played_features, self.discarded_features) # create player with unfucked beliefs self.players.append(player(known, self.get_others_hands(i), self.hints, self.bombs, self.played)) # weight array used for both players self.weights = np.empty([ACTION_NUM, NUM_COLORS * NUM_VALUES * NUM_HAND * NUM_PLAYERS + 7]) self.weights.fill(0.1)
def __init__(self, player_number, play_area): self.deck = deck.deck() self.playerNumber = player_number self.hand = [] self.view = play_area self.hand_size = 5 self.card_list = []
def __init__(self,num_decks=1): #self.num_players = num_players self.deck = deck(num_decks) self.dealer = players(True) self.player = players(False) self.deck.shuffle()
def __init__(self, number_of_players, debug=False): self.deck = deck() if number_of_players < 2 or number_of_players > 10: sys.exit( "*** ERROR ***: Invalid number of players. It must be between 2 and 10." ) self.number_of_players = number_of_players self.debug = debug #This will print out the debug statements during execution
def end_turn(self): self.discard.topdeck(self.hand) self.cards = deck(self.deck.cards + self.discard.cards) self.victory = sum(c.victory for c in self.cards.get_by_kind('cv')) self.actions = 1 self.buys = 1 self.treasure = 0 self.draw(5) return
def __init__(self,kingdom): self.kingdom : dict[str, deck] = {} self.kingdom["province"] = deck([card("province","v",8,victory=6)]*8) self.kingdom["duchy"] = deck([card("duchy","v",5,victory=3)]*8) self.kingdom["estate"] = deck([card("estate","v",2,victory=1)]*12) self.kingdom["curse"] = deck([card("curse","c",0,victory=-1)]*8) self.kingdom["gold"] = deck([card("gold","t",6,treasure=3)]*30) self.kingdom["silver"] = deck([card("silver","t",3,treasure=2)]*40) self.kingdom["copper"] = deck([card("copper","t",0,treasure=1)]*60) for c in kingdom: self.kingdom[c.name] = deck([c]*10)
def random_test(): my_deck = deck() my_deck.shuffle() hands = [] while my_deck.size >= 5: my_hand = hand(my_deck.draw(5)) hands.append(my_hand) print(my_hand) print(my_hand.game) print('\n')
def make_deck(self, instruction=0): '''makes deck from an index or from an int or a dict''' return_deck = deck() try: instruction = self.all_instructions.pop(instruction) except TypeError:#invalid type indexing if isinstance(instruction, dict): pass #if it's a dict :D else: raise TypeError("instruction is not dict")#if not >:( except IndexError:#invalid indexing raise IndexError("invalid instruction index")#specify error #^this shit is just to make sure we get a single dict #...also specify error checking instruction = Dict(instruction) #make instruction a special dict (see 'Dict' class) attributes = Arribute_Dict(instruction["attributes"]) #seperate attributes for referencing get_repeat = lambda x=1:x if x>0 else 0 for card_instruction_name, card_instruction in instruction["cards"].iteritems(): print card_instruction_name #loop through each card instruction repeat = get_repeat(card_instruction["repeat"]) #format the repeat int to 0 or a positive int front_face_iter = self.make_card_face_iter(card_instruction["front_face"], attributes) back_face_iter = self.make_card_face_iter(card_instruction["back_face"], attributes) #make generators for the front and back of the cards for front, back in itertools.izip_longest(front_face_iter, back_face_iter, fillvalue={}): #loop through generators to get info for each card card_dict = { "front_face":dict(front), "back_face":dict(back) } #blank template to add card information for card class for repeat_card in range(repeat): return_deck.add_card(card(card_dict)) #add the repeated cards self.all_decks.append(return_deck) return return_deck
def constdb(): # define deck dk = deck.deck(1) dk.setdeck() # define table & player p = [deck.player('table',0)] p.append(deck.player('player',100)) # all possible card set for table tclist = cpair(dk,5) # file f = file('holdem_db.txt','w') f.write('tcard1\ttcard2\ttcard3\ttcard4\ttcard5\tpcard1\tpcard2\twin\tdraw\tlose\n') f.close()
def __init__(self): # Initialize a new game dealer_id = random_number(3) # Choose random first dealer self.dealer = dealer_id # Assign the dealer ID self.gen_players() # Generate players self.deck = deck() # Generate the deck self.kitty = [] # Initialize the kitty self.hands = [] # Initialize hands self.trump = None # Initialize trump self.alone = -1 # Initialize whether someone is alone self.caller = None # Initialize person who called trump self.make_teams() # Split players into teams self.deal_cards() # Divide cards between players self.play_game() # Start game
def __init__(self): """ dictionary mapping users --> [bet, card1, card2...card-n] """ self.users = {} self.deck = deck.deck() """ locks the play thread if none of the players have decided their next move, whether that be stand or hit """ self.hitLock = threading.Lock() """ the condition so that the play thread will wait until a player has decided what to do as their move """ self.waitForHit = threading.Condition(self.hitLock) self.hitting = True
def constdb(): # define deck dk = deck.deck(1) dk.setdeck() # define table & player p = [deck.player('table', 0)] p.append(deck.player('player', 100)) # all possible card set for table tclist = cpair(dk, 5) # file f = file('holdem_db.txt', 'w') f.write( 'tcard1\ttcard2\ttcard3\ttcard4\ttcard5\tpcard1\tpcard2\twin\tdraw\tlose\n' ) f.close()
def draw(self, count=1): if count == 0: pass elif len(self.deck) > count: self.hand.topdeck(self.deck.draw(count)) else: my_draw = self.deck.draw(len(self.deck)) if len(self.discard) == 0: self.hand.topdeck(my_draw) return self.deck = self.discard self.deck.shuffle() self.discard = deck() if len(self.deck) >= count - len(my_draw): my_draw += self.deck.draw(count - len(my_draw)) else: my_draw += self.deck.draw(len(self.deck)) self.hand.topdeck(my_draw)
def main(): players=[player() for i in range(4)] players[0].setMode(not _debugAllAI) for i in range(0,4): players[i].setAllPlayers(players) players[i].setPlayerNum(i) overAllScore = [0, 0, 0, 0] playedRounds = 0 while True not in [i > 99 for i in overAllScore]: # each game is a loop playedRounds += 1 [each[0].getHand(each[1]) for each in zip(players, deck().fourHands())] handOutTurn(players, overAllScore, playedRounds) playTurn(players, overAllScore, playedRounds) print() trace() print('You get ' + ['first', 'second', 'third', 'last'] [[i for i in range(4) if sorted(overAllScore)[i] == overAllScore[0]][0]] + 'place.')
def multiprocess_simulator(num_deck, num_players, batch, queue): player_list = [] total_tie = 0 total_dealer_won = 0 for _ in range(0, batch): player_won, tie, dealer_won = hand(deck(num_deck), num_players) if not player_list: player_list = player_won else: for i, j in enumerate(player_won): player_list[i] += j total_tie += tie total_dealer_won += dealer_won queue.put([player_list, total_tie, total_dealer_won])
def do_work(cards=0, hands=0, verbose=False, queue=None, _id=1): card_deck = deck(verbose) results = {} for i in range(hands): if verbose: print '\nDrawing hand #%s...' % (i * _id) cur_hand = card_deck.get_hand(cards, verbose) res = cur_hand.score() if res not in results.keys(): results[res] = 1 else: results[res] += 1 # End if/else block # End for if not queue: return results else: queue.put(results) return
def test_length(self): test1 = deck() self.assertEqual(len(test1.cards), 52)
# Created by : James Lee # Created on : June 2019 # The main program from deck import deck from card import card from hand import hand from player import player # All the ranks and suits ranks = ['K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3', '2', 'A'] suits = ['Spades', 'Hearts', 'Clubs', 'Diamonds'] # Creates deck deckOfCards = deck() # Creates all the cards, then puts into deck for i in range(len(ranks)): for j in range(len(suits)): c = card(suits[j], ranks[i]) deckOfCards.addCard(c) # Shuffles deck deckOfCards.shuffle() print( "Welcome to Blackjack! The objective of the game is to draw cards until you get cards with values as close to 21 as possible!" ) while True:
def holdem(n): # define deck dk = deck.deck(1) dk.setdeck() # define table p = [deck.player("table", 0)] for i in range(n): p.append(deck.player(str(i + 1), 100)) # deal 2 cards to each for i in range(1, len(p)): p[i].take(dk.deal()) p[i].take(dk.deal()) # bet ## # deal 2 cards to table p[0].take(dk.deal()) p[0].take(dk.deal()) # show table cards print "table cards" p[0].showcards() # bet ## # deal 3 more cards to table p[0].take(dk.deal()) p[0].take(dk.deal()) p[0].take(dk.deal()) # show table cards print "table cards" p[0].showcards() print "" # bet ## # check # get best cards of each best = [] for i in range(1, len(p)): if p[i].status == 1: continue temp = p[0].getcards() for j in range(len(temp)): p[i].take(temp[j]) best.append([checker.extract(p[i].getcards(), 5), i]) # check the winner win = [0] for i in range(1, len(best)): fight = checker.compete([best[win[0]][0], best[i][0]]) if fight == 2: win = [i] elif fight == 1: win.append(i) # show result for i in range(len(best)): p[best[i][1]].showcards() print p[best[i][1]].name + ": " + score[checker.order(best[i][0])] for j in range(len(best[i][0])): print best[i][0][j] print "" print "The winner is " for i in range(len(win)): print p[best[win[i]][1]].name
def __init__(self, playerColorChoice, enemyPlayerCount, comp1Skill=None, comp1Disp=None, comp2Skill=None, comp2Disp=None, comp3Skill=None, comp3Disp=None): tempMostValuablePawn = None # These pawns are declared here. The purpose of these pawn references tempMiddleValuablePawn = None # is for integration with the GUI. After each call of the computer's tempLeastValuablePawn = None # drawAndMove method, these values are updated accordingly. colorChoiceList = ["green", "yellow", "blue", "red"] self.userPlayer = player.player(playerColorChoice) self.userPlayer.setUserPlayerFlag() colorChoiceList.remove(playerColorChoice) self.totalPlayerCount = enemyPlayerCount + 1 # This hefty section sets the skill and disposition flags for individual # computer players based on the boolean input values in the constructor. if enemyPlayerCount == 3: self.compPlayer1 = player.player(colorChoiceList.pop()) if comp1Skill == True and comp1Disp == True: self.compPlayer1.setSmartMeanCompFlag() elif comp1Skill == True and comp1Disp == False: self.compPlayer1.setSmartNiceCompFlag() elif comp1Skill == False and comp1Disp == True: self.compPlayer1.setDumbMeanCompFlag() else: self.compPlayer1.setDumbNiceCompFlag() self.compPlayer2 = player.player(colorChoiceList.pop()) if comp2Skill == True and comp2Disp == True: self.compPlayer2.setSmartMeanCompFlag() elif comp2Skill == True and comp2Disp == False: self.compPlayer2.setSmartNiceCompFlag() elif comp2Skill == False and comp2Disp == True: self.compPlayer2.setDumbMeanCompFlag() else: self.compPlayer2.setDumbNiceCompFlag() self.compPlayer3 = player.player(colorChoiceList.pop()) if comp3Skill == True and comp3Disp == True: self.compPlayer3.setSmartMeanCompFlag() elif comp3Skill == True and comp3Disp == False: self.compPlayer3.setSmartNiceCompFlag() elif comp3Skill == False and comp3Disp == True: self.compPlayer3.setDumbMeanCompFlag() else: self.compPlayer3.setDumbNiceCompFlag() elif enemyPlayerCount == 2: self.compPlayer1 = player.player(colorChoiceList.pop()) if comp1Skill == True and comp1Disp == True: self.compPlayer1.setSmartMeanCompFlag() elif comp1Skill == True and comp1Disp == False: self.compPlayer1.setSmartNiceCompFlag() elif comp1Skill == False and comp1Disp == True: self.compPlayer1.setDumbMeanCompFlag() else: self.compPlayer1.setDumbNiceCompFlag() self.compPlayer2 = player.player(colorChoiceList.pop()) if comp2Skill == True and comp2Disp == True: self.compPlayer2.setSmartMeanCompFlag() elif comp2Skill == True and comp2Disp == False: self.compPlayer2.setSmartNiceCompFlag() elif comp2Skill == False and comp2Disp == True: self.compPlayer2.setDumbMeanCompFlag() else: self.compPlayer2.setDumbNiceCompFlag() elif enemyPlayerCount == 1: self.compPlayer1 = player.player(colorChoiceList.pop()) if comp1Skill == True and comp1Disp == True: self.compPlayer1.setSmartMeanCompFlag() elif comp1Skill == True and comp1Disp == False: self.compPlayer1.setSmartNiceCompFlag() elif comp1Skill == False and comp1Disp == True: self.compPlayer1.setDumbMeanCompFlag() else: self.compPlayer1.setDumbNiceCompFlag() # The common square list represents all 60 of the common white squares # of the board all of the individual pawns may occupy. There are also # individual red, blue, yellow, and green square lists which represent # the 5 squares of the safety ramp for their particular color. Each # color also has a start and end position from which pawns of their # respective color may be popped and pushed. self.commonSquareList = [] self.redSquareList = [] self.blueSquareList = [] self.yellowSquareList = [] self.greenSquareList = [] for i in range(60): self.commonSquareList.append(self.square()) for i in range(5): self.redSquareList.append(self.square()) self.blueSquareList.append(self.square()) self.yellowSquareList.append(self.square()) self.greenSquareList.append(self.square()) # Note: these start zone fields may be deprecated. I intend to simply # use the pawns' flags to determine whether they are in the start zone # or not, as such although these start zone fields may exist in the code, # they may not be used. They would be a great thing to refactor out. self.redStartZone = [] self.blueStartZone = [] self.yellowStartZone = [] self.greenStartZone = [] self.redEndZone = [] self.blueEndZone = [] self.yellowEndZone = [] self.greenEndZone = [] # The board class also has a deck which may be drawn from. self.cardDeck = deck.deck()
def __int___(self): self.score = 0 self.hand = deck()
import sys #just add the directory where the BA folder is on your computer sys.path.append('C:/Users/Nino/Google Drive/Studium/FS 2021/Bachelorarbeit/BA') sys.path.append('C:/Users/Nino/Google Drive/Studium/FS 2021/Bachelorarbeit/BA/ebplate') import initial_cs as ics from proofs import global_buckling as globb from proofs import local_buckling as locb from output import geometry_output as go import data import deck from classes import merge from classes import stiffener as st from proofs import buckling_proof data.input_data.update({"b_inf": 3000}) data.input_data.update({"b_sup": 4000}) data.input_data.update({"h": 1500}) data.input_data.update({"M_Ed": 50*10**9}) data.input_data.update({"Q_Ed": 1000}) data.input_data.update({"T_Ed": 1000}) data.input_data.update({"a": 1000}) data.input_data.update({"L_e": 1000}) data.input_data.update({"bending type": "sagging bending"}) data.input_data.update({"cs position": 1000}) initial_cs = ics.create_initial_cs(4000, 3000, 1500, 4, 4, 4) deck_stiffeners = deck.deck(4000) stiffened_cs = merge.merge(initial_cs, deck_stiffeners) buckling_proof.buckling_proof(stiffened_cs)
def __init__(self, number_of_players, debug = False): self.deck = deck() if number_of_players < 2 or number_of_players > 10: sys.exit("*** ERROR ***: Invalid number of players. It must be between 2 and 10.") self.number_of_players = number_of_players self.debug = debug
def make_deck(self): self.deck_name = self.deck_entry.get() self.new_deck = deck.deck(self.deck_name) self.name_entry.grid_forget() self.name_button.grid_forget() self.refresh_cards()
sys.path.append('C:/Users/Vinzenz Müller/Dropbox/ETH/6. Semester/BA') #script for analysing an existing crosssection from classes import stiffener from classes import crosssection from input import input_analysis_tool from proofs import buckling_proof import initial_cs import data import deck from output import geometry_output import math from optimizer import opt_eqpressure import defaults defaults.do_deck_as_prop = True #crosssection input and creation (only trapezoid plates) input_analysis_tool.set_cs_geometry() #set forces input_analysis_tool.set_forces() #data.check_input_data_complete() cs = initial_cs.create_initial_cs(data.input_data.get("b_sup"), data.input_data.get("b_inf"), data.input_data.get("h"), data.input_data.get("t_side"), data.input_data.get("t_deck"), data.input_data.get("t_bottom")) #add the deck stiffeners st_prop_deck = deck.deck(data.input_data.get("b_sup")) assert st_prop_deck.stiffeners != [], "st_prop_list is empty" opt_eqpressure.opt_eqpressure(cs, st_prop_deck)
from random import randint import sys import time import shelve import msgpack if __name__ == '__main__': pass top = 21 db=shelve.open("Jack.txt") playerm=db ['money'] count=0 bet=int(raw_input("Place your bet: ")) playerm=playerm-bet game = deck.deck() one = game.SelectCard(randint(0, 51)) two = game.SelectCard(randint(0, 51)) play=one dealer=two resd = "h" res = "h" p=game.SelectCard(randint(0, 51)) q=game.SelectCard(randint(0, 51)) if play==11 and p==11: play+=1 else: play+=p if dealer==11 and q==11: dealer+=1
from deck import deck discard_pile = deck() draw_pile = deck(True) draw_pile.fan() discard_pile.fan()
def test_deck_shuffle(self): test4 = deck() test4_copy = deck() test4.shuffle() self.assertEqual(len(test4.cards), 52) self.assertNotEqual(test4.cards, test4_copy.cards)
#sys.path.append('C:/Users/Vinzenz Müller/Dropbox/ETH/6. Semester/BA') import initial_cs as ics import math from classes import stiffener as st from output import geometry_output as go from classes import point as pt from classes import line as ln from classes import plate_code as plcd from classes import crosssection as cs from classes import merge import deck initial_cs = ics.create_initial_cs(4000, 4000, 2000, 20, 20, 20) st_list_deck = deck.deck(4000) s = len(st_list_deck) stiffener_1 = st.create_stiffener_global(2, s+1, -2000, 1000, 3*math.pi/2, 200, 100, 100, 10) stiffener_2 = st.create_stiffener_global(3, s+2, -1000, 2000, math.pi, 300, 200, 200, 15) stiffener_3 = st.create_stiffener_global(3, s+3, 1000, 2000, math.pi, 300, 200, 200, 15) stiffener_4 = st.create_stiffener_global(4, s+4, 2000, 1000, math.pi/2, 200, 100, 100, 10) st_list_rest = [stiffener_1, stiffener_2, stiffener_3, stiffener_4] st_list = st_list_deck + st_list_rest print(len(st_list))
Current game functionality: - single player. - player can bet if balance > 0. - dealer follows basic blackjack rules (will hit until >= 17 or bust). - Ace is valued at 11 only. - dealer wins if scores are even. - all winning bets are paid out 2:1. ''' import os from deck import deck from player import player from dealer import dealer deck = deck() player = player('Player',100) dealer = dealer('Dealer') bet = 0 round_over = False game_over = False replay = 'n' #loop that contains game while not game_over: #clear output, reset deck,bet,round_over os.system('clear') deck.reset() bet = 0 round_over = False #print player balance, check balance not 0.
from __future__ import division import deck import matplotlib.pyplot as plt import numpy # create a deck d = deck.deck() balanced = [] points = [] num = int(1e4) steps = num // 10 for i in range(num): if (i+1) % steps == 0: print("%d of %d" % (i+1, num)) d.shuffle(7) d.cut() h1, h2, h3, h4 = d.deal() balanced.append([h1.balanced, h2.balanced, h3.balanced, h4.balanced]) points.append([h1.hc_points, h2.hc_points, h3.hc_points, h4.hc_points]) balanced = zip(*balanced)
def test_deal_all_length(self): test3 = deck() test3.deal_all() self.assertEqual(len(test3.cards), 0)
def PlayHand(): import deck import hand prompt = 'H' player = hand.hand() dealer = hand.hand() #new deck mazo = deck.deck() #Shuffle new deck mazo.shuffle() #deal two cards to player player.hit(mazo) player.hit(mazo) #deal two cards to dealer and only show the first card print("\nThe dealer is showing a", dealer.hit(mazo)) dealer.hit(mazo) #create loop to keep playing if need it while prompt == 'H' and not player.bust() and not player.have21(): print("\nYour hand:\n") player.Print() print("You have a total of", player.value()) prompt = input("\nHit (H) or Stand (S): ").upper() if prompt == 'H': print("\nYou got the", player.hit(mazo)) #Player black jack, stop asking hit or stand if player.blackjack(): print("\nYour hand:\n") player.Print() print("************") print("*Black Jack*") print("************") #Player has 21, stop asking hit or stand if player.have21(): print("\nYour hand:\n") player.Print() print("You have a total of", player.value()) #Player busted, stop asking hit or stand and return false if player.bust(): print("\nYour hand:\n") player.Print() print("You have a total of", player.value()) print("\nYou busted, Dealer wins!") return False #Dealer keep getting cards until it reaches 17 while dealer.value() < 17: dealer.hit(mazo) print("\nDealer's hand:\n") dealer.Print() print("Dealer has a total of", dealer.value(), "\n") #Dealer has blackjack wins and return false if dealer.blackjack(): print("Dealer has a Black Jack!") print("Dealer wins!") return False #Player has blackjack wins only if dealer doesnt have blackjack if player.blackjack(): print("Blackjack, you win!") return True #dealer is higher or equal than player without bustin, dealer wins if player.value() <= dealer.value() and not dealer.bust(): print("Dealer wins!") return False #player is higher than dealer if player.value() > dealer.value(): print("Player wins!") return True #dealer bust if dealer.bust(): print("Dealer busted, you win!") return True
def __init__(self): """ Initializes dict of users in the room and a deck. """ self.users = {} self.deck = deck.deck()
def war(n=1, verbose=False, stagger=False) : x = deck(n) y = deck(n) x.shuffle() y.shuffle() while len(x) and len(y) : assert len(x) + len(y) == 104*n if verbose : print ("x:" + str(len(x)) + " y:" + str(len(y)) + " | ") , cx = x.top() cy = y.top() if verbose : print (str(cx) + " versus " + str(cy)) , if cx > cy : if verbose : print "x wins" x.add(cx) x.add(cy) elif cy > cx : if verbose : print "y wins" y.add(cy) y.add(cx) else : #battle if verbose : print "\nBATTLE!" if stagger : time.sleep(1.3) won = False victory_list = [cx, cy] while not won : stake_x = x.create_stakes() if stake_x is None : break stake_y = y.create_stakes() if stake_y is None : break vx = x.top() vy = y.top() victory_list += (stake_x + stake_y + [vx, vy]) if verbose : print "\t" + str(vx) + " versus " + str(vy) if stagger : time.sleep(.65) if vx > vy : random.shuffle(victory_list) if verbose : print "\tx wins: " + str(map(str,victory_list)) + " length: " + str(len(victory_list)) x.add_all(victory_list) won = True elif vy > vx : if verbose : print "\ty wins: " + str(map(str,victory_list)) + " length: " + str(len(victory_list)) random.shuffle(victory_list) y.add_all(victory_list) won = True if stagger : time.sleep(.65) if stagger : time.sleep(.65) if len(x) : print "x wins!" elif len(y) : print "y wins!" else : print "tie??"
''' Created on Jun 25, 2018 @author: Yo boi konstantin ''' from deck import deck feed = 0 Bicicle = deck() Bicicle.shufffle() purple = Bicicle.getdeck() def show(): print('Your Hand: ') for b in range(len(p1)): print(p1[b].toString()) print('Sum: ', p1tot) print('Dealer\'s Hand:', p2[0].toString(), ' ',p2[1].toString(), ' Sum: ',p2tot) while feed != 'quit': game = False feed = input('Do you want to quit? Type Q to quit or skip this to continue: ') p1 = [purple[0]] del purple[0] p2 = [purple[0]] del purple [0] p1.append(purple[0]) del purple[0] p2.append(purple[0]) del purple[0] p1tot = 0 p2tot = 0 while game != True: p1tot = 0
def __init__(self, number_of_players, debug = False): self.deck = deck() if number_of_players < 2 or number_of_players > 10: sys.exit("*** ERROR ***: Invalid number of players. It must be between 2 and 10.") self.number_of_players = number_of_players self.debug = debug #This will print out the debug statements during execution