mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 15:50:20 -08:00
Acey Ducey fixes for #869
This commit is contained in:
@@ -34,10 +34,10 @@ proc printCard(aCard: int) =
|
||||
|
||||
proc drawDealerCards() =
|
||||
echo "HERE ARE YOUR NEXT TWO CARDS: "
|
||||
cardA = rand(2..14)
|
||||
cardA = rand 2..14
|
||||
cardB = cardA # Copy cardA, so we can test cardB to be different
|
||||
while cardB == cardA:
|
||||
cardB = rand(2..14)
|
||||
cardB = rand 2..14
|
||||
if cardA > cardB: # Make sure cardA is the smaller card
|
||||
swap cardA, cardB
|
||||
echo ""
|
||||
@@ -80,8 +80,9 @@ while retry:
|
||||
echo "YOU WIN!!!"
|
||||
stash += bet
|
||||
else:
|
||||
echo "SORRY, YOU LOSE"
|
||||
stash -= bet
|
||||
if bet > 0:
|
||||
echo "SORRY, YOU LOSE"
|
||||
stash -= bet
|
||||
echo "SORRY, FRIEND, BUT YOU BLEW YOUR WAD."
|
||||
echo ""
|
||||
retry = tryAgain()
|
||||
|
||||
@@ -7,7 +7,6 @@ https://www.atariarchives.org/basicgames/showpage.php?page=2
|
||||
import random
|
||||
|
||||
cards = {
|
||||
1: "1",
|
||||
2: "2",
|
||||
3: "3",
|
||||
4: "4",
|
||||
@@ -16,22 +15,25 @@ cards = {
|
||||
7: "7",
|
||||
8: "8",
|
||||
9: "9",
|
||||
10: "Jack",
|
||||
11: "Queen",
|
||||
12: "King",
|
||||
13: "Ace",
|
||||
10: "10",
|
||||
11: "Jack",
|
||||
12: "Queen",
|
||||
13: "King",
|
||||
14: "Ace",
|
||||
}
|
||||
|
||||
|
||||
def play_game() -> None:
|
||||
cash = 100
|
||||
while cash > 0:
|
||||
print(f"You now have {cash} dollars\n")
|
||||
print("Here are you next two cards")
|
||||
round_cards = list(cards.keys())
|
||||
random.shuffle(round_cards)
|
||||
card_a, card_b, card_c = round_cards.pop(), round_cards.pop(), round_cards.pop()
|
||||
if card_a > card_b:
|
||||
round_cards = list(cards.keys()) # gather cards from dictionary
|
||||
card_a = random.choice(round_cards) # choose a card
|
||||
card_b = card_a # clone the first card, so we avoid the same number for the second card
|
||||
while (card_a == card_b): # if the cards are the same, choose another card
|
||||
card_b = random.choice(round_cards)
|
||||
card_c = random.choice(round_cards) # choose last card
|
||||
if card_a > card_b: # swap cards if card_a is greater than card_b
|
||||
card_a, card_b = card_b, card_a
|
||||
print(f" {cards[card_a]}")
|
||||
print(f" {cards[card_b]}\n")
|
||||
@@ -53,7 +55,7 @@ def play_game() -> None:
|
||||
print("Please enter a positive number")
|
||||
print(f" {cards[card_c]}")
|
||||
if bet > 0:
|
||||
if card_a < card_c < card_b:
|
||||
if card_a <= card_c <= card_b:
|
||||
print("You win!!!")
|
||||
cash += bet * 2
|
||||
else:
|
||||
@@ -82,4 +84,5 @@ If you do not want to bet, input a 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
random.seed()
|
||||
main()
|
||||
|
||||
@@ -8,6 +8,7 @@ Python port by Aviyam Fischer, 2022
|
||||
"""
|
||||
|
||||
from typing import List, Literal, NamedTuple, TypeAlias, get_args
|
||||
import random
|
||||
|
||||
Suit: TypeAlias = Literal["\u2665", "\u2666", "\u2663", "\u2660"]
|
||||
Rank: TypeAlias = Literal[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
||||
@@ -34,8 +35,6 @@ class Deck:
|
||||
self.cards.append(Card(suit, rank))
|
||||
|
||||
def shuffle(self) -> None:
|
||||
import random
|
||||
|
||||
random.shuffle(self.cards)
|
||||
|
||||
def deal(self) -> Card:
|
||||
@@ -72,7 +71,7 @@ class Game:
|
||||
if 0 < bet <= self.money:
|
||||
|
||||
print(f"Your deal:\t {player_card}")
|
||||
if card_a.rank < player_card.rank < card_b.rank:
|
||||
if card_a.rank <= player_card.rank <= card_b.rank:
|
||||
print("You Win!")
|
||||
self.money += bet
|
||||
else:
|
||||
@@ -87,9 +86,6 @@ class Game:
|
||||
else:
|
||||
print("You would lose, so it was wise of you to chicken out!")
|
||||
|
||||
self.not_done = False
|
||||
break
|
||||
|
||||
if len(self.deck.cards) <= 3:
|
||||
print("You ran out of cards. Game over.")
|
||||
self.not_done = False
|
||||
@@ -129,4 +125,5 @@ def main() -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
random.seed()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user