def has_same_suit(self, cards): cards = Pack(cards) suitlist = cards.get_suits() if suitlist[1] == suitlist[0] and suitlist[2] == suitlist[0]: return True elif suitlist[1] != suitlist[0] and suitlist[2] != suitlist[0] and suitlist[2] != suitlist[1]: return False return None
def has_sequence(self, cards): cards = Pack(cards) cardlist = cards.get_values() x = min(cardlist) sequence = lambda x: [x, x+1, x+2] if cardlist == sequence(x): return True return False
class Player(object): def __init__(self): self.cards = Pack([]) def play(self): """ Need to implement on extends """ raise NotImplementedError def show_cards(self): i = 1 for card in self.cards: print i, card i += 1 return def get_card(self, card): self.cards.get_card(card)
def __init__(self): self.cards = Pack([])
def has_same_value(self, cards): cards = Pack(cards) valuelist = cards.get_values() if valuelist[1] == valuelist[0] and valuelist[2] == valuelist[0]: return True return False
def __init__(self): self.cards = Pack() self.cards.shuffle() self.players = Human(), Computer() self._num_players = len(self.players) self.distribute()
class Manager(object): players = [] _turn = -1 _num_players = 0 _garbage = None _flipped = None def __init__(self): self.cards = Pack() self.cards.shuffle() self.players = Human(), Computer() self._num_players = len(self.players) self.distribute() def distribute(self): for i in xrange(9): for player in self.players: player.cards.get_card(self.cards.next_card()) def turn(self): self._turn += 1 if self._turn < self._num_players: return self.players[self._turn] self._turn = 0 return self.players[self._turn] def game(self): winner = None while self.cards: player = self.turn() self._garbage = player.play(self._garbage, self.cards) if isinstance(self._garbage, list): winner = self.players[1] # computador break return winner def next_card(self): if self._flipped is None: self._flipped = self.cards.next_card() return self._flipped def has_sequence(self, cards): cards = Pack(cards) cardlist = cards.get_values() x = min(cardlist) sequence = lambda x: [x, x+1, x+2] if cardlist == sequence(x): return True return False def has_same_value(self, cards): cards = Pack(cards) valuelist = cards.get_values() if valuelist[1] == valuelist[0] and valuelist[2] == valuelist[0]: return True return False def has_same_suit(self, cards): cards = Pack(cards) suitlist = cards.get_suits() if suitlist[1] == suitlist[0] and suitlist[2] == suitlist[0]: return True elif suitlist[1] != suitlist[0] and suitlist[2] != suitlist[0] and suitlist[2] != suitlist[1]: return False return None def meta_group(self, cards): ordened = cards.sort_by_value() if len(ordened) == 3: if (self.has_sequence(ordened) and self.has_same_suit(ordened) == True) or \ (self.has_same_value(ordened) and self.has_same_suit(ordened) == False): return True return False def meta(self, cards_groups): cards = [] for group in cards_groups: data = [] for card in group: if card: data.append(Card(card)) else: data.append(None) cards.append(Pack(data)) if len(cards) == 3: is_valid = True for group in cards: if not self.meta_group(group): is_valid = False break continue return is_valid return False