/
uniqNvalue.py
65 lines (47 loc) · 1.25 KB
/
uniqNvalue.py
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
# takes a list of hands
# returns most valuable unique (not containing the same cards as another hand) hands
from addPoints import addPoints
from random import shuffle
def uniqNvalue(hands):
from itertools import permutations
perms = permutations(hands)
results = []
for perm in perms:
uniHands = []
for hand in perm:
alreadyThere = 0
for card in hand:
for uh in uniHands:
if card in uh:
alreadyThere = 1
if not alreadyThere:
uniHands.append(hand)
if uniHands not in results:
results.append(uniHands)
highestScore = 0
newResults = []
for res in results:
points = 0
for hand in res:
points = points + addPoints(hand)
newResults.append([points, res])
if points > highestScore:
highestScore = points
results = []
for thing in newResults:
if thing[0] == highestScore:
results.append(thing[1])
# if there's duplicate entried, this is not completely random
shuffle(results)
return results[0]
'''
hands = [ [[0, 'h'], [1, 'h'], [2, 'h'], [3, 'h']],
[[0, 'h'], [1, 'h'], [2, 'h']],
[[1, 'h'], [2, 'h'], [3, 'h']],
[[3, 'h'], [3, 's'], [3, 'd']],
[[0, 'h'], [0, 's'], [0, 'c']] ]
results = uniqNvalue(hands)
for res in results:
print (res)
print ('')
'''