Course: Princípios de Programação
Project: 3
This project implements a Blackjack game in Haskell, allowing a user to play rounds of Blackjack against the house. The program interacts via command-line input, supporting custom deck files and randomized deck generation.
The goal of this project is to consolidate knowledge in Haskell by building a command-line Blackjack game. The project includes:
- Modularized game logic
- Command-line and file interactions
- Automated property-based testing with QuickCheck
Note: This game is designed for educational purposes and does not support gambling.
- Haskell Stack: Required to build and run the Haskell project.
- QuickCheck: For running automated tests (included in Stack).
- Clone this repository to your local machine:
git clone https://github.com/Fkatar/BlackjackGame.git cd BlackjackGame - Build the project with Stack:
stack build
To start the game, compile and run the Main.hs file:
-
Run the game with a default deck:
stack ghc Main.hs ./Main default.bar
This will load the default deck from
data/default.bar. -
Run the game with a custom deck:
./Main path/to/deck.bar
-
Run the game with a randomized deck:
./Main -n X
Replace
Xwith the number of shuffled decks. -
Run tests:
./Main -t
- Game Rounds: Play multiple rounds until the deck is exhausted or credits are depleted.
- Randomized Decks: Create a randomized deck with
-n X. - Custom Decks: Use
.baror.txtfiles to load different decks. - QuickCheck Tests: Includes automated tests to verify game properties.
This project uses QuickCheck to test game logic. Tests are located in src/Testes.hs and are run with the -t flag:
./Main -tThe tests check:
- Initial hand values are <= 21.
- Credit values after each round match expectations.
- The house hand reaches at least 17 points.
BlackjackGame/
│
├── src/ # Haskell source files
│ ├── Main.hs # Main file for running the game
│ ├── BlackJack.hs # Game logic
│ └── Testes.hs # QuickCheck tests
│
├── data/ # Data files for custom decks
│ ├── default.bar # Default deck
│ ├── 01_baralho.bar # Additional deck files
│ ├── 01_input.txt # Input sequence files for testing
│ └── 01_check.txt # Expected output files for validation
│
├── bin/ # Compiled binaries (local use only)
│
└── README.md # Project documentation
This project was completed by Francisco Catarino, Universidade de Lisboa, 2022/2023.