def game_10_combo_2(games): """ This is a 10 number game using combos of 2 """ winnings = 0 cost = 0 for game in range(1, games + 1): # >>> comb(10,2) 45 cost += 45 played = pick(10) picked = pick(20) caught = 0 gamewon = 0 for play in played: if play in picked: caught += 1 two_groups = comb(caught, 2) if two_groups > 0: gamewon += 12 * two_groups winnings += gamewon print('--------------------------------------') print('total games played:' + str(games)) print('total cost:' + str(cost)) print('total winnings:' + str(winnings)) print('total proffit:' + str(winnings - cost)) print('pay ratio:' + str(winnings / cost))
def do_move(self, args): """Move a selected character""" try: adventurer_type = utils.pick("Explorer", self.model.adventurers, auto_pick=True) valid_directions = self.model.get_directions(adventurer_type) direction = utils.pick("Direction", valid_directions) self.model.move_adventurer(adventurer_type, direction) except Exception as err: print(str(err))
def game_5_combo_1(games): """ This is a 5 number game using combo of 1 """ winnings = 0 cost = 0 for game in range(1, games + 1): cost += 6 played = pick(5) picked = pick(20) caught = 0 gamewon = 0 for play in played: if play in picked: caught += 1 if caught == 1: gamewon += 3 # 1 X 1 number game #print('game:' + str(game) + ' caught 1, won:' + str(gamewon)) if caught == 2: gamewon += 6 # 2 X 1 number game #print('game:' + str(game) + ' caught 2, won:' + str(gamewon)) if caught == 3: gamewon += 9 # 3 X 1 number game gamewon += 2 # 5 number game print('game:' + str(game) + ' caught 3, won:' + str(gamewon)) if caught == 4: gamewon += 12 # 4 X 1 number game gamewon += 14 # 5 number game print('game:' + str(game) + ' caught 4, won:' + str(gamewon)) if caught == 5: gamewon += 15 # 5 X 1 number game gamewon += 640 # 5 number game print('game:' + str(game) + ' caught 5, won:' + str(gamewon)) winnings += gamewon print('--------------------------------------') print('total games played:' + str(games)) print('total cost:' + str(cost)) print('total winnings:' + str(winnings)) print('total proffit:' + str(winnings - cost)) print('pay ratio:' + str(winnings / cost))
def select(): global count if with_style: image_a, image_b = pick_with_style(list_method_to_compare, list_style_to_compare, random_pick) else: image_a, image_b = pick(list_method_to_compare, random_pick) count += 1 print('image_a', image_a, 'image_b', image_b) if count == 500: return render_template('message.html', message1='Test completed successfully.', message2='Thank you very much !') list_a, list_b = request.form['image_a'].replace( image_dir, '').split('/'), request.form['image_b'].replace(image_dir, '').split('/') with open('./results/' + user_id + '.txt', 'a') as f: if 'A' in request.form['mode']: selected_filename = request.form['image_a'] f.write(list_a[0] + '_' + list_b[0] + '_' + list_a[1] + '\n') print(list_a[0], list_b[0], list_a[1]) elif 'B' in request.form['mode']: selected_filename = request.form['image_b'] f.write(list_b[0] + '_' + list_a[0] + '_' + list_a[1] + '\n') print(list_b[0], list_a[0], list_a[1]) return render_template('main.html', image_a=image_a, image_b=image_b, user_id=user_id, count=count)
def run(dataset, datasize, transformer_params, ensemble_params, model_type, filename="result.json"): train_set, test_set = dataset train_set, test_set = utils.pick( train_set, test_set, datasize["n_train"], datasize["n_test"] ) # Set the actual data size datasize["n_train"], datasize["n_test"] = len(train_set[1]), len(test_set[1]) if model_type == "normal": result = evaluate_normal(train_set, test_set, transformer_params) elif model_type == "ensemble": result = evaluate_ensemble(train_set, test_set, ensemble_params, transformer_params) else: raise ValueError("Invalid model type '{}'".format(model_type)) params = utils.concatenate_dicts( datasize, transformer_params, ensemble_params, result ) params["model-type"] = model_type export_json(params, filename) print(json.dumps(params, sort_keys=True))
def do_add(self,args): """Add an adventurer""" try: new_adventurer_type = utils.pick("Adventurer", model.Game.ADVENTURER_TYPES) self.model.add_adventurer(new_adventurer_type) except Exception as err: print(str(err))
def do_start(self, args): """Start the game""" self.model = model.Game() self.model.initialise() loop = True while loop is True: island_names = self.model.get_island_names() chosen_island = utils.pick("Island", island_names) self.model.create_island(chosen_island) self.model.current_island.print_layout() if utils.confirm("Ok with this island?") is True: loop = False
def find_start_bag(td: TreeDecomposition, history: Counter = None, debug=False): if USING_COMPLEXITY_WIDTH: # pick bag with highest complexity complexities = compute_complexities(td, DOMAIN_SIZES) if CW_TRAV_STRAT == "max": bag_order = sorted(complexities, key=complexities.get, reverse=True) elif CW_TRAV_STRAT == "max-min": bag_order = sorted(complexities, key=complexities.get, reverse=not CW_TARGET_REACHED) else: # max-rand or tw-max-rand if CW_TARGET_REACHED: bag_order = shuffled(complexities.keys()) else: bag_order = sorted(complexities, key=complexities.get, reverse=True) mincount = min(history[bag_id] for bag_id in bag_order) for bag_id in bag_order: if history[bag_id] == mincount: return bag_id # maxbagidx, _ = max(complexities.items(), key=itemgetter(1)) # if history[maxbagidx] == 0: # return maxbagidx # else: # cw target already met, return random bag # print("randomly picking bag:", end="") # return pick(td.bags.keys()) elif TRAV_STRAT == "random": # randomly pick a bag return pick(td.bags.keys()) else: # pick bag with least count and earliest in order if TRAV_STRAT == "post": trav_order = list(nx.dfs_postorder_nodes(td.decomp)) elif TRAV_STRAT == "pre": trav_order = list(nx.dfs_postorder_nodes(td.decomp)) else: raise ValueError(f"invalid traversal strategy {TRAV_STRAT}") mincount = min(history.values()) # todo[opt]: avoid retraversing every time for bag_id in trav_order: if history[bag_id] == mincount: return bag_id
def start(): global user_id, count count = 1 user_id = request.form['id'] if user_id == '': return render_template('message.html', message1='User ID cannot be EMPTY !', message2='Please input one as you like.') if with_style: image_a, image_b = pick_with_style(list_method_to_compare, list_style_to_compare, random_pick=True) else: image_a, image_b = pick(list_method_to_compare, random_pick=True) print('image_a', image_a, 'image_b', image_b) return render_template('main.html', image_a=image_a, image_b=image_b, user_id=user_id, count=count)
def update(self, data): columns = dict(Listing.__table__.columns) columns = utils.exclude(["user_id", "id"], columns) self.__dict__.update(utils.pick(columns, data))
def snipUser(user): sensitiveKeyList = utils.readKeyz(""" hpw, hVeriCode, hResetPw, resetPwExpiresAt, """) return utils.pick(user, lambda k: k not in sensitiveKeyList)