Skip to content

Instantly share code, notes, and snippets.

@Hylian
Last active January 13, 2020 15:12
Show Gist options
  • Save Hylian/0c95b6c9978b1179604bee5e7b2cb11b to your computer and use it in GitHub Desktop.
Save Hylian/0c95b6c9978b1179604bee5e7b2cb11b to your computer and use it in GitHub Desktop.
my greatest creation
from itertools import *
from operator import *
convertValue, convertHouse = {'A': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'T': 10, 'J': 11, 'Q': 12, 'K': 13}, {'D': 0, 'C': 1, 'H': 2, 'S': 3}
def addcard(n, h):
if len(h) <= 1 and filter(lambda x: x[0] != 0, h) == 0: h.append((0, n))
else:
for c in h:
if c[0] == 2 and c[1][0][1] == n[1] and (convertValue[c[1][0][0]] == convertValue[n[0]]+1 or convertValue[c[1][2][0]] == convertValue[n[0]]-1):
h.append((3, c[1] + [n]))
h.remove(c)
break
elif c[0] == 1 and c[1][0][0] == convertValue[n[0]]:
h.append((4, c[1] + [n]))
h.remove(c)
break
else:
groupedruns = []
for g,k in groupby(enumerate(map(itemgetter(1), sorted(filter(lambda x: x[0] == 0 and convertValue[x[1][0]] >= convertValue[n[0]]-2 and convertValue[x[1][0]] <= convertValue[n[0]]+2, h)+[(0,n)], key=lambda x: convertValue[x[1][0]]))), lambda (i,x):i-convertValue[x[0]]): groupedruns.append(map(itemgetter(1),k))
runlist = filter(lambda x: len(x) == 3 and all(j[1] == n[1] for j in x),groupedruns)
if len(filter(lambda x: x[0] == 0 and convertValue[x[1][0]]==convertValue[n[0]], h)) >= 2:
h.append((1,map(itemgetter(1),filter(lambda x: x[0] == 0 and convertValue[x[1][0]]==convertValue[n[0]], h)[0:2])+ [n]))
for j in filter(lambda x: x[0] == 0 and convertValue[x[1][0]]==convertValue[n[0]], h)[0:2]: h.remove(j)
elif len(runlist) >= 1:
h.append((2, list(runlist[0])))
runlist[0].remove(n)
for j in runlist[0]: h.remove((0,j))
elif (len(filter(lambda x: x[0] == 0, h)) + 3 * len(filter(lambda x: x[0] == 1 or x[0] == 2, h)) + 4 * len(filter(lambda x: x[0] == 3 or x[0] == 4, h))) < 7: h.append((0,n))
if (len(filter(lambda x: x[0] == 0, h)) + 3 * len(filter(lambda x: x[0] == 1 or x[0] == 2, h)) + 4 * len(filter(lambda x: x[0] == 3 or x[0] == 4, h))) > 7: h.remove(sorted(sorted(filter(lambda x: x[0] == 0, h), key = lambda x: convertHouse[x[1][1]]), key = lambda x: convertValue[x[1][0]])[0])
h = sorted(map(lambda x: (x[0], sorted(sorted(x[1], key = lambda x: convertHouse[x[1]], reverse=True), key = lambda x: convertValue[x[0]])), filter(lambda x: x[0] != 0, h)), cmp = lambda x,y: (x[0]-y[0])*100 + (convertValue[y[1][0][0]] - convertValue[x[1][0][0]]), reverse=True) + sorted(sorted(filter(lambda x: x[0] == 0, h), key = lambda x: convertHouse[x[1][1]], reverse=True), key = lambda x: convertValue[x[1][0]], reverse=True)
return h
hand = raw_input("\nACSL Rummy - Edward Shin - Enter line in ACSL formatting (delimiter: \", \"): ").split(", ") # add convert to int from chess
for r in range(5):
h = []
for c in hand: h = addcard(c,h)
draw = raw_input("...: ").split(", ")
for c in draw:
if len(filter(lambda x: x[0] != 0, h)) >= 2: break
h = addcard(c,h)
for c in h:
if c[0] == 0: print c[1][0]+c[1][1]+' ',
else:
for a in c[1]: print a[0]+a[1]+' ',
print ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment