A fully-featured, text-based Blackjack CLI game written in Python, designed to be beautiful, functional, and clean. The game is extremely well-documented and commented, making it an excellent resource for anyone learning Python or exploring CLI game development.
It features a complete Blackjack system including betting, splitting, doubling down, surrendering, and fully customizable settings, all presented with polished ASCII card graphics.
- Player and dealer turns, betting system, doubling down, splitting, and surrendering.
- Automatic handling of Ace values for optimal scoring:
def hand_value(cards: list[str]) -> int:
value = 0
aces = 0
for card in cards:
rank = card[:-1]
if rank in "JQK": value += 10
elif rank == "A": aces += 1; value += 11
else: value += int(rank)
while value > 21 and aces:
value -= 10
aces -= 1
return value- Supports multiple hands for splits and dynamic gameplay.
def split_hand(hand: dict, hands: list[dict]):
if len(hand["cards"]) == 2 and hand["cards"][0][:-1] == hand["cards"][1][:-1]:
new_hand = {"cards": [hand["cards"].pop()], "bet": hand["bet"], "active": True}
hands.append(new_hand)- Clean, visually appealing ASCII art for each card:
def render_card(card: str, hidden: bool=False) -> str:
if hidden:
return "┌─────┐\n│░░░░░│\n│░░░░░│\n└─────┘"
rank, suit = card[:-1], card[-1]
return f"┌─────┐\n│{rank:<2} │\n│ {suit} │\n│ {rank:>2}│\n└─────┘"- Displays multiple player hands and dealer hand neatly:
def print_hands(player_hands: list[dict], dealer_hand: dict, hide_dealer=True):
for hand in player_hands:
print("Your Hand:")
for card in hand["cards"]:
print(render_card(card))
print(f"Value: {hand_value(hand['cards'])}\n")
print("Dealer Hand:")
for i, card in enumerate(dealer_hand["cards"]):
print(render_card(card, hidden=(i == 0 and hide_dealer)))- Adjust deck count, enable/disable doubling, splitting, surrendering, and soft-17 rules.
- Changes are applied in real time, including shuffling:
def generate_deck(num_decks=1) -> list[str]:
deck = [f"{rank}{suit}" for rank in ranks for suit in SUITS] * num_decks
random.shuffle(deck)
return deck- Well-documented functions and classes for easy learning.
- Perfect for beginners learning Python, CLI game logic, or card game development.
- Demonstrates that terminal-based games can be polished, functional, and visually engaging.
Welcome Screen and Main Menu
Tutorial Preview
Sample Game Preview
Settings Menu
- Python
- CLI
- ASCII Art
- Python
- CLI Game
- Open Source
- Game Development
- ASCII Art
- Clone the repository:
git clone https://github.com/your-username/blackjack-cli.git
cd blackjack-cli- Run the game:
python3 main.py- Follow the on-screen prompts to play.
Feel free to fork, submit issues, or make pull requests. Contributions are welcome!
This project is open source and available under the MIT License.



