def find_all_straights(cards: Cards): #TODO fix levels #TODO, put the level in there to differentiate phoenix at start and end #TODO Sort the combinations # remove Dog and Dragon from any straights cards = cards - Dog() - Dragon() buckets = Cards.bucketize_hands(cards.cards) power_values = buckets.keys() possible_straights_power_values = [] # Get all possible power combinations for start in range(Mahjong().power, Dragon().power): length = 0 current_straight_values = [] for next_value in range(start, Dragon().power): found = False new_value = None if next_value in power_values: found = True new_value = next_value elif Phoenix().power in power_values and Phoenix().power not in current_straight_values: if next_value != 1: found = True new_value = Phoenix().power if found and new_value not in current_straight_values: current_straight_values.append(new_value) length += 1 if length >= 5: possible_straights_power_values.append(current_straight_values.copy()) elif not found: break # Now that we have the powers, we get all possible straights straights = [] for straight in possible_straights_power_values: straight_cards = [buckets[power] for power in straight] for combinations in itertools.product(*straight_cards): # straights.append(Cards(cards_list=list(combinations))) straights.append(Combination(cards_list=list(combinations))) # We replace the phoenix in all the straights where we can new_straights = [] for straight in straights: if Phoenix() not in straight.cards: for card in straight.cards: if not card == Mahjong(): new_cards = straight-card+Phoenix() new_combo = Combination(cards_list=new_cards.cards) new_straights.append(new_combo) # new_straights.append(straight - card + Phoenix()) straights.extend(new_straights) straights.sort() return straights
def find_all_multiples(cards: Cards, multiple: int): cards = cards - Dog() - Dragon() buckets = Cards.bucketize_hands(cards.cards) multiples = [] for level in range(Mahjong().power+1, Dragon().power): cards_this_level = buckets[level] if (Phoenix().power in buckets.keys()) and (multiple != 4): cards_this_level.append(Phoenix()) if len(cards_this_level) > 1: for pair in itertools.combinations(cards_this_level, multiple): multiples.append(Combination(cards_list=list(pair))) return multiples
def find_all_multiples(cards: Cards, multiple: int): cards = cards - Dog() - Dragon() buckets = Cards.bucketize_hands(cards.cards) multiples = [] for level in range(Mahjong().power + 1, Dragon().power): cards_this_level = buckets[level] if (Phoenix().power in buckets.keys()) and (multiple != 4): cards_this_level.append(Phoenix()) if len(cards_this_level) > 1: for pair in itertools.combinations(cards_this_level, multiple): multiples.append(Combination(cards_list=list(pair))) return multiples
def find_all_straights(cards: Cards): #TODO fix levels #TODO, put the level in there to differentiate phoenix at start and end #TODO Sort the combinations # remove Dog and Dragon from any straights cards = cards - Dog() - Dragon() buckets = Cards.bucketize_hands(cards.cards) power_values = buckets.keys() possible_straights_power_values = [] # Get all possible power combinations for start in range(Mahjong().power, Dragon().power): length = 0 current_straight_values = [] for next_value in range(start, Dragon().power): found = False new_value = None if next_value in power_values: found = True new_value = next_value elif Phoenix().power in power_values and Phoenix( ).power not in current_straight_values: if next_value != 1: found = True new_value = Phoenix().power if found and new_value not in current_straight_values: current_straight_values.append(new_value) length += 1 if length >= 5: possible_straights_power_values.append( current_straight_values.copy()) elif not found: break # Now that we have the powers, we get all possible straights straights = [] for straight in possible_straights_power_values: straight_cards = [buckets[power] for power in straight] for combinations in itertools.product(*straight_cards): # straights.append(Cards(cards_list=list(combinations))) straights.append(Combination(cards_list=list(combinations))) # We replace the phoenix in all the straights where we can new_straights = [] for straight in straights: if Phoenix() not in straight.cards: for card in straight.cards: if not card == Mahjong(): new_cards = straight - card + Phoenix() new_combo = Combination(cards_list=new_cards.cards) new_straights.append(new_combo) # new_straights.append(straight - card + Phoenix()) straights.extend(new_straights) straights.sort() return straights