import itertools
ranks = '23456789TJQKA'
deck = [r+s for r in ranks for s in 'dchs']
allholdemhands = [i for i in itertools.combinations(deck,2)]
def allcombos(hand,group):
'give all combos of a given hand for a given game'
return [i for i in group if (i[0][0] == hand[0] and i[1][0] == hand[1])
or (i[0][0] == hand[1] and i[1][0] == hand[0])]
def allbettercombos(cards,group):
'all combos as good as or better, of that type'
if cards[0] == cards[1]:
betterpairs = [i+i for i in ranks if ranks.index(i) >=
ranks.index(cards[0])]
return [allcombos(x,group) for x in betterpairs]
else:
bettercards = [cards[0]+i for i in ranks
if ranks.index(i) >= ranks.index(cards[1])
and ranks.index(i) < ranks.index(cards[0])]
return [allcombos(x,group) for x in bettercards]
def makerange(hands, group = allholdemhands):
'create a range of all hands from list of types'
handrange = []
for hand in hands:
if hand[-1] != '+':
handrange.append(allcombos(hand,group))
else:
handrange.append(allbettercombos(hand,group))
return handrange
위의 코드는 makerange 함수가 holdem 포커 핸드 또는 범위의 일부 집합을 입력하고 가능한 모든 고유 한 카드 조합의 목록을 출력하도록 허용하는 코드입니다.파이썬 - 포커 맞춤 범위 목록 출력 구조와 관련된 문제
작동하지만 출력이 목록 길이 1로 나오고 그 길이를 나타내는 카드의 조합 수와 같은 길이의 목록이되고 싶습니다.
- 아래 코드는 이 길이 38의 목록이되도록 코드를 변경하는 방법을 알려줄 수 있습니까? 각 손을 요소로 사용 하시겠습니까?
PS : makerange 대한 입력의 구문에 짧은 프라이머
makerange ([ 'AA', 'KJ +']) 것 출력 :
[[('Ad', 'Ac'), ('Ad', 'Ah'), ('Ad', 'As'), ('Ac', 'Ah'), ('Ac', 'As'), ('Ah', 'As')], [[('Td', 'Kd'), ('Td', 'Kc'), ('Td', 'Kh'), ('Td', 'Ks'), ('Tc', 'Kd'), ('Tc', 'Kc'), ('Tc', 'Kh'), ('Tc', 'Ks'), ('Th', 'Kd'), ('Th', 'Kc'), ('Th', 'Kh'), ('Th', 'Ks'), ('Ts', 'Kd'), ('Ts', 'Kc'), ('Ts', 'Kh'), ('Ts', 'Ks')], [('Jd', 'Kd'), ('Jd', 'Kc'), ('Jd', 'Kh'), ('Jd', 'Ks'), ('Jc', 'Kd'), ('Jc', 'Kc'), ('Jc', 'Kh'), ('Jc', 'Ks'), ('Jh', 'Kd'), ('Jh', 'Kc'), ('Jh', 'Kh'), ('Jh', 'Ks'), ('Js', 'Kd'), ('Js', 'Kc'), ('Js', 'Kh'), ('Js', 'Ks')], [('Qd', 'Kd'), ('Qd', 'Kc'), ('Qd', 'Kh'), ('Qd', 'Ks'), ('Qc', 'Kd'), ('Qc', 'Kc'), ('Qc', 'Kh'), ('Qc', 'Ks'), ('Qh', 'Kd'), ('Qh', 'Kc'), ('Qh', 'Kh'), ('Qh', 'Ks'), ('Qs', 'Kd'), ('Qs', 'Kc'), ('Qs', 'Kh'), ('Qs', 'Ks')]]]
이것은 모든 6 나타낸다 AA 카드를 만드는 방법과 높은 카드 K를 가지고있는 32 핸드 모두와 두 번째로 높은 J 카드를 만드는 방법.
그럼 당신은 'makerange (['AA ','KJ + '])'와 같은 함수를 호출 할 것이라고 말하고 있습니까? –
맞습니다. 정확히 맞습니다. – mariomendoza
사소한 점이지만'ranks'의 값이'deck' 정의에 사용 되더라도'ranks = '23456789TJQKA'' * after *'deck'을 정의하는 것은 이상합니다. – Iguananaut