python 扑克手Generator.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 扑克手Generator.py相关的知识,希望对你有一定的参考价值。

#Generates different requested sets of poker hands.
# 'J-D' means jack of diamonds, '4-C' means four of clubs.
# the deck is used when order matters, where the suits lists are used when order doesn't matter.

Clubs = {'A-C', '2-C', '3-C', '4-C', '5-C', '6-C', '7-C', '8-C', '9-C', '10-C', 'J-C', 'Q-C', 'K-C'}
Diamonds = {'A-D', '2-D', '3-D', '4-D', '5-D', '6-D', '7-D', '8-D', '9-D', '10-D', 'J-D', 'Q-D', 'K-D'}
Spades = {'A-S', '2-S', '3-S', '4-S', '5-S', '6-S', '7-S', '8-S', '9-S', '10-S', 'J-S', 'Q-S', 'K-S'}
Hearts = {'A-H', '2-H', '3-H', '4-H', '5-H', '6-H', '7-H', '8-H', '9-H', '10-H', 'J-H', 'Q-H', 'K-H'}
Deck = Clubs.union(Diamonds.union(Spades.union(Hearts)))

def all_5_card_hands():
	return [(v,w,x,y,z) for v in Deck for w in Deck for x in Deck for y in Deck for z in Deck if v != w and v != x and v != y and v != z and w != x and w != y and w != z and x != y and x != z and y != z]
def two_card_draws():
	return [(x,y) for x in Deck for y in Deck if x != y]
def three_card_draws():
	return [(x,y,z) for x in Deck for y in Deck for z in Deck if x != y and x != z and y != z]
def all_pairs():
	return [(x,y) for x in Deck for y in Deck if x[0] == y[0] and x[2] != y[2]]
def all_no_order_pairs():
	dc = [(x,y) for x in Clubs for y in Diamonds if x[0] == y[0]]
	ds = [(x,y) for x in Spades for y in Diamonds if x[0] == y[0]]
	dh = [(x,y) for x in Hearts for y in Diamonds if x[0] == y[0]]
	cs = [(x,y) for x in Clubs for y in Spades if x[0] == y[0]]
	ch = [(x,y) for x in Clubs for y in Spades if x[0] == y[0]]
	sh = [(x,y) for x in Spades for y in Hearts if x[0] == y[0]]
	return dc + ds + dh + cs + ch + sh
def all_no_order_3_of_a_kind():
	cdh = [(x,y,z) for x in Clubs for y in Diamonds for z in Hearts if x[0] == y[0] and x[0] == z[0] and y[0] == z[0] and x[2] != y[2] and x[2] != z[2] and y[2] != z[2]]
	cds = [(x,y,z) for x in Clubs for y in Diamonds for z in Spades if x[0] == y[0] and x[0] == z[0] and y[0] == z[0] and x[2] != y[2] and x[2] != z[2] and y[2] != z[2]]
	sdh = [(x,y,z) for x in Spades for y in Diamonds for z in Hearts if x[0] == y[0] and x[0] == z[0] and y[0] == z[0] and x[2] != y[2] and x[2] != z[2] and y[2] != z[2]]
	chs = [(x,y,z) for x in Clubs for y in Spades for z in Hearts if x[0] == y[0] and x[0] == z[0] and y[0] == z[0] and x[2] != y[2] and x[2] != z[2] and y[2] != z[2]]
	return cdh + cds + sdh + chs
	
def all_three_of_a_kind():
	return [(x,y,z) for x in Deck for y in Deck for z in Deck if x[0] == y[0] and x[0] == z[0] and y[0] == z[0] and x[2] != y[2] and x[2] != z[2] and y[2] != z[2]]
def all_four_of_a_kind():
	return [(w,x,y,z) for w in Spades for x in Hearts for y in Clubs for z in Diamonds if x[0] == y[0] and x[0] == z[0] and x[0] == w[0] and y[0] == w[0] and z[0] == w[0] and y[0] == z[0]]
def all_no_order_full_houses():
	return [(x,y) for x in all_no_order_pairs() for y in all_no_order_3_of_a_kind() if x[0] != y[0] and x[0] != y[1] and x[0] != y[2] and x[1] != y[0] and x[1] != y[1] and x[1] != y[2]]
def all_ordered_flushes_diamonds():
	d = [(v,w,x,y,z) for v in Diamonds for w in Diamonds for x in Diamonds for y in Diamonds for z in Diamonds if v != w and v != x and v != y and v != z and w != x and w != y and w != z and x != y and x != z and y != z]
	return d 




	

以上是关于python 扑克手Generator.py的主要内容,如果未能解决你的问题,请参考以下文章

Java:扑克手

使用 RegEx 获得扑克手分数

LeetCode 2347. 最好的扑克手牌

LeetCode 2347. 最好的扑克手牌

python generator.py

python pdf_generator.py