Anonymous
Anonymous

Reputation: 9

How to compare a tuple to a previous one

I've been creating a python program based on the program in this link: how to shuffle a deck of cards in python, but to do it I need to create something to check the different values of the previous cards on the list.

The main program I have so far is this:

# imports random
# imports random
import itertools, random

# make a deck of tiles
deck = list(itertools.product(range(1, 4), range(1,9), [0, 1, 2], ))
deckWinds=(list(itertools.product(range(1, 4), [10, 11, 12, 13], [3])))
deckDragons=(list(itertools.product(range(1, 4), [14, 15, 16], [4])))
deck=deck+deckWinds+deckDragons

for i in range(34):
    x = 'var%d'%i
    globals()[x]=i

# shuffles the deck
random.shuffle(deck)

#have a dictionary of suit names and number names
numbers={10: "E", 11: "S", 12: "W", 13: "N", 14: "White", 15: "Green", 16: "Red"}
suits={0: "Wan", 1: "So", 2: "Pin", 3: "Wind", 4: "Dragon"}

#which card is to be drawn
cardNumber=1

# deal myHand
myHand=[]
for i in range(14):
    drawn=deck[cardNumber]
    cardNumber=cardNumber+1
    myHand.append(drawn)
print(myHand)
visibleHand=[]

# make readable UI version
for i in range(len(myHand)):
    tile, number, suit = myHand[i] # unpack the tuple to have cleaner code
    tileRank=int(number)+(9*int(suit))
    if len(visibleHand)<1:
        visibleHand.append(f"{numbers.get(number, number)} {suits.get(suit, suit)}")
    else:
        if ((number+(suit*9)(myHand[i-1]))<number+(suit*9):
            visibleHand.insert(1, (f"{numbers.get(number, number)} {suits.get(suit, suit)}"))
print(visibleHand)

It starts by generating and shuffling the deck, before drawing a hand for the player. When printed out, though, the hand itself is just a bunch of numbers listed in the order they were drawn, which would make actually playing the game a total pain, because the player would not only have to know what the numbers mean, but also have to rearrange the cards in his head to figure out if he had any usable hands, whereas most online games sort the hands automatically, like in Clubhouse Games switch edition for instance:

Clubhouse Games Switch Riichi Mahjong

I've tried several ways to do this, but most of them have kind of failed. The latest route I'm trying is to get the numbers and suits of all of the previous drawn cards in your hand and compare them to the suit and number of the currently drawn card to see where in the list the card should go, but my closest attempt to a coherent way of phrasing it turned out as such:

  File "main.py", line 40
    if ((number+(suit*9)(myHand[i-1]))<number+(suit*9):
                                                      ^
SyntaxError: invalid syntax

How do you do something like this so it actually works?

Upvotes: 0

Views: 41

Answers (0)

Related Questions