Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks,macos

### JupyterNotebooks ###
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/

.ipynb_checkpoints
*/.ipynb_checkpoints/*

# IPython
profile_default/
ipython_config.py

# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks,macos
186 changes: 186 additions & 0 deletions your-project/Faisals_Blackjack.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def deal(cards):\n",
" \n",
" random.shuffle(cards)\n",
" player_cards.append(cards[0])\n",
" player_cards.append(cards[2])\n",
" dealer_cards.append(cards[1])\n",
" dealer_cards.append(cards[3])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def calculate_scores(p_cards, d_cards, c_dict):\n",
" player = []\n",
" dealer = []\n",
" player.append(c_dict[p_cards[0]])\n",
" player.append(c_dict[p_cards[1]])\n",
" dealer.append(c_dict[d_cards[0]])\n",
" dealer.append(c_dict[d_cards[1]])\n",
" \n",
" return player, dealer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def hitter(dealing_deck, p_dealt_cards, d_dealt_cards):\n",
" p_dealt_cards.append(dealing_deck[hit_index])\n",
" d_dealt_cards.append(dealing_deck[hit_index])\n",
" return dealing_deck[hit_index]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def ace_counter(cards):\n",
" ace_counter = 0\n",
" for card in cards:\n",
" if (\"ace\" in card):\n",
" ace_counter += 1\n",
" return ace_counter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"deck_dict = {\"ace_spades\": 11, \"2_spades\": 2, \"3_spades\": 3, \"4_spades\": 4, \"5_spades\": 5, \"6_spades\": 6, \"7_spades\": 7,\"8_spades\": 8, \"9_spades\": 9, \"10_spades\": 10, \"j_spades\": 10, \"q_spades\": 10, \"k_spades\": 10, \"ace_hearts\": 11, \"2_hearts\": 2, \"3_hearts\": 3, \"4_hearts\": 4, \"5_hearts\": 5, \"6_hearts\": 6, \"7_hearts\": 7,\"8_hearts\": 8, \"9_hearts\": 9, \"10_hearts\": 10, \"j_hearts\": 10, \"q_hearts\": 10, \"k_hearts\": 10,\"ace_diamonds\": 11, \"2_diamonds\": 2, \"3_diamonds\": 3, \"4_diamonds\": 4, \"5_diamonds\": 5, \"6_diamonds\": 6, \"7_diamonds\": 7,\"8_diamonds\": 8, \"9_diamonds\": 9, \"10_diamonds\": 10, \"j_diamonds\": 10, \"q_diamonds\": 10, \"k_diamonds\": 10,\"ace_clubs\": 11, \"2_clubs\": 2, \"3_clubs\": 3, \"4_clubs\": 4, \"5_clubs\": 5, \"6_clubs\": 6, \"7_clubs\": 7,\"8_clubs\": 8, \"9_clubs\": 9, \"10_clubs\": 10, \"j_clubs\": 10, \"q_clubs\": 10, \"k_clubs\": 10}\n",
"deck = list(deck_dict.keys())\n",
"player_scores = []\n",
"dealer_scores = []\n",
"player_cards = []\n",
"dealer_cards = []\n",
"hit_index = 4\n",
"player_ace = 0\n",
"dealer_ace = 0\n",
"command = \"\"\n",
"command_options = [\"hit\", \"stand\"]\n",
"print(\"Welcome to Faisal's Blackjack, where the house always wins!\")\n",
"time.sleep(2)\n",
"deal(deck)\n",
"player_scores, dealer_scores = calculate_scores(player_cards, dealer_cards, deck_dict)\n",
"player_total_score = sum(player_scores)\n",
"dealer_total_score = sum(dealer_scores)\n",
"# flip prints and edit text\n",
"print(\"Dealing cards...\")\n",
"time.sleep(1.2)\n",
"print(\"The second card of the dealer is: \", dealer_cards[1])\n",
"time.sleep(3)\n",
"print(\"Your cards are: \", player_cards, \"your total score is :\", player_total_score)\n",
"while (True):\n",
" while ( command not in command_options):\n",
" command = input(\"Would you like to hit hit or stand? \")\n",
" if command.lower() == \"hit\" and player_total_score <= 21:\n",
" new_card = hitter(deck, player_cards, dealer_cards)\n",
" player_total_score += deck_dict[new_card]\n",
" hit_index += 1\n",
" command = \"\"\n",
" if player_total_score == 21:\n",
" print(\"BLACKJACK!\")\n",
" elif player_total_score > 21:\n",
" player_ace = ace_counter(player_cards)\n",
" if player_ace > 0:\n",
" player_total_score -= 10\n",
" player_ace -= 1\n",
" else:\n",
" print(\"Your cards are: \", player_cards, \"your total score is :\", player_total_score)\n",
" time.sleep(1.2)\n",
" print(\"BUSTTT! You lose!\")\n",
" break\n",
" print(\"Your cards are: \", player_cards)\n",
" time.sleep(0.8)\n",
" print(\"Your total score is :\", player_total_score)\n",
" while ( command not in command_options):\n",
" command = input(\"Type hit or stand? \")\n",
" else:\n",
" print(\"Your cards are: \", player_cards)\n",
" time.sleep(0.8)\n",
" print(\"Your total score is :\", player_total_score)\n",
" while dealer_total_score < 17:\n",
" new_card = hitter(deck, player_cards, dealer_cards)\n",
" dealer_total_score += deck_dict[new_card]\n",
" hit_index += 1\n",
"\n",
" if dealer_total_score > 21:\n",
" dealer_ace = ace_counter(dealer_cards)\n",
" if dealer_ace > 0:\n",
" dealer_total_score -= 10\n",
" dealer_ace -= 1\n",
" else:\n",
" print(\"Dealer cards are: \", dealer_cards, \"Dealer total score is :\", dealer_total_score)\n",
" time.sleep(0.8)\n",
" print(\"Seems the house doesn't always wins afterall :(\")\n",
" time.sleep(0.8)\n",
" print(\"Dealer is BUSTTT! You WINN!\")\n",
" break\n",
" print(\"Dealer cards are: \", dealer_cards, \"Dealer total score is :\", dealer_total_score)\n",
" if dealer_total_score >= player_total_score:\n",
" print(\"The house wins, like always..\")\n",
" break\n",
" else:\n",
" print(\"Seems the house doesn't always wins afterall :(\")\n",
" time.sleep(1.2)\n",
" print(\"You WINN!!\")\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
32 changes: 18 additions & 14 deletions your-project/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<img src="https://bit.ly/2VnXWr2" alt="Ironhack Logo" width="100"/>

# Title of Your Project
*[Your Name]*
# Faisal's Blackjack

*[Your Cohort, Campus & Date]*
*Faisal Hammad*

*Data Analytics, Remote Mar 2021*

## Content
- [Project Description](#project-description)
Expand All @@ -13,22 +14,25 @@
- [Links](#links)

## Project Description
Write a short description of your project. Write 1-2 sentences about the game you chose to build and why.
I chose to create the Blackjack game since I wanted to use code using a dictionary. The dictionary I used in this instance was the deck of cards.

## Rules
Briefly describe the rules of the game.
The game is simple: each card has a power. You start with 2 cards and are given the option to get more cards..
Your score is the sum of the card powers you have. Your score should be as closest possible to the number 21. if you exceed you lose

## Workflow
Outline the workflow you used in your project. What are the steps you went through?
I started with defining functions to the main actions of the game which are:
* shuffeling
* dealing
* hitting and standing
* ace power

## Organization
How did you organize your work? Did you use any tools like a kanban board?

What does your repository look like? Explain your folder and file structure.
## Organization
I used a kanban board to track my progress but most of the work was
my repo includes this readme file, the .gitignore file, and a folder that contains the jupyter_notebook file.

## Links
Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project.

[Repository](https://github.com/)
[Slides](https://slides.com/)
[Trello](https://trello.com/en)
[Repository](https://github.com/Faisal7ammad/Project-Week-1-Build-Your-Own-Game)
[Slides](https://drive.google.com/file/d/1zV7l2-VqTTGluNttK8WuHkXvuj84o4lz/view?usp=sharing)
[Trello](https://trello.com/b/G8jVR5ct/blackjack-project)