Ejemplo n.º 1
0
 def __init__(self, iterations=5):
     results = []
     situations = []
     logging.basicConfig()
     for i in range(0, iterations):
         g = Game(print_board=False)
         round_situations = []
         while not g.game_over:
             choices = g.available_cols()
             choice = random.choice(choices)
             round_situations.append(self.game_to_sit(g, choice))
             g.place_piece(choice)
         for situation in round_situations:
             results.append(g.points)
         situations.extend(round_situations)
     #self.pipeline = Pipeline([
     #    ('min/max scaler', MinMaxScaler(feature_range=(0.0, 1.0))),
     #    ('neural network', Regressor(
     self.nn = Regressor(layers=[
                 Layer("Rectifier", units=100),
                 Layer("Linear")],
             learning_rate=0.00002,
             n_iter=10)
     #self.pipeline.fit(np.array(situations), np.array(results))
     print np.array(situations).shape
     self.nn.fit(np.array(situations), np.array(results))
Ejemplo n.º 2
0
def naive_scores(iterations):
    scores = []
    for i in range(iterations):
        g = Game(print_board=False, classic_mode=False)
        while not g.game_over:
            choices = g.available_cols()
            choice = random.choice(choices)
            g.place_piece(choice)
        scores.append(g.points)
    return max(scores), sum(scores)/len(scores)