Skip to main content

No project description provided

Project description

This README is still not finished, if yo wish to use this class, good luck

BlackJackTable


Overview

This library provides basic support to simulate a blackjack table, it also adds a default computer bot(basic strategy) and 2 human bots: with card count help and without.


Instalation

Either

  • Download source code from Library dir and use freely Or
  • Install BlackJackTable with: pip install BlackJackTable

Usage

  • Using default bots:
from BlackJackTable import HumanBot

startingFunds = 500
name = "Human player"
player = HumanBot(startingFunds, name)
  • Using BlackJack table:
from BlackJackTable import BlackJackGame as BJ
from BlackJackTable import HumanBot, PlayerBot

# vars
deck_count = 6
startingFunds = 500
# if logging is True it will print out some game desitions like player loosing all funds, if it is false that information can still be acceced with return codes
logging = True
# shuffle_procent decides how much procent of the deck should be used untill a reshuffle happens
shuffle_procent = 60
# initiating the player class
Player = HumanBot(startingFunds, "Player")
# initiating the standart bot that computer will play
Bot = PlayerBot(500, "BOT")
# adding our bots to a list
list_of_players = [Player, Bot, Bot]
# initiating the BJ class
BJ(list_of_players, deck_count, logging, shuffle_procent)
  • Simplified:
from BlackJackTable import BlackJackGame as BJ
from BlackJackTable import HumanBot, PlayerBot

table = BJ([], 6, False, 60)
table.add_player(HumanBot(500, "Human"))
table.add_player(PlayerBot(500, "BOT"))
table.add_player(PlayerBot(500, "BOT")) 
  • CodeError function returns the error that an error code corresponds to. An error code is returned from something failing in the BlackJackGame itterate function:
from BlackJackGame import CodeError

code = 2
print(CodeError(code)) # prints out "Can't split non-pair"
  • Example of a working playable game:
from BlackJackTable import BlackJackGame, CodeError
from BlackJackTable import HumanBot, PlayerBot
import time

table = BlackJackGame([
    HumanBot(500, "me"), 
    PlayerBot(500, "bot"), 
    PlayerBot(500, "bot"), 
    PlayerBot(500, "bot")], 
    1, True, 70)

while True:
    info = table.itterate()
    if isinstance(info, int):
        print(f"Game over, info: {CodeError(info)}")
        if CodeError(info) != "Deck has been reshuffled" or CodeError(info) != "Dealer has blackjack, new game":
            break
    else:
        print(info)
        time.sleep(2)
  • Understanding BlackJackGame class
    • It derives from parent class SGame:
class SGame(ABC):
    @abstractmethod
    def itterate(self) -> str:
        pass
    def get_game_number(self) -> int:
        pass
    def add_player(self, player) -> None:
        pass
    def normal_info(self) -> str:
        pass
    def __init__(self, players = [], deck_count=1, log=False, cut_procent = 60) -> None:
        pass
  • It has 4 usable methods:
    • normal_info returns information about that table formated as:
      f"
      Game number:  {gamenumber}
      Player count: {playercount}
      Deck count:   {deckcount}
      Alive Players:{aliveplayers's names}
      Players funds:{funds of alive players}
      Dead players: {deal players's names}
      Decks used:   {times shuffled}
      "
      
    • get_game_number returns number of game played.
    • add_player adds a new player into the game.
    • itterate compleates 1 full game cycle by getting players bets, dealing the game, asking players desitions and giving out/taking money from bot class funds variable (Note: get_bet method in bot class MUST negte the chosen bet from its own funds).

Code in a nutshell

Writing your own bots
  • There are 3 default bots in the library:
    • HumanBot <- a bot for a human to controll, no card counting help, possible to train card counting
    • HumanBotWithCount <- a bot with card counting help, imposible to train card counting
    • PlayerBot <- default self playing bot, follows the default strategy
  • All bots must derive from a parent class Sbot:
class SBot(ABC):
    @abstractmethod
    def __init__(self, funds, name):
        self.name = name
        self.funds = funds
    @abstractmethod
    def play(self, info) -> str:
        pass
    @abstractmethod
    def get_bet(self, info) -> int:
        # get_bet function MUST negate the bet from own funds
        bet = 0
        self.funds -= bet
        return bet
        pass
    @abstractmethod
    def kick(self, info) -> None:
        pass
    @abstractmethod
    def check_insurence(self, info) -> bool:
        pass
  • All methods take in info variable which is a dictionary formated as:
{
    "cards": self.__game_deck.get_used_cards(),        # Cards that at some point were on the table before resuffuling
    "p_cards": self.__player_hands[index].get_cards(), # The hand of the player formated as for example: B21, P8, H20, H10, P18, S18, S17, etc...
    "d_cards": self.__dealer_hand.get_cards(),         # Dealers hand formated in the same way
    "p_count": self.__player_count,                    # How many players playing
    "deck_game": self.__game_deck._deck_count,         # How many decks in the game
    "pos": index+1,                                    # Which position the player is sitting
    "num": self.__game_number,                         # Which game it is played
    "table_cards": self.table_cards                    # The cards that are currently on the table dealt
}
  • The class can process the data howewer they want and must return:
    • play returns a play desition: H(hit), S(stand), D(double down), Y(split)
    • get_bet returns the bet amount
    • kick informs the class that it was kicked from the table
    • check_insurence returns either True to take insurence or False not to
  • Writing your own bot is as simple as processing the info data. Example HumanBot:
from BlackJackTable import SBot

class HumanBot(SBot):
    def __init__(self, funds, name):
        self.name = name
        self.funds = funds
        
    def play(self, info):
        command = 'cls' if os.name == 'nt' else 'clear'
        os.system(command)
        print(f"Your hand: {info['p_cards']}")
        print(f"Dealer's hand: {info['d_cards']}")
        print(f"Table cards: {info['table_cards']}")
        print(f"Funds: {self.funds}")
        action = input("Enter action (H(hit), S(stand), D(double), Y(split)): ")
        return action

    def get_bet(self, info):
        command = 'cls' if os.name == 'nt' else 'clear'
        os.system(command)
        print(f"Funds: {self.funds}")
        bet = int(input("Enter bet: "))
        self.funds -= bet
        return bet

    def kick(self, info):
        command = 'cls' if os.name == 'nt' else 'clear'
        os.system(command)
        print(f"Game over, round: {info}, funds: {self.funds}")
        
    def check_insurence(self, info):
        command = 'cls' if os.name == 'nt' else 'clear'
        os.system(command)
        print(f"Dealer's hand: {info['d_cards']}")
        print(f"Table cards: {info['table_cards']}")
        print(f"Funds: {self.funds}")
        action = input("Do you want to insure? (Y/N): ")
        return True if action == "Y" else False
  • This class takes in input() as the choices that it makes

ToDo
  • Publish v1.0
  • Set up a python lybrary
  • Set up docker

The end

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BlackJackTable-0.2.6.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

BlackJackTable-0.2.6-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file BlackJackTable-0.2.6.tar.gz.

File metadata

  • Download URL: BlackJackTable-0.2.6.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for BlackJackTable-0.2.6.tar.gz
Algorithm Hash digest
SHA256 3fe707e317f919dc899096401a98eb6b06b239bd6acd9ff591c8d17fd3ab6bdd
MD5 cd671b898b0c98697518d31784dac58a
BLAKE2b-256 5f51949c7c0c9ceabac58936cdb6196c20be717b90afb4d7bdfba8e68f5c9b20

See more details on using hashes here.

File details

Details for the file BlackJackTable-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: BlackJackTable-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for BlackJackTable-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 72b5391461ba6aaee379d7c8f39d0bbad2b98fd65d4d5ed540913e04a844a553
MD5 3989ea641ecb8fe0ce10f65e2fbc57a9
BLAKE2b-256 464a3d8f4cf23ca258c0b094b7285102769147d7f63e4137ef5de4e0a382c5d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page