Skip to content

Instantly share code, notes, and snippets.

@JellyWX
Last active June 30, 2017 13:33
Show Gist options
  • Save JellyWX/219e438f26676518b4b7e9338c6b58a7 to your computer and use it in GitHub Desktop.
Save JellyWX/219e438f26676518b4b7e9338c6b58a7 to your computer and use it in GitHub Desktop.
## card sort program ##
from random import choice
from math import floor
from time import sleep
class Card(object):
all_types = ['ace','two','three','four','five','six','seven','eight','nine','jack','queen','king']
all_classes = ['clubs','spades','diamonds','hearts']
def __init__(self,typ,clas):
self.typ = self.all_types[typ]
self.clas = self.all_classes[clas]
self.name = self.typ + ' of ' + self.clas
class CardSet(object):
def __init__(self,length=21):
self.sets = []
self.select_cards = []
self.all_cards = []
for i in range(12):
for j in range(4):
self.all_cards.append(Card(i,j))
self.select_cards = []
for _ in range(length):
card_selected = choice(self.all_cards)
self.select_cards.append(card_selected)
self.all_cards.remove(card_selected)
def break_list(self,li_no):
no = len(self.select_cards) / li_no
for _ in range(li_no):
self.sets.append([])
for i in range(len(self.select_cards)):
self.sets[floor(i/no)].append(self.select_cards[i])
def resort_lists(self,order):
new_set = []
temp_set = []
for i in order:
temp_set.append(self.sets[i])
self.sets = temp_set
temp_set = []
for _ in order:
new_set.append([])
max_ = len(self.sets) - 1
current = 0
for i in self.sets:
for j in i:
new_set[current].append(j)
current += 1
if current > max_:
current = 0
self.sets = new_set
def show_set(self):
for i in self.sets:
for j in i:
print(j.name)
print('-------------')
done = False
while not done:
cards = CardSet()
cards.break_list(3)
cards.show_set()
print('Here is your shuffled list of 21 cards. Got one in mind?')
sleep(2)
input('[press enter when you have thought of a card]')
print('Good.')
for i in range(3):
print('Tell me: which stack is it in (1-3)?')
valid = False
while not valid:
ui = input('1-3 > ')
try:
ui = int(ui)
valid = True
except ValueError:
print('Don\'t be stupid. \'' + ui + '\'... well funny...')
if valid and not -1 < ui < 4:
valid = False
print('Um... didn\'t I say 1-3? How have you come this far in life without counting?')
print('Okay. Reshuffling this shouldn\'t take a second.')
ui -= 1
order = [0,1,2]
new_order = []
order.remove(ui)
first_list = choice(order)
new_order.append(first_list)
order.remove(first_list)
new_order.append(ui)
new_order.append(order[0])
cards.resort_lists(new_order)
cards.show_set()
print('Here is your reshuffled set. Lets go again...')
print('Okay. So, by my calculations, your card should be ' + cards.sets[1][3].name)
print('Want to go again?')
again = input('y/N > ')
if again in 'yes' and again != '':
done = False
else:
done = True
print('Okay, goodbye')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment