예제 #1
0
 def __init__(self, conversor):
     self.conversor = conversor
     self.baraja = Baraja()
예제 #2
0
파일: tests.py 프로젝트: lab156/baraja
 def setUp(self):
     self.baraja = Baraja()
예제 #3
0
#     name: python3
# ---

import random as r
import itertools as itt
import sys
from scipy.stats import chi2
# %load_ext autoreload
# %autoreload 2
import actions as act
from collections import Counter
from baraja import Naipe, Mano, Baraja, Prize
# #%run ~/code/EfedEquis/Efedequis/poquer/baraja/baraja

# %%time
b = Baraja()
b.start_with(map(Naipe,['6D', 'QH', '7H', '7S', '10C']))
#b.evaluate(13, sample_size=5000000)
prize_counter = Counter()
for _ in range(1000):
    prize_counter.update([b.play(13)])
print(prize_counter.most_common())
b.approx_best_move(sample_size=300)

# %%time
b = Baraja()
b.start_with(map(Naipe,['3S', 'QS', 'JD', '7S', '6S']))
res = []
for i in range(32):
    res.append((act.actions[i], b.evaluate_eff(i, sample_size=10)))
{k: v for k, v in sorted(res, key=lambda item: -item[1])}
예제 #4
0
파일: tests.py 프로젝트: lab156/baraja
 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)
예제 #5
0
파일: tests.py 프로젝트: lab156/baraja
 def test_approx_best_move(self):
     b = Baraja()
     b.start_with(map(Naipe, ['AS', 'QS', 'JS', 'KS', '10S']))
     self.assertEqual(b.approx_best_move(sample_size=200)[0], 31)
예제 #6
0
파일: tests.py 프로젝트: lab156/baraja
 def test_randSample(self):
     B = Baraja()
     s = B.randSample(1, after=51)[0]
     self.assertEqual(Naipe('KD'), Naipe(s))
예제 #7
0
파일: tests.py 프로젝트: lab156/baraja
 def test_one_hot(self):
     B = Baraja()
     bin_lst = B.one_hot()
     self.assertEqual(sum(bin_lst), 5)
예제 #8
0
파일: tests.py 프로젝트: lab156/baraja
 def test_baraja_index2(self):
     B = Baraja()
     carta = Naipe((2, 0))
     ind = B.index(carta)
     self.assertEqual(ind, 4)
예제 #9
0
파일: tests.py 프로젝트: lab156/baraja
 def test_randNaipe_alot(self):
     B = Baraja()
     for _ in range(1000):
         B.randNaipe(15)
예제 #10
0
파일: tests.py 프로젝트: lab156/baraja
 def test_certificate_stays_the_same(self):
     B = Baraja()
     certif1 = B.certificate
     B.revolver
     certif2 = B.certificate
     self.assertEqual(certif1, certif2)
예제 #11
0
파일: tests.py 프로젝트: lab156/baraja
 def test_baraja_index1(self):
     B = Baraja()
     ind = B.index((2, 0))
     self.assertEqual(ind, 4)
예제 #12
0
파일: tests.py 프로젝트: lab156/baraja
 def test_preview_length(self):
     B = Baraja()
     B.preview()
     self.assertEqual(len(B.preview()), 10)
예제 #13
0
파일: tests.py 프로젝트: lab156/baraja
 def test_sacar_lista_naipes(self):
     B = Baraja()
     self.assertEqual(len(B.sacar_lista_naipes(26)), 26)
     self.assertEqual(len(B.sacar_lista_naipes(26)), 26)
     self.assertEqual(len(B.sacar_lista_naipes(26)), 0)
예제 #14
0
파일: test_baraja.py 프로젝트: spuzi/holdem
 def test_baraja_tiene_52_cartas(self):
     baraja = Baraja()
     numero_de_cartas = baraja.get_numero_de_cartas()
     self.assertEqual(numero_de_cartas, 52,
                      "El numero de cartas en una baraja es de 52 cartas")
예제 #15
0
import io
import sys
import time
import pickle
from baraja import Naipe, Baraja

#sys.stdout.write('/033[31m' + 'some red text\\n')
#sys.stdout.flush()

b = Baraja()
n = 0
conjunto = set()
print("Inicializando Todo")

cycle_size = 1000
keep_looping = True
while keep_looping:
    try:
        n = n + 1
        for i in range(cycle_size):
            b.revolver()
            if b.chequear_3_iguales():
                conjunto.add(b.sacar_mano(5))
        message_str = "Hallado: %s de %s \r" % (len(conjunto), n * cycle_size)
        sys.stdout.write(message_str)
        sys.stdout.flush()
        time.sleep(1)
    except KeyboardInterrupt:
        print('Salio Exito')
        keep_looping = False
예제 #16
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)