# <随便写>Python实现斗地主

```‘‘‘
斗地主:v1.0
‘‘‘
import random

def creat_poker():
# 扑克9种:2-10
poker_num = [str(i) for i in range(2, 11)]
# 剩下的4种
poker_str = [‘A‘, ‘J‘, ‘Q‘, ‘K‘]
# 2个王
poker_king = [‘大王‘, ‘小王‘]
# 花色
poker_color = [‘红桃‘, ‘黑桃‘, ‘方块‘, ‘梅花‘]
# 先选择花色,在选择13种牌,最后加上大小王
pokers = [‘%s%s‘ % (i, j) for i in poker_color for j in poker_num + poker_str] + poker_king
return pokers

def poker_bottoms(pokers):
Three_bottoms = random.sample(pokers, 3)
# 4.从牌中删除3张留底
for i in range(len(pokers) - 1, -1, -1):
if pokers[i] in Three_bottoms:
del pokers[i]
return pokers, Three_bottoms

def Licensing(pokers):
person_a = pokers[::3]
person_b = pokers[1::3]
person_c = pokers[2::3]
return person_a, person_b, person_c

if __name__ == ‘__main__‘:
# 1.创建牌
pokers = creat_poker()
# 2.洗牌
random.shuffle(pokers)
print(pokers, len(pokers))
# 3.选择3张留底
pokers, Three_bottoms = poker_bottoms(pokers)
print(pokers, len(pokers), Three_bottoms)
# 4.发牌
person_a, person_b, person_c = Licensing(pokers)
print(person_a, len(person_a))
print(person_b, len(person_b))
print(person_c, len(person_c))
# 5.假设a地主
person_a = person_a + Three_bottoms
print(person_a, len(person_a))
```

```[‘黑桃4‘, ‘黑桃5‘, ‘红桃10‘, ‘梅花9‘, ‘红桃Q‘, ‘红桃3‘, ‘方块2‘, ‘梅花4‘, ‘红桃A‘, ‘黑桃Q‘, ‘红桃K‘, ‘梅花7‘, ‘红桃7‘, ‘方块7‘, ‘方块9‘, ‘黑桃6‘, ‘梅花10‘, ‘梅花A‘, ‘方块5‘, ‘黑桃2‘, ‘梅花3‘, ‘黑桃3‘, ‘梅花K‘, ‘红桃5‘, ‘小王‘, ‘黑桃9‘, ‘方块Q‘, ‘黑桃J‘, ‘黑桃7‘, ‘梅花2‘, ‘黑桃10‘, ‘黑桃A‘, ‘梅花5‘, ‘红桃2‘, ‘黑桃K‘, ‘梅花6‘, ‘红桃6‘, ‘黑桃8‘, ‘红桃J‘, ‘方块J‘, ‘方块3‘, ‘红桃9‘, ‘方块8‘, ‘红桃8‘, ‘方块4‘, ‘大王‘, ‘方块A‘, ‘方块K‘, ‘梅花J‘, ‘红桃4‘, ‘梅花8‘, ‘方块10‘, ‘梅花Q‘, ‘方块6‘] 54
[‘黑桃4‘, ‘黑桃5‘, ‘红桃10‘, ‘梅花9‘, ‘红桃Q‘, ‘红桃3‘, ‘方块2‘, ‘梅花4‘, ‘红桃A‘, ‘黑桃Q‘, ‘红桃K‘, ‘梅花7‘, ‘红桃7‘, ‘方块7‘, ‘方块9‘, ‘梅花10‘, ‘梅花A‘, ‘方块5‘, ‘黑桃2‘, ‘梅花3‘, ‘黑桃3‘, ‘梅花K‘, ‘红桃5‘, ‘小王‘, ‘黑桃9‘, ‘方块Q‘, ‘黑桃J‘, ‘黑桃7‘, ‘梅花2‘, ‘黑桃10‘, ‘黑桃A‘, ‘梅花5‘, ‘黑桃K‘, ‘梅花6‘, ‘红桃6‘, ‘黑桃8‘, ‘红桃J‘, ‘方块J‘, ‘方块3‘, ‘红桃9‘, ‘方块8‘, ‘方块4‘, ‘大王‘, ‘方块A‘, ‘方块K‘, ‘梅花J‘, ‘红桃4‘, ‘梅花8‘, ‘方块10‘, ‘梅花Q‘, ‘方块6‘] 51 [‘红桃8‘, ‘黑桃6‘, ‘红桃2‘]
[‘黑桃4‘, ‘梅花9‘, ‘方块2‘, ‘黑桃Q‘, ‘红桃7‘, ‘梅花10‘, ‘黑桃2‘, ‘梅花K‘, ‘黑桃9‘, ‘黑桃7‘, ‘黑桃A‘, ‘梅花6‘, ‘红桃J‘, ‘红桃9‘, ‘大王‘, ‘梅花J‘, ‘方块10‘] 17
[‘黑桃5‘, ‘红桃Q‘, ‘梅花4‘, ‘红桃K‘, ‘方块7‘, ‘梅花A‘, ‘梅花3‘, ‘红桃5‘, ‘方块Q‘, ‘梅花2‘, ‘梅花5‘, ‘红桃6‘, ‘方块J‘, ‘方块8‘, ‘方块A‘, ‘红桃4‘, ‘梅花Q‘] 17
[‘红桃10‘, ‘红桃3‘, ‘红桃A‘, ‘梅花7‘, ‘方块9‘, ‘方块5‘, ‘黑桃3‘, ‘小王‘, ‘黑桃J‘, ‘黑桃10‘, ‘黑桃K‘, ‘黑桃8‘, ‘方块3‘, ‘方块4‘, ‘方块K‘, ‘梅花8‘, ‘方块6‘] 17
[‘黑桃4‘, ‘梅花9‘, ‘方块2‘, ‘黑桃Q‘, ‘红桃7‘, ‘梅花10‘, ‘黑桃2‘, ‘梅花K‘, ‘黑桃9‘, ‘黑桃7‘, ‘黑桃A‘, ‘梅花6‘, ‘红桃J‘, ‘红桃9‘, ‘大王‘, ‘梅花J‘, ‘方块10‘, ‘红桃8‘, ‘黑桃6‘, ‘红桃2‘] 20
```

<随便写>Python实现斗地主

(0)
(0)