【发布时间】:2019-02-06 17:39:30
【问题描述】:
考虑长度为 7 的排序列表,其中每个条目 x 是一个数字 2
在线扑克网站会对高性能算法感兴趣,这些算法会在这种情况下获得 5 张最好的牌。
用 Python 编写不导入模块的程序是对此类算法进行原型设计的好方法。
“怪物大小”的在线扑克网站很可能不需要我们的任何帮助,但看到专为速度设计的算法会很有趣。在问题中
从 2010 年开始对此进行了检查,但许多链接已损坏。很高兴知道当今使用的最快的已知算法的状态。
问题:下面讨论的算法是否已知?是否已确定某些算法在性能方面表现出色?
我的工作
我注意到长度为 7 的列表有一个中点,并且算法可以包含“组合对称”和结构。我们在下面的代码中实现了这个逻辑。可以想象一个用汇编程序编写的闪电般的快速程序,它可以计算出GOTO 数字偏移量。
注意:我还有一个一次性排序例程,它采用任意 7 张牌来确定是顺子还是同花。但有人建议我让我的问题更加集中,所以这里不讨论。
Python 程序:
hand=[2,2,7,7,8,11,12]
hand=[2,3,4,7,7,7,11]
start_spot = 3
end_spot = 3
if hand[3] == hand[4]:
if hand[4] == hand[5]:
if hand[5] == hand[6]:
end_spot = 6
else:
end_spot = 5
else:
end_spot = 4
if hand[3] == hand[2]:
if hand[2] == hand[1]:
if hand[1] == hand[0]:
start_spot = 0
else:
start_spot = 1
else:
start_spot = 2
if end_spot - start_spot == 3:
if end_spot == 6:
Kick = hand[start_spot-1]
else:
Kick = hand[6]
best5 = [Kick,hand[start_spot],hand[start_spot+1],hand[start_spot+2],hand[start_spot+3]]
print(hand, best5, 'four of a kind')
raise SystemExit
else:
pass
def multCount(c1,c2,c3):
pc = 0
if c1 == c2: pc = pc + 1
if c2 == c3: pc = pc + 10
return pc
pc_r = multCount(hand[4],hand[5],hand[6])
pc_l = multCount(hand[2],hand[1],hand[0])
if start_spot == 3 and end_spot == 3:
if pc_l == 0 and pc_r == 0:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'no pair')
raise SystemExit
elif pc_l == 0 and pc_r == 1:
best5 = [hand[2],hand[3],hand[6],hand[4],hand[5]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 0 and pc_r == 10:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 0 and pc_r == 11:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'trips')
raise SystemExit
elif pc_l == 1 and pc_r == 0:
best5 = [hand[4],hand[5],hand[6],hand[1],hand[2]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 1 and pc_r == 1:
best5 = [hand[6],hand[1],hand[2],hand[4],hand[5]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 1 and pc_r == 10:
best5 = [hand[4],hand[1],hand[2],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 1 and pc_r == 11:
best5 = [hand[1],hand[2],hand[4],hand[5],hand[6]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 10 and pc_r == 0:
best5 = [hand[4],hand[5],hand[6],hand[0],hand[1]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 10 and pc_r == 1:
best5 = [hand[6],hand[0],hand[1],hand[4],hand[5]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 10:
best5 = [hand[4],hand[0],hand[1],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 11:
best5 = [hand[0],hand[1],hand[4],hand[5],hand[6]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11 and pc_r == 0:
best5 = [hand[5],hand[6],hand[0],hand[1],hand[2]]
print(hand, best5, 'trips')
raise SystemExit
elif pc_l == 11 and pc_r == 1:
best5 = [hand[4],hand[5],hand[0],hand[1],hand[2]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11 and pc_r == 10:
best5 = [hand[5],hand[6],hand[0],hand[1],hand[2]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11 and pc_r == 11:
best5 = [hand[1],hand[2],hand[4],hand[5],hand[6]]
print(hand, best5, 'full house')
raise SystemExit
else:
pass
if start_spot == 3 and end_spot == 4:
if pc_l == 0 and pc_r == 0:
best5 = [hand[2],hand[5],hand[6],hand[3],hand[4]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 0 and pc_r == 1:
print("ERROR 1")
pass # can't happen
raise SystemExit
elif pc_l == 0 and pc_r == 10:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 0 and pc_r == 11:
print("ERROR 2")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 0:
best5 = [hand[6],hand[1],hand[2],hand[3],hand[4]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 1 and pc_r == 1:
print("ERROR 3")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 10:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 1 and pc_r == 11:
print("ERROR 4")
pass # can't happen
raise SystemExit
elif pc_l == 10 and pc_r == 0:
best5 = [hand[6],hand[0],hand[1],hand[3],hand[4]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 1:
print("ERROR 5")
pass # can't happen
raise SystemExit
elif pc_l == 10 and pc_r == 10:
best5 = [hand[4],hand[0],hand[1],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 11:
print("ERROR 6")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 0:
best5 = [hand[3],hand[4],hand[0],hand[1],hand[2]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11 and pc_r == 1:
print("ERROR 7")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 10:
best5 = [hand[5],hand[6],hand[0],hand[1],hand[2]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11 and pc_r == 11:
print("ERROR 8")
pass # can't happen
raise SystemExit
else:
pass
if start_spot == 2 and end_spot == 3:
if pc_l == 0 and pc_r == 0:
best5 = [hand[4],hand[5],hand[6],hand[2],hand[3]]
print(hand, best5, 'one pair')
raise SystemExit
elif pc_l == 0 and pc_r == 1:
best5 = [hand[6],hand[2],hand[3],hand[4],hand[5]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 0 and pc_r == 10:
best5 = [hand[4],hand[2],hand[3],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 0 and pc_r == 11:
print("ERROR 9")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 0:
print("ERROR 10")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 1:
print("ERROR 11")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 10:
print("ERROR 12")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 11:
print("ERROR 13")
pass # can't happen
raise SystemExit
elif pc_l == 10 and pc_r == 0:
best5 = [hand[6],hand[0],hand[1],hand[2],hand[3]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 1:
best5 = [hand[6],hand[2],hand[3],hand[4],hand[5]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 10:
best5 = [hand[4],hand[2],hand[3],hand[5],hand[6]]
print(hand, best5, 'two pair')
raise SystemExit
elif pc_l == 10 and pc_r == 11:
print("ERROR 14")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 0:
print("ERROR 15")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 1:
print("ERROR 16")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 10:
print("ERROR 17")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 11:
print("ERROR 18")
pass # can't happen
raise SystemExit
else:
pass
if start_spot == 2 and end_spot == 4:
if pc_l == 0 and pc_r == 0:
best5 = [hand[5],hand[6],hand[2],hand[3],hand[4]]
print(hand, best5, 'trips')
raise SystemExit
elif pc_l == 0 and pc_r == 1:
print("ERROR 19")
pass # can't happen
raise SystemExit
elif pc_l == 0 and pc_r == 10:
best5 = [hand[5],hand[6],hand[2],hand[3],hand[4]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 0 and pc_r == 11:
print("ERROR 20")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 0:
print("ERROR 21")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 1:
print("ERROR 22")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 10:
print("ERROR 23")
pass # can't happen
raise SystemExit
elif pc_l == 1 and pc_r == 11:
print("ERROR 24")
pass # can't happen
raise SystemExit
elif pc_l == 10 and pc_r == 0:
best5 = [hand[0],hand[1],hand[2],hand[3],hand[4]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 10 and pc_r == 1:
print("ERROR 25")
pass # can't happen
raise SystemExit
elif pc_l == 10 and pc_r == 10:
best5 = [hand[5],hand[6],hand[2],hand[3],hand[4]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 10 and pc_r == 11:
print("ERROR 26")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 0:
print("ERROR 27")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 1:
print("ERROR 28")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 10:
print("ERROR 29")
pass # can't happen
raise SystemExit
elif pc_l == 11 and pc_r == 11:
print("ERROR 30")
pass # can't happen
raise SystemExit
else:
pass
if start_spot == 1 and end_spot == 3:
if pc_r == 0:
best5 = [hand[5],hand[6],hand[1],hand[2],hand[3]]
print(hand, best5, 'trips')
raise SystemExit
elif pc_r == 1:
best5 = [hand[4],hand[5],hand[1],hand[2],hand[3]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_r == 10:
best5 = [hand[5],hand[6],hand[1],hand[2],hand[3]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_r == 11:
best5 = [hand[2],hand[3],hand[4],hand[5],hand[6]]
print(hand, best5, 'full house')
raise SystemExit
else:
pass
if start_spot == 3 and end_spot == 5:
if pc_l == 0:
best5 = [hand[2],hand[6],hand[3],hand[4],hand[5]]
print(hand, best5, 'trips')
raise SystemExit
elif pc_l == 1:
best5 = [hand[1],hand[2],hand[3],hand[4],hand[5]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 10:
best5 = [hand[0],hand[1],hand[3],hand[4],hand[5]]
print(hand, best5, 'full house')
raise SystemExit
elif pc_l == 11:
best5 = [hand[1],hand[2],hand[4],hand[5],hand[6]]
print(hand, best5, 'full house')
raise SystemExit
else:
pass
print("ERROR 99")
pass # can't happen
raise SystemExit
【问题讨论】:
-
我建议对顺子、满屋子、三连子等进行一系列单独的过牌,然后看看哪一个会产生最好的结果。在按价值对卡片进行排序和/或按花色分组之后,这些检查中的大多数应该是相当简单的。
-
@tobias_k 如果您了解扑克,这当然会有所帮助,这样您就可以减少决策树。
-
请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 On topic、how to ask 和 ... the perfect question 在此处申请。 StackOverflow 不是设计、编码、研究或教程资源。但是,如果您遵循您在网上找到的任何资源,进行诚实的编码尝试并遇到问题,那么您将有一个很好的示例可以发布。
-
问题的问题是:虽然这个问题确实有点有趣,但你的努力似乎非常有限,而且问题也很广泛,需要实现例如以上所有这些检查。此外,如果这确实意味着某种代码高尔夫挑战,那么这些实际上并不是这里的主题。
-
我认为它不值得投反对票,但问题确实很广泛。你想让我为你写整个程序吗?该算法似乎您有一个想法,只是给了我们相当随意的部分?这就像你试图写一个家庭作业问题来张贴在这里。
标签: python algorithm performance poker