# Jared Wasserman
# 6/4/2013
# This class stores a single playing card
# Python translation of Arup's Java program

class Card:

    suits = ["Clubs", "Diamonds", "Hearts", "Spades"]
    kinds = ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"]


    # Since we are storing the array indices of the suit and kind, if we are given
    # the string representation of either of these values, just return the array index. 
    def __init__(self, s, k):
        if (isinstance(s, str)):
            self.suit = Card.lookup(Card.suits, s)
        else:
            self.suit = s
        
        if (isinstance(k, str)):
            self.kind = Card.lookup(Card.kinds, k)
        else:
            self.kind = k


    # If item is an element of list, this method returns the FIRST
    # index in which item is stored. If it is not, -1 is returned.
    @staticmethod
    def lookup(my_list, item):

        # Go through each item in the list.
        for i in range(len(my_list)):
            if (my_list[i] == item):
                return i

        # Item was not found, so return -1.
        return -1


    # Returns true iff this is the same kind as the kind s.
    def same_kind(self, s):
        return self.kind == Card.lookup(Card.kinds, s)
    

    # Returns a string representation of a card.
    def __str__(self): 
        return Card.kinds[self.kind] + " of " + Card.suits[self.suit]
    
