def __init__(self, library): self.log = logger.console_logger(logger.get_output_level()) self.current_state = self.GameInit self.players = [] self.player_count = 0 self.library = library self.starting_player = None self.current_player = None self.turns = 0 self.lineups = [] self.buyable_powers = [] self.curses = [] self.main_deck = cards.card_deck() self.change_turn = None self.card_played = None self.lineup_changed = None self.drawn_card = None self.ask_player = None self.game_text = None self.refresh_hands = None self.player_choices = [] self.pending_choice = None self.supervilains = cards.card_deck() self.current_supervilain = None self.destroyed_cards = []
def eq_class3_rollout(hand, no_players): for i in range(no_players): create_players(no_players) #hand = eq_class3[i] deck = cards.card_deck() deck.remove(hand) players[0].hand = hand #deck = cards.shuffle_cards(deck) for i in range(2): for j in range(1,no_players-1): players[j].hand.append(deck.deal_one_card()) flop(deck) river(deck) turn(deck) #for player in players: # print player.no, player.hand #print table try: s = showdown() #table_entry += s del table[:] #return table_entry return s except Exception as inst: print inst print s
def simulate_game(self, player_cards, p): deck = cards.card_deck() final_results = {"win": 0, "loss": 0, "tie": 0} for j in range(self.R): self.remove_card_from_deck(deck.cards, player_cards) # deal cards to opponents opponents = [] for i in range(p): opponents.append(deck.deal_n_cards(2)) # play and calculate wins/loss/ties shared_cards = deck.deal_n_cards(5) temp_results = self.calculate_results(player_cards, opponents, shared_cards) final_results['win'] += temp_results['win'] final_results['loss'] += temp_results['loss'] final_results['tie'] += temp_results['tie'] deck.reset() return final_results
def simulate_game(self, player_cards, p): deck = cards.card_deck() final_results = {"win": 0, "loss":0, "tie": 0} for j in range(self.R): self.remove_card_from_deck(deck.cards, player_cards) # deal cards to opponents opponents = [] for i in range(p): opponents.append(deck.deal_n_cards(2)) # play and calculate wins/loss/ties shared_cards = deck.deal_n_cards(5) temp_results = self.calculate_results(player_cards, opponents, shared_cards) final_results['win'] += temp_results['win'] final_results['loss'] += temp_results['loss'] final_results['tie'] += temp_results['tie'] deck.reset() return final_results
def new_round(): global deck for player in players: player.clear_hand() player.in_game = True player.bet = 0 table.clear_table() deck = cards.card_deck()
def new_round(): global deck global game for player in game.getPlayers(): player.clear_hand() player.in_game = True player.bet = 0 player.strategy.setBluffing(False) game.getTable().clear_table() game.finished = False deck = cards.card_deck() return deck
def eq_class_rollout(hand, no_players): for i in range(no_players): create_players(no_players) deck = cards.card_deck() deck.remove(hand) players[0].hand = hand for i in range(2): for j in range(1, no_players-1): players[j].hand.append(deck.deal_one_card()) flop(deck) river(deck) turn(deck) try: s = showdown() del table[:] return s except Exception as inst: print inst print s
def __init__(self, player_id, name): self.player_id = player_id self.name = name self.superhero = None self.passive_superhero = False self.base_hand_size = 5 self.next_hand_size = self.base_hand_size self.discard_pile = [] self.played_cards = [] self.gained_cards = [] self.total_power = 0 self.deck = cards.card_deck() self.is_playing = False self.hand = [] self.superhero_bonuses = []
def play(): game_finished = False new_round() deal_hole_cards() global table table = Table() # this object will store all relevant information about the game # still to be implemented game = Game_State(table, players, False) global deck # This while is just to keep the game going until there's only 1 player left, as proper betting is not implemented yet while not game.finished: remaining = find_remaining(players) print len(remaining) if len(remaining) < 2: game.finished = True player_won(remaining[0]) break small_blind = remaining[0] big_blind = remaining[1] betting.small_blind(small_blind, table) betting.big_blind(big_blind, table) pre_flop(game) flop() bet(game) small_blind.blind = False big_blind.blind = False turn() bet(game) river() bet(game) if len(remaining) > 1: showdown(game) random.shuffle(players) table.clear_table() deck = cards.card_deck()
# # import random import cards import betting from table import Table from game_state import Game_State from player import Player game = Game_State() # the game object containing all the game info. no_players = 0 remaining = 0 no_games = 0 money = 0 deck = cards.card_deck() no_bets = 3 def print_players_final(): global game for player in game.getPlayers(): print "Player", player.no, " - ", player.get_money() def print_players(): global game for player in game.getRemaining(): if player.in_game: print "Player", player.no, "has the hand", player.get_hand(), "has", player.get_money(), "dollars and have bet", player.get_bet() def print_table(): global game
def tryit(p, t, no): global deck global player_hand global table #deck = cards.card_deck() #player_hand = deck.deal_n_cards(2) #table = deck.deal_n_cards(3) deck = cards.card_deck() player_hand = p table = t no_players = no #print "Player:", player_hand #print "Table:", table deck = cards.gen_52_cards() for card in player_hand: #print "player:HAND: ", player_hand deck.remove(card) for card in table: #print "**********************" #print card #print deck #print "**********************" deck.remove(card) possible_hands = [] for i in range(len(deck)-1): for j in range(i+1, len(deck)): h = [deck[i], deck[j]] possible_hands.append(h) #print len(possible_hands) #for i in range(2): # print "Opponent:", possible_hands[i] result = [] for o in possible_hands: players_power = [] #o = possible_hands[i] r = [] r.append(player_hand) r.append(o) s = showdown(r) result.append(s) #print len(result) wins = 0 draws = 0 losses = 0 for e in result: if e == "w": wins += 1 elif e == "d": draws += 1 elif e == "l": losses += 1 #print wins, draws, losses strength = (((wins+draws/2.0)/(wins+draws+losses))**no_players)*100 return strength
def start_game(self): self.deck = cards.card_deck() # Main game loop/structure. Based on Texas Hold 'Em rules for i in range(self.n_rounds): # Reset info self.deck.reset() self.state = 1 # 1 = Pre-flop self.round = i print('\n') print("================================== Round #", self.round, "State: ",self.state," ========================================") # Shuffle for big blind/small blind if(i != 0): self.players.append(self.players.pop(0)) # Reset info. self.pot = 0 self.flop = [] self.turn = [] self.river = [] self.shared_cards = [] self.active_players = self.players[:] self.total_raises = 0 # Deal hole cards j = 0 for p in self.active_players: if p == None: continue small_blind_player = j == len(self.players)-2 big_blind_player = j == len(self.players)-1 self.pot += p.new_round(small_blind_player, big_blind_player) p.set_cards(self.deck.deal_n_cards(2)) j += 1 self.log("Pot:", self.pot) #self.show_active_player_stats() self.do_betting_round(False) p = self.calculate_win() if p: self.log("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== FLOP ======") self.deal_flop() self.do_betting_round() print("====== END FLOP ======") p = self.calculate_win() if p: self.log("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== TURN ======") self.deal_turn() self.do_betting_round() print("====== END TURN ======") p = self.calculate_win() if p: print("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== RIVER ======") self.deal_river() self.do_betting_round() print("====== END RIVER ======") p = self.calculate_win(True) if p: print("Winner(s) with hand ranking:", p[1]) for winner in p[0]: winner.print_info(self.shared_cards) continue # Serve a fresh deck print("\n\n\n\n=========== THE POKER GAME IS FINISHED ===============") self.show_all_player_stats()
def start_game(self): self.deck = cards.card_deck() # Main game loop/structure. Based on Texas Hold 'Em rules for i in range(self.n_rounds): # Reset info self.deck.reset() self.state = 1 # 1 = Pre-flop self.round = i print("\n") print( "================================== Round #", self.round, "State: ", self.state, " ========================================", ) # Shuffle for big blind/small blind if i != 0: self.players.append(self.players.pop(0)) # Reset info. self.pot = 0 self.flop = [] self.turn = [] self.river = [] self.shared_cards = [] self.active_players = self.players[:] self.total_raises = 0 # Deal hole cards j = 0 for p in self.active_players: if p == None: continue small_blind_player = j == len(self.players) - 2 big_blind_player = j == len(self.players) - 1 self.pot += p.new_round(small_blind_player, big_blind_player) p.set_cards(self.deck.deal_n_cards(2)) j += 1 self.log("Pot:", self.pot) # self.show_active_player_stats() self.do_betting_round(False) p = self.calculate_win() if p: self.log("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== FLOP ======") self.deal_flop() self.do_betting_round() print("====== END FLOP ======") p = self.calculate_win() if p: self.log("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== TURN ======") self.deal_turn() self.do_betting_round() print("====== END TURN ======") p = self.calculate_win() if p: print("Winner:") p[0][0].print_info(self.shared_cards) continue print("====== RIVER ======") self.deal_river() self.do_betting_round() print("====== END RIVER ======") p = self.calculate_win(True) if p: print("Winner(s) with hand ranking:", p[1]) for winner in p[0]: winner.print_info(self.shared_cards) continue # Serve a fresh deck print("\n\n\n\n=========== THE POKER GAME IS FINISHED ===============") self.show_all_player_stats()