Project Overview
This project delivers a command-line Baccarat card game written in modern C++. It simulates standard Baccarat rules, enables interactive betting, and tracks game outcomes across multiple rounds. Developers and players can extend, customize, or integrate the core engine into larger gaming frameworks.
Purpose
Provide a lightweight, extensible Baccarat engine to:
- Demonstrate idiomatic C++ design (classes, RAII, STL).
- Offer a fun CLI game for end users.
- Serve as a foundation for AI-driven betting strategies or GUI wrappers.
Why It Exists
- Exercise hands-on C++ development with real-world game rules.
- Supply an open-source baseline for wagering system prototypes.
- Foster community contributions around card-game implementations.
Key Features
- Full adherence to Baccarat dealing and scoring rules.
- Interactive CLI: place bets on Player, Banker, or Tie.
- Configurable deck count and shuffle threshold.
- Round history logging with win/loss statistics.
- Clear separation of engine, I/O, and game-state modules for easy extension.
- Cross-platform: builds on Linux, macOS, and Windows.
Basic Usage
Compile and run the game:
# Clone repository
git clone https://github.com/novafs/baccarat-game.git
cd baccarat-game
# Build with C++17
g++ -std=c++17 src/*.cpp -o baccarat
# Start the game
./baccarat
Sample Gameplay Flow
Welcome to Baccarat C++!
Enter starting balance: 1000
Round 1: Bet on (P)layer, (B)anker, or (T)ie? P
Dealing cards...
Player: 8, 4 (Total 2) Banker: 7, 5 (Total 2)
Third card rules apply...
Result: Player wins! You gain 100.
Balance: 1100
Continue? (Y/N)
License
This project is licensed under GNU General Public License v3.0. You may use, modify, and distribute the software provided you include the full license text and preserve all copyright notices.
See LICENSE for full terms.
Quick Start & Compilation
Get the Baccarat game up and running in minutes on any fresh system.
Prerequisites
- Git
- C++ compiler (GCC/Clang supporting C++11 or later, or MSVC)
- (Optional) Make for automated builds
Clone the Repository
Navigate to your workspace and clone:
git clone https://github.com/novafs/baccarat-game.git
cd baccarat-game
Compile
Linux / macOS
g++ -std=c++11 baccarat.cpp -O2 -o baccarat
Windows (MinGW)
g++ -std=c++11 baccarat.cpp -O2 -o baccarat.exe
Windows (Visual Studio Developer Command Prompt)
cl /EHsc /O2 baccarat.cpp /Fe:baccarat.exe
Run the Game
After a successful build, launch the executable:
# Linux / macOS
./baccarat
# Windows
baccarat.exe
On first run, the game auto-creates accounts.txt
to store user data.
Custom Build Flags
Append flags to suit your workflow:
# Enable debug symbols
g++ -std=c++11 -g baccarat.cpp -o baccarat-debug
# Target C++17
g++ -std=c++17 baccarat.cpp -O2 -o baccarat_cpp17
File Storage & Permissions
The game reads and writes accounts.txt
in the working directory. Ensure:
- Write permissions on launch folder
- Back up
accounts.txt
before bulk edits or resets
You’re now ready to play or extend the Baccarat game code. Enjoy!
Gameplay Guide
This guide explains how to start the Baccarat program, manage your account, and play a round of Baccarat with the built-in rules and payouts.
Starting the Application
• Compile and run the binary:
g++ baccarat.cpp -o baccarat
./baccarat
• You’ll see a main menu prompting for account actions or gameplay.
Account System
1. Create Account
- Select 1. Buat Akun
- Enter username, phone number, email
- The program assigns a random numeric ID and an initial balance of 10 000
- Your new record appends to
data.txt
Console example:
Masukkan username :: alice
Masukkan nomor Handphone :: 08123456789
Masukkan alamat email :: alice@example.com
Saldo awal : 10000
ID Akun kamu :: 4823958023
2. Login
- Select 2. Login
- Enter your Account ID
- On success, the system sets the global
search
variable to your ID
3. Deposit Funds
- Select 3. Deposit Saldo
- Enter the amount to add
- The program reads all records from
data.txt
, updates your balance, and rewrites the file
Console example:
Masukkan jumlah deposit anda :: 5000
Saldo sebelumnya :: 10000
Saldo sekarang :: 15000
4. View Account Info
- Select 4. Info Akun
- The program scans
data.txt
for your ID and displays:- ID Akun
- User Name
- Nomor HP
- Saldo Tersisa
Playing Baccarat
1. Start a Round
After logging in, select 5. Main Game to begin.
2. Place Your Bet
• Choose one of:
- Player (payout 1:1)
- Banker (payout 0.95:1)
- Tie (payout 8:1)
• Enter your bet amount (must not exceed your current balance).
3. Dealing Cards
• The program shuffles a virtual 6-deck shoe.
• Deals two cards each to Player and Banker.
4. Third‐Card Rules
• If either hand totals 8 or 9 (natural), no more cards draw.
• If Player total ≤ 5, Player draws a third card.
• Banker draws based on its total and Player’s third card value per standard Baccarat tables.
5. Determining the Winner
• Scores compute as (sum of card values) % 10.
• Higher score wins; equal scores result in a tie.
6. Payout and Balance Update
• On win, the program calculates winnings and calls depoSaldo()
internally to credit your account.
• On loss, it deducts your bet from your balance.
Example Gameplay Session
=== BACCARAT 6-DECK CONSOLE GAME ===
1. Buat Akun
2. Login
3. Deposit Saldo
4. Info Akun
5. Main Game
6. Exit
Pilih menu :: 2
Masukkan ID Akun :: 4823958023
Login berhasil!
Saldo Anda: 15000
-- Main Game --
Pilih taruhan:
1. Player
2. Banker
3. Tie
Pilihan :: 1
Masukkan jumlah bet :: 5000
Dealing cards...
Player: [7♠, 3♥] Total = 0
Banker: [5♦, 2♣] Total = 7
Player draws a third card: 4♣
Player final total = 4
Banker draws third? No
Result: Banker wins
Anda kalah 5000
Saldo sekarang: 10000
Extending or Debugging
– All account operations use simple tab-separated flat-file I/O on data.txt
.
– Game logic resides in functions like dealCards()
, calculateScore()
, and resolveBet()
.
– To adjust payout rates or shoe size, locate constants at the top of baccarat.cpp
.
– For production, consider replacing file I/O with a lightweight database and adding input validation.
Code Structure & Contribution
This section outlines the single-source layout of baccarat.cpp
and guides contributions. Refer to function landmarks for quick navigation and use the “Adding New Features” example when proposing improvements.
File Layout
- baccarat.cpp
Implements:- Account management (create, load, save, deposit)
- Console menu and input handling
- Baccarat gameplay (betting, dealing, scoring, winner determination)
- Text-file persistence (
accounts.txt
)
Key Functions Overview
struct Account
- Holds
username
andbalance
- Holds
Account I/O
bool loadAccount(const string& user, Account &acc)
void saveAccount(const Account &acc)
bool createAccount(const string& user)
Account Operations
void depositFunds(Account &acc)
Gameplay Helpers
int dealCard()
int calculateScore(const vector<int>& hand)
string determineWinner(int playerScore, int bankerScore)
Betting & Round Flow
double placeBet(const Account &acc)
void playRound(Account &acc)
Entry Point
int main()
- Shows menu loop: Create/Load account, Deposit, Play, Exit
Navigating the Code
Locate these sections by searching for their names in baccarat.cpp
:
Account Persistence
bool loadAccount(const string& user, Account &acc);
void saveAccount(const Account &acc);
bool createAccount(const string& user);
Gameplay Logic
int dealCard(); // Returns 1–13
int calculateScore(const vector<int>&); // Baccarat rules
string determineWinner(int, int);
User Interaction & Menu
double placeBet(const Account &acc);
void depositFunds(Account &acc);
void playRound(Account &acc);
int main();
Adding New Features
Example: implement a “Withdraw Funds” feature.
Define
withdrawFunds
belowdepositFunds
:void withdrawFunds(Account &acc) { double amount; cout << "Enter amount to withdraw: "; cin >> amount; if (amount <= 0) { cout << "Invalid amount.\n"; } else if (amount <= acc.balance) { acc.balance -= amount; cout << "Withdrawal successful. New balance: $" << acc.balance << "\n"; saveAccount(acc); } else { cout << "Insufficient funds.\n"; } }
Update the main menu in
main()
:// After the Deposit option cout << "4. Withdraw Funds\n"; // Handle user choice: case 4: withdrawFunds(acc); break; // Shift existing cases accordingly
Run and verify persistence in
accounts.txt
.
Contribution Guidelines
- Fork the repository, create a feature branch (e.g.
feature/withdrawal
). - Follow existing code style: single-file layout,
std::
prefixes, simple I/O. - Add comments for new logic and update menu prompts.
- Test CLI flows manually to ensure file I/O integrity.
- Submit a pull request referencing this feature and any related issue.
By following these landmarks and the example, you can navigate baccarat.cpp
quickly and propose targeted improvements.