Exemplo n.º 1
0
def batching(size):
    print('running batching')
    xbat = []
    ybat = []
    b = Baraja()
    for _ in range(size):
        b.revolver()
        xbat.append(b.one_hot())
        ybat.append(b.approx_best_move(sample_size=150)[0])
    return xbat, ybat
Exemplo n.º 2
0
 def test_one_hot_inv(self):
     B = Baraja()
     B.revolver()
     bin_lst = B.one_hot()
     self.assertEqual(B.sacar_mano(5), Mano(one_hot_inv(bin_lst)))
     self.assertEqual(len(bin_lst), 52)
Exemplo n.º 3
0
 def test_one_hot(self):
     B = Baraja()
     bin_lst = B.one_hot()
     self.assertEqual(sum(bin_lst), 5)
Exemplo n.º 4
0
        b.revolver()
        xbat.append(b.one_hot())
        ybat.append(b.approx_best_move(sample_size=150)[0])
    return xbat, ybat


for _ in range(5):
    print('started batching ')
    pool = mp.Pool(processes=4)
    ret = pool.map(batching, 4 * [10])
    pool.close()
    lx = reduce(lambda a, b: a + b, [r[0] for r in ret])
    ly = reduce(lambda a, b: a + b, [r[1] for r in ret])
    x_train = np.reshape(np.array(lx).astype(np.float32), [len(lx), 52])
    y_train = np.reshape(np.array(ly).astype(np.float32), [len(ly), 1])
    model.fit(x_train, y_train, epochs=5)

bar = Baraja()
num_games = 10
credit = 0
for _ in range(num_games):
    bar.revolver()
    oh = np.array(bar.one_hot(), ndmin=2)
    acc = np.argmax(model.call(oh))
    #acc = random.randint(0,31)
    credit += bar.play(acc).value
print("The expected return is: ", credit / num_games - 1)
model_filepath = 'poker.mdl'
print('saving model at: ', model_filepath)
model.save(model_filepath)