diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..152a79d --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks +# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks + +### 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/ + +# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks \ No newline at end of file diff --git a/your-project/Draft 2.ipynb b/your-project/Draft 2.ipynb new file mode 100644 index 0000000..237a1a9 --- /dev/null +++ b/your-project/Draft 2.ipynb @@ -0,0 +1,180 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['1 of clubs', '1 of diamonds', '1 of heart', '1 of spades', '2 of clubs', '2 of diamonds', '2 of heart', '2 of spades', '3 of clubs', '3 of diamonds', '3 of heart', '3 of spades', '4 of clubs', '4 of diamonds', '4 of heart', '4 of spades', '5 of clubs', '5 of diamonds', '5 of heart', '5 of spades', '6 of clubs', '6 of diamonds', '6 of heart', '6 of spades', '7 of clubs', '7 of diamonds', '7 of heart', '7 of spades', '8 of clubs', '8 of diamonds', '8 of heart', '8 of spades', '9 of clubs', '9 of diamonds', '9 of heart', '9 of spades', '10 of clubs', '10 of diamonds', '10 of heart', '10 of spades', 'J of clubs', 'J of diamonds', 'J of heart', 'J of spades', 'Q of clubs', 'Q of diamonds', 'Q of heart', 'Q of spades', 'K of clubs', 'K of diamonds', 'K of heart', 'K of spades']\n" + ] + } + ], + "source": [ + "suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\")\n", + "values=(\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\")\n", + "deck=[]\n", + "for value in values:\n", + " for suit in suits:\n", + " deck.append(value +\" of \"+ str(suit)) \n", + "print(deck)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "def card_value(card):\n", + " if card[0] in (\"J\",\"Q\",\"K\"):\n", + " return int(10)\n", + " elif card[0] in (\"A\"):\n", + " return int(1)\n", + " elif card[0] in (\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"):\n", + " return int(card[0])\n", + " \n", + "player_value=0\n", + "dealer_value=0" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['6 of spades', '5 of spades']\n", + "6\n", + "11\n", + "Would you like another card? Yes\n" + ] + } + ], + "source": [ + "player_hand=random.sample(deck,2)\n", + "print(player_hand)\n", + "for card in player_hand:\n", + " player_value += card_value(card)\n", + " print(player_value)\n", + "if player_value==21:\n", + " print(\"Congratulations it's a Blackjack!\")\n", + "else:\n", + " answer= input(\"Would you like another card? \")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['6 of spades', '5 of spades', 'K of diamonds']\n", + "17\n", + "22\n", + "32\n", + "Oh, you have lost! Try next time\n", + "['4 of spades', '5 of heart']\n", + "9\n", + "['6 of diamonds', '9 of diamonds']\n", + "24\n", + "['Q of heart', '2 of diamonds']\n", + "36\n", + "['K of spades', '3 of diamonds']\n", + "49\n", + "['Q of clubs', '7 of spades']\n", + "66\n", + "['K of clubs', 'Q of heart']\n", + "86\n", + "['3 of clubs', 'K of clubs']\n", + "99\n", + "['1 of clubs', 'Q of diamonds']\n" + ] + }, + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for +=: 'int' and 'NoneType'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdealer_hand\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mcard\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdealer_hand\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 22\u001b[1;33m \u001b[0mdealer_value\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[0mcard_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcard\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 23\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdealer_value\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +=: 'int' and 'NoneType'" + ] + } + ], + "source": [ + "while True:\n", + " if answer == \"Yes\":\n", + " player_hand.append(random.sample(deck,1)[0])\n", + " print(player_hand)\n", + " for card in player_hand:\n", + " player_value += card_value(card) \n", + " print(player_value)\n", + " if player_value == 21:\n", + " print(\"Congratulations, it's a BlackjacK!\")\n", + " elif player_value>21:\n", + " print(\"Oh, you have lost! Try next time\")\n", + " break\n", + " \n", + " elif answer == \"No\":\n", + " \n", + " break\n", + " \n", + "while True:\n", + " dealer_hand=random.sample(deck,2)\n", + " print(dealer_hand)\n", + " for card in dealer_hand:\n", + " dealer_value += card_value(card)\n", + " print(dealer_value)\n", + " \n", + " \n", + "\n", + "if dealer_value==player_value== 21:\n", + " print(\"It's a tie!\")\n", + "elif player_valuedealer_value<21:\n", + " print(\"Oh, you have lost! Try next time\")\n" + ] + }, + { + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/your-project/Draft 3.ipynb b/your-project/Draft 3.ipynb new file mode 100644 index 0000000..c5c9667 --- /dev/null +++ b/your-project/Draft 3.ipynb @@ -0,0 +1,145 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First of all define each object we will use for the game loop:\n", + "\n", + "- Card(and value of each card)\n", + "\n", + "- Deck of 52 cards\n", + "\n", + "- Player hand (2 or 3 cards)\n", + "\n", + "- Dealers hand (2 or 3 cards)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Then we define:\n", + "- the first mix and deal to the players\n", + "- players pass or asks\n", + "- players busts\n", + "- mix and deal to the dealer\n", + "- dealer face up second card and pass or asks\n", + "- dealer busts\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once we have all the objects we can start the loop of the game\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\")\n", + "values=(\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\")\n", + "deck=[]\n", + "absolute_values={\"A\":\"1\",\"J\":\"10\",\"Q\":\"10\",\"K\":\"10\"}\n", + "\n", + "for value in values:\n", + " for suit in suits:\n", + " deck.append(value +\" of \"+ str(suit)) \n", + "print(deck)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def card_value(card):\n", + " if card[0] in (\"J\",\"Q\",\"K\"):\n", + " return int(10)\n", + " elif card[0] in (\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"):\n", + " return int(card[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "player_hand=[]\n", + "dealer_hand=[]\n", + "player_value=0\n", + "dealer_value=0\n", + "\n", + "player_hand.append(random.sample(deck,2))\n", + "print(player_hand)\n", + "\n", + "for card in player_hand:\n", + " player_value += card_value(card)\n", + "print(player_hand)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "if player_value == 21:\n", + " print(\"Congratulations you hit the pot!\")\n", + "else:\n", + " print (\"Hit?\")\n", + " answer=input()\n", + "if answer == \"Yes\":\n", + " player_hand.append(random.sample(deck,1))\n", + "else:\n", + " dealer_hand.append(random.sample(deck,2))\n", + " if dealer_value == 21:\n", + " print(\"The dealer has won!\")\n", + " else:\n", + " print (\"Hit?\")\n", + " answer=input()\n", + " if answer == \"Yes\":\n", + " dealer_hand.append(random.sample(deck,1))\n", + " else:\n", + " print(\"Face up the cards\")\n", + " \n" + ] + }, + { + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/your-project/Draft.ipynb b/your-project/Draft.ipynb new file mode 100644 index 0000000..3fd08ac --- /dev/null +++ b/your-project/Draft.ipynb @@ -0,0 +1,111 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\")\n", + "values=(\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\")\n", + "deck=[]\n", + "for value in values:\n", + " for suit in suits:\n", + " deck.append(value +\" of \"+ str(suit)) \n", + "random.shuffle(deck)\n", + "print(deck)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "def card_value(card):\n", + " if card[0] in (\"J\",\"Q\",\"K\"):\n", + " return int(10)\n", + " elif card[0] in (\"A\"):\n", + " return int(1)\n", + " elif card[0] in (\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"):\n", + " return int(card[0])\n", + " \n", + "player_value=0\n", + "dealer_value=0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "player_hand=random.sample(deck,2)\n", + "print(player_hand)\n", + "for card in player_hand:\n", + " player_value += card_value(card)\n", + " print(player_value)\n", + " if player_value==21:\n", + " print(\"Congratulations it's a Blackjack!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " answer=input(\"Hit? \")\n", + " if answer == \"Yes\":\n", + " player_hand.append(random.sample(deck,1)[0])\n", + " print(player_hand)\n", + " for card in player_hand:\n", + " player_value += card_value(card) \n", + " print(player_value)\n", + " if player_value == 21:\n", + " print(\"Congratulations, it's a BlackjacK!\")\n", + " elif player_value>21:\n", + " print(\"Oh, you have lost! Try next time\")\n", + " break\n", + " elif answer == \"No\":\n", + " \n", + "dealer_hand=random.sample(deck,2)\n", + "print(dealer_hand)\n", + "for card in dealer_hand:\n", + "dealer_value +=(card_value(card)\n", + "print(dealer_value)\n", + " \n", + "if dealer_value==player_value== 21:\n", + " print(\"It's a tie!\")\n", + "elif player_valuedealer_value<21:\n", + " print(\"Oh, you have lost! Try next time\")\n" + ] + } + ], + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/your-project/Project 1_final version-Pol Serramalera.ipynb b/your-project/Project 1_final version-Pol Serramalera.ipynb new file mode 100644 index 0000000..a2a1865 --- /dev/null +++ b/your-project/Project 1_final version-Pol Serramalera.ipynb @@ -0,0 +1,163 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Let's play Ironjack!" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to Ironjack, be patient gambler we are shuffling the deck!\n", + "['2 of heart', 'A of clubs', 'A of diamonds', '3 of heart', 'J of spades', 'K of diamonds', 'K of clubs', 'Q of diamonds', '4 of heart', '9 of heart', '8 of clubs', '6 of clubs', '5 of clubs', '3 of spades', '10 of heart', '9 of spades', '6 of heart', '6 of diamonds', '7 of heart', '6 of spades', '9 of clubs', 'Q of spades', '4 of spades', '7 of spades', '4 of clubs', '10 of diamonds', '2 of clubs', 'J of heart', 'J of clubs', '9 of diamonds', '2 of spades', '7 of diamonds', '3 of diamonds', 'J of diamonds', 'A of heart', 'Q of clubs', '8 of heart', '10 of spades', 'Q of heart', '7 of clubs', '3 of clubs', '4 of diamonds', '8 of diamonds', '5 of heart', '2 of diamonds', '5 of diamonds', 'K of spades', 'K of heart', '8 of spades', '5 of spades', '10 of clubs', 'A of spades']\n", + "Here are your cards!\n", + "['9 of diamonds', 'Q of clubs']\n", + "19\n", + "Do you want another card? No\n", + "Okay, now it's the dealer turn!\n", + "['4 of heart', '5 of diamonds']\n", + "['4 of heart', '5 of diamonds', '9 of spades']\n", + "18\n", + "You win!\n" + ] + } + ], + "source": [ + "import random\n", + "import time \n", + "suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\") \n", + "values=(\"A\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\") \n", + "deck=[]\n", + "for value in values: \n", + " for suit in suits:\n", + " deck.append(value +\" of \"+ str(suit)) #First of all, create a deck through a list of suits and values and using a for loop\n", + "\n", + "random.shuffle(deck) #with this function here we are able to mix randomly the deck\n", + "\n", + "print(\"Welcome to Ironjack, be patient gambler we are shuffling the deck!\")\n", + "\n", + "time.sleep(2)\n", + "\n", + "print(deck)\n", + "\n", + "time.sleep(1)\n", + " \n", + " \n", + " #-----------------------\n", + "\n", + "def card_value(card):\n", + " if card[0] in (\"J\",\"Q\",\"K\"): #Here we create a function in order to give a integer value to each type of card of the deck\n", + " return int(10)\n", + " elif card[0] in (\"A\"): #We assume A has a value of 1\n", + " return int(1)\n", + " else:\n", + " return int(card[0])\n", + "\n", + " #----------------------\n", + "player_value=0\n", + "dealer_value=0\n", + "print(\"Here are your cards!\")\n", + "time.sleep(2)\n", + "player_hand=random.sample(deck,2) #We deal 2 random cards to the player. With this function the two cards are removed from the deck\n", + "print(player_hand)\n", + "for card in player_hand:\n", + " player_value += card_value(card)\n", + " \n", + " if player_value==21:\n", + " print(\"Congratulations it's a Blackjack!\")\n", + " \n", + "print(player_value)\n", + "\n", + "time.sleep(1)\n", + "\n", + "while True:\n", + " answer=input(\"Do you want another card? \")\n", + " if answer == \"Yes\":\n", + " time.sleep(2) #We ask the player if he wants another card and start a while loop\n", + " player_hand.append(random.sample(deck,1)[0])\n", + " print(player_hand)\n", + " extra_card = card_value(player_hand[-1])\n", + " player_value += extra_card\n", + " print(player_value)\n", + " if player_value == 21:\n", + " print(\"Congratulations, it's a BlackjacK!\")\n", + " break\n", + " elif player_value>21:\n", + " print(\"You are busted!\")\n", + " break\n", + " \n", + " \n", + " elif answer == \"No\":\n", + " print(\"Okay, now it's the dealer turn!\")\n", + " time.sleep(2)\n", + " dealer_hand=random.sample(deck,2)\n", + " print(dealer_hand)\n", + " for card in dealer_hand:\n", + " dealer_value += card_value(card)\n", + " \n", + " while dealer_value <= 17:\n", + " dealer_hand.append(random.sample(deck,1)[0])\n", + " extra_cardd=card_value(dealer_hand[-1])\n", + " dealer_value += extra_cardd\n", + " print(dealer_hand) \n", + " print(dealer_value)\n", + " if dealer_value<=21:\n", + " if dealer_value==player_value:\n", + " print(\"It's a tie!\")\n", + " elif player_value>dealer_value:\n", + " print(\"You win!\")\n", + " else:\n", + " print(\"You lose!\")\n", + "\n", + " else:\n", + " print(\"Dealer is busted, you win!\")\n", + "\n", + " break\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}