def generate_card(): card_data = read_card_data() card = create_new_card() if card != None: card_data.append(card) save_card_data(card_data)
def remove_card(): card_data = read_card_data() input_index = get_input(prompt("Card index: "), is_int) card_index = int(input_index) if card_index >= len(card_data): print_warn("card index out of range, abort!") return card = card_data[card_index] print(content("===========================")) print(content("Card: " + str(card.index))) print(content("---------------------------")) print_card(card) print(content("===========================")) answer = input(warn("remove[y, n]? ")) if answer == "y": print_done("remove card " + str(card_index)) del card_data[card_index] save_card_data(card_data) else: print_done("remove abort")
def list_cards(): card_data = read_card_data() for card in card_data: print(content("Card " + str(card_data.index(card)))) print_card(card) print(content("--------------------------------"))
def filter_with_condition(): done = False while not done: input_condition = input(prompt("condition: ")) if len(input_condition.strip()) == 0: done = True print(warn("empty input, abort")) continue conditions = parse_condition(input_condition) print(Style.BRIGHT + hint("filter conditions: " + str(conditions)) + Style.RESET_ALL) if len(conditions.keys()) == 0: print(warn("no available condition found, press ENTER to abort")) continue cards = read_card_data() card_set_combinations = get_card_set_combination(cards) #for card_set in card_set_combinations: print_max(conditions, card_set_combinations) print("number of card combination: " + str(len(card_set_combinations))) print("============================") match_card_set = [] match_count = 0 for card_set in card_set_combinations: if not match_conditions(card_set, conditions): continue if contain_exclusive_card(card_set): continue card_list = "" for i in range(len(card_set)): if i == 0: card_list += str(card_set[i].index) else: card_list += ", " + str(card_set[i].index) print("Cards: [" + card_list + "]") print("----------------------------") compare_with_current_card_set(card_set) print("============================") match_card_set.append(card_set) match_count += 1 print_done("matched result: " + str(match_count)) best_card_set = find_best_card_set_with_conditions( match_card_set, conditions)
def insert_card(): card = create_new_card() if card == None: return index = int(get_input("insert at index: ", verify_index)) card_data = read_card_data() if index <= len(card_data): card_data.insert(index, card) save_card_data(card_data) else: print_warn("invalid index, abort!")
def optimize(): cards = read_card_data() card_set_combinations = get_card_set_combination(cards) print("number of card combination: " + str(len(card_set_combinations))) print("============================") equipped_card_set = list(map(lambda index: cards[index], range(5))) equipped_card_attr = get_summed_attribute_vector(equipped_card_set) important_attr_index = range(5) for card_set in card_set_combinations: sum_vector = get_summed_attribute_vector(card_set) skip = False for index in important_attr_index: if sum_vector[index] < equipped_card_attr[index]: skip = True break if skip: continue if contain_exclusive_card(card_set): continue card_list = "" for i in range(len(card_set)): if i == 0: card_list += str(card_set[i].index) else: card_list += ", " + str(card_set[i].index) print("Cards: [" + card_list + "]") print("----------------------------") #print_attribute(sum_vector) compare_with_current_card_set(card_set) print("============================")
def create_new_card(): done = False card_data = read_card_data() card = Card(len(card_data)) while not done: print_options() input_line = input(prompt("enter \"attr value\": ")) if len(input_line.strip()) == 0: done = True continue split_line = input_line.split(" ") length = len(split_line) if length == 0 or length % 2 != 0: done = True continue for i in range(0, len(split_line) - 1, 2): attr = split_line[i].strip() value = split_line[i + 1].strip() resolved_attribute_name = resolve_attribute_name(attr, value) if resolved_attribute_name == None: continue card.attributes[resolved_attribute_name] = value if len(card.attributes.keys()) == 0: print_warn("no attribute set, cancel") return None else: print_card(card) return card
def compare_with_current_card_set(card_set): from IOUtils import read_card_data cards = read_card_data() compare_card_set([cards[0], cards[1], cards[2], cards[3], cards[4]], card_set)