コード例 #1
0
def generateNNTrainingData(policy, state_potentials, new_training_title,
                           n_trials):
    labelout = open("training/" + new_training_title, "a")
    sys.stdout.write('Generating training data')
    sys.stdout.flush()
    for x in range(0, n_trials):
        sheet, roll, n_rerolls = sample_gamespace(policy.choose_dice,
                                                  policy.choose_category)
        opt_move = optimal_strategy.queryMove(state_potentials,
                                              sheet.as_bitmask(),
                                              roll.as_list(), n_rerolls)
        labeled_one_hot = None
        labelout.write(sheet.as_csv() + "," + roll.as_string() + "," +
                       str(n_rerolls) + ",")
        try:
            best_category = YahtzeeScoresheet.categories[opt_move]
            labelout.write(best_category + ",")
            labeled_one_hot = label.build_one_hot(opt_move, 13)
        except (ValueError, TypeError) as e:
            kept_dice = Roll(opt_move)
            labelout.write("[" + kept_dice.as_string() + "],")
            labeled_one_hot = label.find_macro(kept_dice, roll, sheet,
                                               n_rerolls)
        labelout.write(labeled_one_hot + "\n")
        if x % 1000 == 0:
            sys.stdout.write('.')
            sys.stdout.flush()
    labelout.close()
コード例 #2
0
 def generate_training_data(self, n_trials, all_data):
     for x in range(0, n_trials):
         current_line = ""
         sheet, roll, n_rerolls = sample_gamespace(self.choose_dice,
                                                   self.choose_category)
         opt_move = optimal_strategy.queryMove(self.state_potentials,
                                               sheet.as_bitmask(),
                                               roll.as_list(), n_rerolls)
         labeled_one_hot = None
         current_line = sheet.as_csv() + "," + roll.as_string() + "," + str(
             n_rerolls) + ","
         try:  # assume in this situation you choose a category to score in
             best_category = YahtzeeScoresheet.categories[opt_move]
             current_line += best_category + ","
             labeled_one_hot = label.build_one_hot(lookup_macro[opt_move],
                                                   10)
         except (ValueError, TypeError) as e:
             kept_dice = Roll(opt_move)
             current_line += "[" + kept_dice.as_string() + "],"
             labeled_one_hot = label.find_macro(kept_dice, roll, sheet,
                                                n_rerolls)
         current_line += labeled_one_hot + "\n"
         all_data.append(current_line)