import deck

class Card(object):
    '''A card with a rank and a suit that can be either face up or face down.
    The rank is one of deck.Deck.RANKS and the suit is one of
    deck.Deck.SUITS.'''
    
    def __init__(self, s, r):
        '''A new face-down Card with suit str s and rank str r.'''

        self.suit = s
        self.rank = r
        self.is_face_up = False
        
    def __str__(self):       
        '''Return this Card's rank and suit together as a str, or 'XX' if this
        card is face down.'''

        if self.is_face_up:
            return self.rank + self.suit
        else:
            return 'XX'
    
    def __cmp__(self, other):
        '''Return -1 if this Card is less than Card other, 0 if they are equal,
        and 1 if this Card is greater. The comparison is done based on the rank
        of the cards. NOTE: This method isn't quite right. One of your tasks
        will be to fix it.'''

        if deck.Deck.RANKS.index(self.rank) < deck.Deck.RANKS.index(other.rank):
            return -1
        else:
            return 1

    def turn_over(self):
        '''Flip this card over.'''

        self.is_face_up = not self.is_face_up
        
    def turn_down(self):
        '''Make this card be face down.'''
        
        self.is_face_up = False
