-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardtrick.py
More file actions
78 lines (67 loc) · 1.86 KB
/
cardtrick.py
File metadata and controls
78 lines (67 loc) · 1.86 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
# -*- coding: utf-8 -*-
from __future__ import print_function
from random import shuffle
fids = range(13)
colors = ["♠","♥","♦","♣"]
jokers = ["JB","JR"]
trycnt = 0
trymax = 4
pnum = int(3)
def deckgen():
deck = []
for color in colors:
for fid in fids:
try:
crd = str(int(hex(fid)[2:])+1)+color
except:
crd = str(hex(fid)[2:])+color
deck.append(crd)
return (deck + jokers)[:-3]
def showpils(pls,ui=False):
for i in range(len(pls[0])):
for j in range(len(pls)):
try:
print(pls[j][i], end='\t')#, flush=True)
except: pass
print('\n', end='')#, flush=True)
if ui:
if [len(a) for a in pls][1:]==[len(a) for a in pls][:-1] and len(pls)%2 == 1:
pilui(pls,len(pls))
else:
raise "DAFUCK"
else:
return pls
def exactck(deck,div):
return len(deck)/float(div) == len(deck)/div
def pilgen(deck,div,exact=False):
if exact and not(exactck(deck,div)):
raise "Bwaaaaaaaaaaa"
pils = []
for _ in range(div):
pils.append([])
for i in range(len(deck)):
pils[i % div].append(deck[i])
return pils
def pilui(pl,nbr):
try:
global trycnt
global deck
deck=[]
pilid = int(input("Dans quelle pille est votre carte? ")) - (nbr/2)
for i in range(nbr):
j=int((pilid+i) % nbr)
deck += pl[j]
trycnt += 1
except:
print("Entrez un nombre bordel")
deck = deckgen()
print("Choisisez une carte (Sans le dire à l'ordi)")
showpils(pilgen(deck,5))
input("Press Enter to continue...")
shuffle(deck)
while trycnt < trymax:
showpils(pilgen(deck,pnum,True),True)
i=int(pnum/2)
j=int((len(deck)/pnum)/2)
print(pilgen(deck,pnum,True)[i][j],"est votre carte")
input("Press Enter to close...")