This is a Acey Ducey Game. I have been at this project for about 4 days now
Question:
This is a Acey Ducey Game.
I have been at this project for about 4 days now and everything works awesome except for the examples shown in my screenshot. I am missing something in the code.
deal - a method that returns the value of the card on top of the deck. Once a card is dealt it cannot be dealt again until the deck is shuffled.
shuffle - a method that returns to the deck all dealt cards (for a total of 52, no Jokers) and places it in a random order.
fan - fan is a method that will simply list the cards in the deck from the top card to the card on the bottom of the deck.
isOrdered - a method that returns True if the deck is in order and False if it is not. If an ordered deck has a few cards dealt off of the top it is still in order. You do not need a full deck to be in order.
Order - a method that sorts the deck or puts the cards in order with the 2 of clubs beings lowest and the ace of spades being highest (while there is no real ranking of suits we'll go with the standard poker/bridge ranking of clubs(lowest), diamonds, hearts, spades(highest).
Example 1. Two Cards QC & 8S
Third Card 10C
This should be a win, but it is showing as a loss
Example 2. Two Cards 3H & AS(Ace is a high card)
Third Card 5D
This should be a win, but it is showing as a loss
Example 3. Two Cards KS & 4S
Third Card 3D
This should be a loss, but it is showing as a win.
What am I missing??
import random
class Deck(object):
def __init__(self):
self.cards = []
self.dealt=0
self.Order()
def deal(self):
if self.dealt==52:
self.shuffle()
dealt_value=self.cards[self.dealt]
self.dealt=self.dealt+1
return dealt_value
def shuffle(self):
self.dealt=0
for i in range(len(self.cards)):
rNo=random.randint(0,51)
temp=self.cards[rNo]
self.cards[rNo]=self.cards[i]
self.cards[i]=temp
def fan(self):
for i in range(len(self.cards)):
print(self.cards[i],end=' ')
def isOrdered(self):
suit = ["C", "D", "H", "S"]
rank = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K","A",]
sorted_deck=[]
for s in suit:
for r in rank:
sorted_deck.append(r+s)
x=self.dealt
while x
return False
x=x+1
return True
def Order(self):
suit = ["C", "D", "H", "S"]
rank = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K","A",]
for s in suit:
for r in rank:
self.cards.append(r+s)
print("The Acey Deucey Game")
deck=Deck()
deck.shuffle()
print("Rules:")
print("1. If the 3rd card lands exactly between first two cards, you will WIN. ")
print("2. If it falls outside of your two cards you LOSE")
print("Deal the cards dealer...")
ranks="23456789TJQKA"
balance = 1000
while True:
c1=deck.deal()
c2=deck.deal()
print("Your two cards: ",c1,c2)
print("Current balance: ", balance)
v1=c1[0:len(c1)-1]
v2=c2[0:len(c2)-1]
if v1=="10":
v1="T"
if v2=="10":
v2="T"
bet = 0
if v1==v2:
print("if both cards have the same value!")
print("You LOSE!")
balance -= bet
else:
s1=ranks.find(v1)
s2=ranks.find(v2)
bet = 0
if s1-s2==1 or s2-s1==1:
print("Sorry they are consecutvie cards!")
print("You LOSE!")
balance -= bet
else:
bet=int(input('Enter Your Wager: '))
while bet <= 0:
print("Wager must be at least 1 chip")
bet=int(input('Enter the Wager(number of chips): '))
print("The game continues...")
c3=deck.deal()
print("The 3rd card is: ",c3)
v3=c3[0:len(c3)-1]
if v3=="10":
v3="T"
s3=ranks.find(v3)
if s1-s3==1 or s3-s1==1 or s2-s3==1 or s3-s2==1:
print("Congratulations, you won!")
balance += bet
else:
print("Sorry, you LOSE!")
balance -= bet
if balance < -500:
print("Your balance is below -$500. Please add money to your account.")
break
nextRound=input("Would you like to play one more round(y/n)? ")
if nextRound=="n" or nextRound=="N":
print(" ***Thank you***")
print("***Come back and play again***")
break
Applying Communication Theory For Professional Life A Practical Introduction
ISBN: 9781506315478
4th Edition
Authors: Marianne Dainton, Elaine D. Zelley