Skip to content

Instantly share code, notes, and snippets.

@samsonq
Last active June 28, 2022 22:01
Show Gist options
  • Save samsonq/a1232925e16922a7cb552fe7842d91d3 to your computer and use it in GitHub Desktop.
Save samsonq/a1232925e16922a7cb552fe7842d91d3 to your computer and use it in GitHub Desktop.
Monte Carlo Simulation to Play Card Games (Poker, Blackjack, etc.)
import numpy as np
import random
import numpy as np
import random
class Deck:
def __init__(self):
cards = [i for i in range(1, 14)]
self.deck = {"Spades": cards, "Hearts" : cards, "Diamonds": cards, "Clubs": cards}
class Poker(Deck):
def __init__(self, num_players, starting_chips=1000000):
super().__init__()
self.players = []
self.num_players = num_players
for _ in range(num_players):
self.players.append(PokerPlayer(starting_chips))
self.board = []
def __str__(self):
return "Board: {}".format(self.board)
class PokerPlayer():
def __init__(self, chips):
self.hand = []
self.bet = 0
self.status = "" # Bet or Fold
self.chips = chips
def deal_cards(self, cards):
for card in cards:
self.hand.append(card)
def __str__(self):
return "Chips: {}".format(self.chips)
def get_hand(self):
return self.hand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment