Last active
June 28, 2022 22:01
-
-
Save samsonq/a1232925e16922a7cb552fe7842d91d3 to your computer and use it in GitHub Desktop.
Monte Carlo Simulation to Play Card Games (Poker, Blackjack, etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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