In [3]:
from Kniffel import *
In [4]:
giacomo = player('Jack')
In [5]:
bob = player('Bob')
In [6]:
prt = partita([giacomo,bob])
In [60]:
tiri = 0
ones,twos,threes,fours,fives,sixes,tris,poker,full,ps,gs,k=0,0,0,0,0,0,0,0,0,0,0,0
while k < 100:
tiri += 1
giacomo.tiraDadi()
a=giacomo.getValoreTiro()
if prt.checkTrisPoker(giacomo,5):
k+=1
if checkFull(a):
full += 1
if checkScala(a,5):
gs +=1
if checkScala(a):
ps +=1
if prt.checkTrisPoker(giacomo,3):
tris+=1
if prt.checkTrisPoker(giacomo,4):
poker+=1
if a.count(1)>=3:
ones+=1
elif a.count(2)>=3:
twos+=1
elif a.count(3)>=3:
threes+=1
elif a.count(4)>=3:
fours+=1
elif a.count(5)>=3:
fives+=1
elif a.count(6)>=3:
sixes+=1
print tiri
In [61]:
print ones,twos,threes,fours,fives,sixes,tris,poker,full,ps,gs,k
In [20]:
prt.checkTrisPoker(giacomo, 4)
Out[20]:
In [56]:
giacomo.tiraDadi()
In [23]:
a.sort()
In [43]:
ps=[[1,2,3,4,6],[2,3,4,5,3],[3,4,5,6,1]]
ls=[[1,2,3,4,5],[2,3,4,5,6]]
In [47]:
def f7(seq):
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
def checkScala(a,n=4):
b = f7(sorted(a))
if len(b) < n:
return False
if n==5:
for i in range(1,5):
if b[i]-b[i-1] != 1:
return False
return True
else:
fila = True
for i in range(1,4):
if b[i]-b[i-1] != 1:
fila = False
if fila:
return True
if len(b) < 5:
return False
fila = True
for i in range(2,5):
if b[i]-b[i-1] != 1:
fila = False
if fila:
return True
return False
In [45]:
for a in ps:
print a, checkScala(a)
for a in ls:
print a, checkScala(a,5)
In [49]:
def checkFull(a):
coppia = False
tris = False
for n in range(1,7):
if a.count(n) == 3:
tris = n
elif a.count(n) == 2:
coppia = n
return coppia and tris
In [ ]: