Skip to content

CGFixIT/Blackjack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Casino Blackjack aka Twenty-one (Written in C++; I used Visual Studio but many compilers are supported



Fun old-school CMD console Blackjack game written in C++ as a school projects from many moons ago..

This is a legacy / educational project – not production-grade casino software. It’s here as a snapshot of where my C++ journey started.


#This is Blackjack, written in C++. Includes:
-User accounts (Includes tally of winnings and player rankings)
-Leaderboard
-Basic dealer AI (very basic lol but met criteria for project) / Level of difficulty
-Lots of other stuff that I will add

Main Code:


Youtube Demo of Game


What You Get

  • Blackjack game loop
    • Hit / Stand
    • Double Down (when initial total is 9, 10, or 11)
    • Insurance side bets when dealer shows an Ace
  • 1–7 players (local hotseat)
    • Solo: you vs dealer
    • Multi: multiple human players taking turns at the same console
  • Persistent user accounts
    • Simple User class: name, email, username, pw, earnings, rank
    • Accounts stored in userDB.txt between runs
  • Dealer difficulty levels
    • Beginner – dealer stands on soft 17
    • Expert – dealer hits on soft 17 (When the dealer hits on soft 17, it gives them a chance to improve their hand but it also adds risk of busting; aka Expert can improve on soft 17; Beginner plays it safe)
  • Leaderboard
    • Players ranked by total lifetime earnings
    • Custom selection sort over the User array

Game Rules & Payouts

The project follows standard, simplified Blackjack rules:

  • Card values
    • Number cards: face value
    • J, Q, K: 10 points
    • A: 1 or 11 points (player chooses; dealer logic adjusts)
  • Blackjack
    • Natural blackjack pays 3:2 (150% of your bet in profit)
  • Standard outcomes
    • Win: you beat dealer without busting ⇒ you win an amount equal to your bet
    • Push: same total as dealer ⇒ your bet is returned
    • Loss: you bust or dealer is closer to 21 ⇒ you lose your bet
  • Insurance
    • Offered if dealer’s face-up card is an Ace
    • You can bet up to half your original bet that the dealer has blackjack
    • Insurance pays 2:1 if the dealer does have blackjack

All players start each session with an initial bankroll of $50, and that bankroll is tracked per account across runs.


Project Layout

The repo is intentionally small:

  • Blackjack/Blackjack/main.cpp
    Core of the program:

    • User auth / signup (userSignIn)
    • Game loop (playFirstHand)
    • Betting, insurance, and double-down logic
    • Dealer AI (hitUntilStandAI, checkSoftOrHardAI)
    • Hand evaluation (CardValue, getHandValue)
    • Leaderboard and ranking (determineRank, selectionSort, displayResults)
    • File I/O for user accounts (loadAccounts, updateDB, updateEarnings)
  • Blackjack/Blackjack/User.h
    Simple User class with public fields:

    • string name
    • string email
    • string username
    • string pw
    • double earnings
    • int rank
  • userDB.txt (created/updated at runtime)

    • Flat-file “database” containing:
      • Number of users
      • One block per user: name, email, username, password, earnings, rank

Tech Stack & Constraints

  • Language: C++ (written against a 2016-era toolchain)
  • Standard library:
    • <iostream>, <iomanip>, <string>, <fstream>
    • <algorithm> (uses random_shuffle in this repo version)
    • <cstdlib>, <ctime>, <limits>
  • OS assumptions: Windows
    • Uses system("cls") to clear the console
    • Uses system("pause") for “press any key to continue”
    • On Linux/macOS you’ll either need to stub these out or replace them

V2 Updates / Shuffling

The latest version in this repo uses Mersenne Twister 19937 generator (mt19937 algo)
Previously I used the system time thinking that was random... which it is if you wait hours in between each round lolz. The demo video I made years ago where somehow me and the dealer got face cards twice in a row (and the odds of that happening) bothered me even though the teacher gave me an A since he prob didn't read the code just saw it worked - Anywho; not that it matters now unless I wanna start writing massive apps that need C++ but I felt like I should archive this if I didn't at least fix that part. That's my story ;) - Anyways enjoy :

void shuffleDeck(int deck[], int size)
{
    random_device rd;
    mt19937 g(rd());
    std::shuffle(deck, deck + size, g);  // Explicit std:: for clarity
}
/>

About

Casino Blackjack w/ User Accounts

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages