Guide language:
The phrase “Hurry up until the flowers die” is familiar. Hey, how about using Python to help you review in advance? I will not be psychologically prepared.
If it takes all my luck to meet you! Then I ask you to stay away from me. I play cards for Chinese New Year.
At the poker table, he is his own director, his own destiny is really in his hands, through playing cards, feel his real existence
Throughout the year.
Text: Python card game
The character of a card player: he often stands behind the master, nodding and smiling, learning what he wants, which shows that he is good at learning from others’ strengths.
Card player idiosyncrasies: when luck is bad, wash a hand, ang, luck comes 😏
🛒 code:
From random import sample from collections import Counter def get_pk_lst(PLS, PKS): result = [] for p in PLS: pk = sample(pks, 3) for _pk in pk: pks.remove(_pk) result.append({"name": p, "poker": Pk}) return result def calculate(_score_map, pk_lst): _score_map[x], Same_suit = len(set([PK [:2] for PK in PK_lst])) == 1 # If continuity = sorted(n_lst) == [I for I in range(min(n_lst), max(n_lst) + 1)] or set(n_lst) == {14, 2, If not same_suit and not continuity and check == 3: Return same_suit and check == 2 if same_suit == 2: w = [i for i in n_lst if n_lst.count(i) == 2][0] single = [i for i in n_lst if i ! = w][0] return w*2*2 + single, "same_suit" if same_suit and not continuity: Return sum(n_lst)*9, if continuity and not same_suit: return sum(n_lst)*81, if same_lst == 1: Return sum(n_lst)*666, if continuity and same_suit: return sum(n_lst)*999, def compare(_score_map, pk_grp): For p in pk_grp: p["score"], p["type"] = calculate(_score_map, p["poker"]) print(" open result ------") for p in pk_grp: Print (p) print(" winner is ------") best = Max (pk_grp, key=lambda x: x["score"])["name"] print(best) return pk_grp def show(_score_map, _players): List (_score_map.keys()) poker_grp = get_pk_lst(_players, pokers) return compare(_score_map, Def start_game(_score_map, _players, freq=1): type_lst = [] for I in range(freq): grp = show(_score_map, _players) type_lst = type_lst + [t["type"] for t in grp] c = Counter(type_lst) print(c) total = sum(c.values()) for item C.i in tems () : print (f "{item [0]} frequency: {item [1] / total:. 2%}") if __name__ = = "__main__ ': # for poker suit = [" spade ", "red heart", "square", "plum blossom"] num = [STR (I) for I in range (2, 11)] + [" J ", "Q", "K", "A"] score_map = {} # for s in suit: count = 2 for n in num: Score_map [f"{s}{n}"] = count count += 1 # 5 players = [f"p{I}" for I in range(1, 6)] players, freq=100000)Copy the code
The end:
【 play cards tips 】 : play cards has become everyone’s favorite entertainment, summed up a little tips to everyone, I wish you win more
Ha! Ha!
Good article to share to end here ~
Everyone like to remember a little praise, need a complete project source can be private letter I yo! Click here!