wk5.0 (almost half-way!)
Stuff that's due this week
1. Your project proposal
- Approach your project from a technical perspective; what part of the stack do you want to know more about?
- Focus on one basic thing that you want to go really deep into.
- For everything else, it's okay to use libraries.
2. Your individual assignment: Blackjack!
Blackjack is a comparing card game between a player and dealer, meaning players compete against the dealer but not against other players. It is played with one or more decks of 52 cards. The object of the game is to beat the dealer in one of the following ways:
- Get 21 points on the player's first two cards (called a blackjack), without a dealer blackjack;
- Reach a final score higher than the dealer without exceeding 21; or
- Let the dealer draw additional cards until his or her hand exceeds 21.
The player or players are dealt a two-card hand and add together the value of their cards. Face cards (kings, queens, and jacks) are counted as ten points. A player and the dealer can count an ace as 1 point or 11 points. All other cards are counted as the numeric value shown on the card. After receiving their first two cards, players have the option of getting a "hit", or taking an additional card. In a given round, the player or the dealer wins by having a score of 21 or by having the higher score that is less than 21. Scoring higher than 21 (called "busting" or "going bust") results in a loss. A player may win by having any final score equal to or less than 21 if the dealer busts. If a player holds an ace valued as 11, the hand is called "soft", meaning that the player cannot go bust by taking an additional card; 11 plus the value of any other card will always be less than or equal to 21. Otherwise, the hand is "hard".
Requirements
Create a repo called Blackjack on your github account that contains a python implementation of blackjack.
OOP
- Implement blackjack using classes. Your code should at least implement a deck object that contains the following methods (non-exhaustive):
- constructor: Creates a new deck of 52 cards in a standard order.
- shuffle: Randomizes the order of the cards.
- draw_card: Returns a single card from the top of the deck and removes the card from the deck.
- cards_left: Returns the number of cards remaining in the deck.
- sort: Sorts the cards back into standard order. Should be $O(nlog(n))$ (I suggest implementing merge sort).
Clean design
- Focus on clean, modular design.
- Separate classes and methods into different .py files and directories and import for reusability.
- Follow PEP8 (your life will be greatly simplified if you a) use an IDE, or b) create class and function templates).
- Check out
Test Driven Development
- Outline your classes, methods and functions by defining them and creating docstrings (don't implement the logic yet!).
- After each new class/method/function, make an associated class/method/function test in a top-level tests directory with the convention file_name_tests.py (ex. name your deck.py test file deck_tests.py in the test directory). Check that your tests fail (important!), then write logic that causes the tests to pass.
- Make sure you comprehensively test each of your methods!
- Here are some helpful links:
Wonderful documentation
- In addition to implementing clear headers, docstrings, and comments, add a README.md (the .md is for markdown) that explains how to use your library to play blackjack. Your readme should (at least) have:
- name of the project and author
- high level description of the project
- short (5-line) code snippet on how it's used.
- Here are some other helpful links on writing a readme:
Suggested approach
- Create a Card class, which has a value (1, 2 ... 10) and a name (2, ... K, A)
- Note: In blackjack, aces can be either one or eleven.
- Create a Deck class, which is a list/tuple or other collection of Card with a shuffle function and a draw_card function.
- Create a Hand class, which is also similar to the Deck class
- Create a Player class, which basically has a Hand class object associated with it.
- Create a Blackjack class which has the main game logic.
When are we going to work on our individual assignments!?
- This week will be less lecture based to allow for individual project and capstone proposal time.
- One of the goals of this week will be managing three projects at once (javascript, blackjack, and capstone proposal). Where you decide to spend your time is up to you (although I would suggest getting the easy stuff out of the way first).