I decided to challenge myself by creating a poker game. I am currently very confused with tuples and trying to use them properly. I am currently stuck trying to check if the hand (h) is a straight flush or not. Below is the code I am using to create a deck of cards.
numbers=(2,3,4,5,6,7,8,9,10,'J','Q','K','A')
faces=("Clubs","Diamond","Spades","Harts")
print(numbers[0],faces[0])
deck=[]
for i in numbers:
for j in faces:
deck.append((j,i))
hand=d[1],d[5],d[9],d[13],d[17]
The hand above is (('Diamond', 2), ('Diamond', 3), ('Diamond', 4), ('Diamond', 5), ('Diamond', 6))
.
Below is the code I am having trouble with. Currently, it is only able to check if all the faces are the same (it can check if Diamond is the face for all the cards in h), but not able to check if the number is in sequence with numbers. Also I would like to make it so A
can be looped, as a hand like (('Diamond', 2), ('Diamond', 3), ('Diamond', 4), ('Diamond', 5), ('Diamond', A))
is still a valid straight. I know I can use numbers to check the sequence but am trying to do it only using deck.
def straight_flush(h):
r=True
for (i,j) in h:
for (a,b) in h:
if i==a:
r=True
else:
r=False
return r
print(straight_flush(h))