-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceliter.py
More file actions
104 lines (91 loc) · 3.02 KB
/
celiter.py
File metadata and controls
104 lines (91 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
from iteration_utilities import grouper
from beggarplay import play as celplay
from celery import Celery
from beggar import BeggarGame, Court, Deck
import time
import sys
import os
from tqdm import tqdm
def report(res):
for r in res:
print("Game {}, max {}".format(r[0], r[1]))
start = 4433230883192896
# start = 0
deck = Deck(court=Court().default(), decksize=52)
c = Court()
c.add("A", 4, 3)
c.add("K", 3, 3)
c.add("Q", 2, 3)
c.add("J", 1, 3)
deck = Deck(court=c, decksize=52)
bg = BeggarGame(deck, gamenum=start)
os.environ['BROKER_POOL_LIMIT'] = 'None'
app = Celery('celiter', backend='rpc://', broker=os.environ['BROKERURL'])
app.conf.broker_heartbeat = 0
longest = 0
handchunk = 1000
taskchunk = 1000
rescollect = 10
b = grouper(bg.dealer(), handchunk)
res = []
results = []
collect = 0
try:
while True:
pbar = tqdm(total=deck.court.permutations,
unit=' hands',
ncols=140,
bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}] {rate_fmt} {postfix[0]} {postfix[1][maxturns]}',
postfix=["Max Turns:", dict(maxturns=0)])
for chunk in b:
res.append(celplay.chunks(
[(deck.court.courtmap, x) for x in chunk], taskchunk)())
collect += 1
if collect == rescollect:
for r in res:
for x in r.results:
for f in x.get():
results.append(f)
chunkmax = max([t[0] for t in results])
if chunkmax > longest:
longest = chunkmax
pbar.postfix[1]['maxturns'] = longest
res = []
collect = 0
pbar.update(taskchunk*rescollect)
for r in res:
for x in r.results:
for f in x.get():
results.append(f)
chunkmax = max([t[0] for t in results])
if chunkmax > longest:
longest = chunkmax
pbar.postfix[1]['maxturns'] = longest
res = []
pbar.update(len(res))
break
except StopIteration:
for r in res:
for x in r.results:
for f in x.get():
results.append(f)
print("Games: {}, Max Turns: {}".format(
len(results), max([t[0] for t in results])))
except KeyboardInterrupt:
for r in res:
r.forget()
# pbar = tqdm(total=deck.court.permutations, unit='Games', ncols=140,
# bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}] {rate_fmt} {postfix[0]} {postfix[1][maxturns]}', postfix=["Max Turns:", dict(maxturns=0)])
# try:
# while True:
# res = celplay.delay(deck.court.courtmap, bg.deal())
# (turns, tricks, starts) = res.get()
# if turns > longest:
# longest = turns
# pbar.postfix[1]['maxturns'] = longest
# # print (turns, tricks, starts)
# pbar.update()
# except StopIteration:
# pbar.update()
# print(longest)