Finish blackjack
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
cards = [card for card in range(2, 11) for _ in range(4)]
|
# Generate cards
|
||||||
|
# The first list is for cards 2-10, the second is for cards J-A
|
||||||
|
cards = [card for card in range(2, 11) for _ in range(4)] + [10 for _ in range(0, 16)]
|
||||||
|
|
||||||
def card_string(card: int) -> str:
|
def card_string(card: int) -> str:
|
||||||
match card:
|
match card:
|
||||||
@@ -24,8 +26,6 @@ random.shuffle(cards)
|
|||||||
def deal_card(cards: [int]) -> int:
|
def deal_card(cards: [int]) -> int:
|
||||||
return cards.pop()
|
return cards.pop()
|
||||||
|
|
||||||
print(cards)
|
|
||||||
|
|
||||||
you = 0
|
you = 0
|
||||||
dealer = 0
|
dealer = 0
|
||||||
|
|
||||||
@@ -38,8 +38,6 @@ print("You got dealt", card_string(card1), "and", card_string(card2), "for a tot
|
|||||||
|
|
||||||
dealer += deal_card(cards) + deal_card(cards)
|
dealer += deal_card(cards) + deal_card(cards)
|
||||||
|
|
||||||
print("Shh dont tell them but the dealer has", dealer)
|
|
||||||
|
|
||||||
dealerWon = False
|
dealerWon = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -62,3 +60,18 @@ while True:
|
|||||||
|
|
||||||
if not dealerWon:
|
if not dealerWon:
|
||||||
print("Dealing the dealer")
|
print("Dealing the dealer")
|
||||||
|
print("Dealer has", dealer)
|
||||||
|
while dealer < 16:
|
||||||
|
card = deal_card(cards)
|
||||||
|
dealer += card
|
||||||
|
print("Dealer got", card_string(card), "they have", dealer)
|
||||||
|
if dealer > 21:
|
||||||
|
print("Dealer is bust!")
|
||||||
|
dealerWon = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if dealerWon:
|
||||||
|
if you > dealer:
|
||||||
|
print("You win!")
|
||||||
|
else:
|
||||||
|
print("Dealer wins...")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<title>Max's School Stuff</title>
|
<title>Max's School Stuff</title>
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
body {
|
html {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
Reference in New Issue
Block a user