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 Still not a public library

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.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-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: BlackJackTable-0.2.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.tar.gz
Algorithm Hash digest
SHA256 1f509f13ba99c552653c75df0fbe7aa6c5c06f7f492a765553a27b80c834e605
MD5 90f6a2fdd0c2cec05e6a846cc792aaf5
BLAKE2b-256 0ad183868780fb9df1a98291e6076bda3acfcb8eacbbea2270b91abfa388ec24

See more details on using hashes here.

File details

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

File metadata

  • Download URL: BlackJackTable-0.2-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-py3-none-any.whl
Algorithm Hash digest
SHA256 52b64c346776b6a139b26ce2cd6c31017e7cade195f0edc15dd58a0f5e5d3448
MD5 978ce5e0b5d8c5d2a66ccef3c9d75be5
BLAKE2b-256 53d7b75153d2ea5554bb9007c898ed93721b1645ab08714246e74ce796186af3

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