def calculate_valid_cards(self): '''Calculates which cards can be played on layout.''' # If layout is not active then only card of rank 7 is valid if len(self.cards) == 0: valid_cards = [Card(7, self.suit)] else: valid_cards = [ self.get_highest_playable_card(), self.get_lowest_playable_card() ] return [c for c in valid_cards if c is not None]
def get_lowest_playable_card(self): '''Returns card instance for the lowest playable card''' lowest_playable_card = None lowest_rank = self.get_lowest_card_rank() if lowest_rank: lowest_playable_rank = lowest_rank - 1 if lowest_playable_rank in RANKS: lowest_playable_card = Card(lowest_playable_rank, self.suit) return lowest_playable_card
def get_highest_playable_card(self): '''Returns card instance for the highest playable card''' highest_playable_card = None highest_rank = self.get_highest_card_rank() if highest_rank: highest_playable_rank = highest_rank + 1 if highest_playable_rank in RANKS: highest_playable_card = Card(highest_playable_rank, self.suit) return highest_playable_card