다음 카드가 무엇이든간에 손의 확률을 찾는 방법을 찾으려고합니다. 나는 다음 카드를 확인하고 확률을 얻는 방법을 모르며, 각 종류의 손마다 각각의 방법으로 모두 쓰려고 할 때 무엇을해야 할지를 알지도 못한다. 카드를 손에 들고 그 손을 잡을 확률을 찾아 내면 도움이 될 것입니다.파이썬에서 입력 파일이있는 포커 확률
텍스트 파일을 읽는 프로그램을 작성하십시오. 이름은 으로 명령 줄 매개 변수로 제공됩니다. 각 행은 현재 핸드 카드 에있는 4 장의 카드 목록을 제공합니다. 파일의 판독 후, 프로그램 화료 가 주어진다 손 우승 각 유형의 확률에서 인쇄한다
import sys
#error message
if len (sys.argv) == 1:
print "Error"
exit()
file = sys.argv[1]
#counts and arrays
#count = 0
f = open(file)
f = f.read()
hand = f.splitlines()
arraynum = 0
def deck():
deck = []
suit = ['H', 'S', 'D', 'C']
number = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
for s in suit:
for n in number:
deck.append(n+s)
return deck
def startHand(arraynum):
hand1 = str(hand[arraynum]).split(', ')
hand1.sort()
return hand1
def checkHand(deck,hand1):
for card in hand1:
for Card in deck:
if Card == card:
deck.remove(card)
return deck
def check1(deck, hand1):
count = 0
for Card in deck:
for i in hand1[0:-1]:
if i != Card:
count +=1
prob = count/48
print prob
print count
t1 = deck()
t2 = startHand(3)
t3 = checkHand(t1,t2)
t4 = check1(t2,t3)'
입력 파일이다 QS, JS, KS, 10S SOM은이 여기
('Chance of Royal Flush: ', 0.020833333333333332)
('Chance of Straight Flush: ', 0.020833333333333332)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.14583333333333334)
('Chance of Straight: ', 0.125)
('Chance of Three of a Kind: ', 0.0)
('Chance of Two Pair: ', 0.0)
('Chance of Pair: ', 0.25)
('Chance of High Card: ', 0.4375)
*************************************
('Chance of Royal Flush: ', 0.0)
('Chance of Straight Flush: ', 0.0)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.0)
('Chance of Straight: ', 0.0)
('Chance of Three of a Kind: ', 0.041666666666666664)
('Chance of Two Pair: ', 0.125)
('Chance of Pair: ', 0.8333333333333334)
('Chance of High Card: ', 0.0)
*************************************
('Chance of Royal Flush: ', 0.0)
('Chance of Straight Flush: ', 0.0)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.1875)
('Chance of Straight: ', 0.0)
('Chance of Three of a Kind: ', 0.0)
('Chance of Two Pair: ', 0.0)
('Chance of Pair: ', 0.25)
('Chance of High Card: ', 0.5625)
*************************************
에 오신 것을 환영합니다. 도움말 설명서의 게시 지침을 읽고 따르십시오. [주제] (http://stackoverflow.com/help/on-topic) 및 [묻는 방법] (http://stackoverflow.com/help/how-to-ask) 여기를 참조하십시오. StackOverflow는 코딩 또는 튜토리얼 서비스가 아닙니다. – Prune