In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will show you how to write the sample code for Python to achieve the fried golden flower game. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
Today's second work, ha, feels very interesting, but in the code, I replaced several numbers of card JMagol Q _ Q _ K _ A with 11 ~ 12 ~ 13 ~ 14 ~ 14. The main reason is that I didn't think of a simple way to compare it. I simply used numbers. I was too bad. I hope I can get some advice from the boss.
The code is as follows:
Import random # Import random number function def puke (): "" generate a deck of 52 playing cards (excluding big and small king): "list1 = ['spades', 'hearts', 'diamonds', 'clubs'] list2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 14] list3 = [] for i in list1: for j in list2: dict1 = {I: J} list3.append (dict1) return list3def func (num): "judge the type of three randomly generated cards Double the bottom points of different types of cards accordingly, in which the num parameter returns the calculated score for the player's card type. (the minimum leaflet is: 2, 11, 12, 13, 14, respectively, for: JJournal Q ~ K A): param num:: return: "user_list1 = [] # user_list2 for storing cards = [] # Digital global list4 # declaration for storing cards calls the external global variable for i in list4: user_list1.append (list (i.keys () for j in i: user_list1. Append (list (i.values ()) user_list2.append (user_list1 [1]) # adds the traversed number to user_list2 user_list2.append (user_list1 [3]) user_list2.append (user_list1 [5]) user_list2 = [int (x) for item in user_list2 for x in item] # merge list user_list2.sort () # column Table sort if user_list2 [0] = = user_list1 [1] = = user_list1 [2]: # determine whether the three numbers are the same num = user_list1 [1] [0] * 100000 + zhadan elif user_list1 [0] = = user_list1 [2] = = user_list1 [4] and user_list2 [2]-user_list2 [1] = = user_list2 [1] -\ user_list2 [0 ] = 1: # judge whether the three designs are the same and the serial number num = user_list2 [1] * 10000 + shunjin elif user_list2 [2]-user_list2 [1] = = user_list2 [1]-user_list2 [0] = 1: # determine whether the serial number num = user_list2 [1] * 1000 + shunzi elif user_list2 [0] = = user_list2 [1] or user_list2 [ 1] = user_list2 [2] or user_list2 [2] = = user_list2 [0]: # determine whether there are two identical numbers if user_list2 [0] = = user_list2 [1]: num = user_list2 [0] * 100 + duizi if user_list2 [0] = user_list2 [2]: num = user_list2 [2] * 100 + duizi if User_list2 [2] = = user_list2 [1]: num = user_list2 [1] * 100 + duizi elif user_list2 [0]! = user_list2 [1]! = user_list2 [2]: # Last possibility Single sheet num = user_list2 [2] * 10 + user_list2 [1] + danzhang return num # returns the calculated score # defines the bottom score of the player's card type zhadan = 100shunjin = 80shunzi = 60duizi = 40danzhang = 20 gamer = [] # defines a new list Number of players gamers = int (input ('Please enter the number of players (only 2-9 players):') if gamers > = 2 and gamers Shunjin > Golden Flower > Shunzi > pair > single if player1.type > player2.type: return player1 elif player1.type
< player2.type: return player2 else: # 当玩家双方手中的牌型一致时,根据赢法一一判断 if player1.type == 5 or player1.type == 4 or player1.type == 2: # 豹子、顺金、顺子 规则说明:按照比点 if self.get_max_card(player1) >Self.get_max_card (player2): return player1 else: return player2 elif player1.type = = 1: # Sub-rule description: first compare the values of the same two sheets, who is bigger and who wins If the pair is the same, compare a single repeat_rank_value1, single_rank_value1 = self.get_card_value (player1) repeat_rank_value2, single_rank_value2 = self.get_card_value (player1) if repeat_rank_value1 > repeat_rank_value2: return player1 elif repeat_rank_value1
< repeat_rank_value2: return player2 else: if single_rank_value1 >Single_rank_value2: return player1 elif single_rank_value1
< single_rank_value2: return player2 else: return None # 平局,大家手上的牌一样大 else: # 单牌,金花 规则:比较所有牌的点数大小,不区分牌色 if self.get_player_score(player1) >Self.get_player_score (player2): return player1 elif self.get_player_score (player1)
< self.get_player_score(player2): return player2 else: return None 由于不是很清楚炸金花的游戏规则,这里我们采用的是最简单的游戏规则。 牌型 豹子:三张同样大小的牌。顺金:花色相同的三张连牌。金花:三张花色相同的牌。 顺子:三张花色不全相同的连牌。 对子:三张牌中有两张同样大小的牌。单张:除以上牌型的牌。 玩法比较简单,豹子>Shunjin > Jinhua > Shunzi > pair > sheet, when the card type is inconsistent, which card shape is big and who wins; when the card shape is consistent, it is divided into three situations: first, leopard, Shunjin, Shunzi, compare the maximum value of the card in the player's hand, who has the largest face value of the card, who wins; the second is the pair, compare the face size of the pair in the player's hand, and then compare it separately if it is the same. Third, golden flowers, leaflets, compare the sum of the size of all cards in the player's hands.
In addition to the above three object classes, a dealer (charge officer) is required to preside over the shuffle and deal.
Def compare_card (card1, card2):''compare whether the two playing cards are the same: param card1:: param card2:: return: the same is returned as True, otherwise it is False''if card1.rank = = card2.rank and card1.suit = = card2.suit: return True return Falsedef dutch_official_work (poker, player1, player2):''the dealer (Holder) deals cards to two players alternately. All cards issued need to be removed from this deck: param poker: that deck of cards: param player1: player 1: param player2: player 2: return: def distribute_card (player): card = choice (poker) # player.pokers.append (Own_Poker (player.id, card.rank, card.suit) Player.set_card_score (card)) for i in range (len (poker)): if compare_card (card, poker [I]): poker.__delitem__ (I) break shuffle (poker) # shuffle for k in range (3): distribute_card (player1) distribute_card (player2) what are the advantages of return pokerPython 1. Easy to use Compared with traditional languages such as Python, Java, C# and so on, Python has less strict requirements on code format. 2. Python is open source, everyone can see the source code, and can be ported to many platforms; 3, Python object-oriented, can support process-oriented programming, but also support object-oriented programming; 4. Python is an interpretive language, programs written by Python do not need to be compiled into binary code, you can run programs directly from the source code 5. Python has powerful functions, has many modules, and can basically achieve all the common functions.
The above is the full content of how to write the sample code for Python to achieve the fried golden flower game, and more about how to write the sample code for Python to achieve the fried golden flower game can be searched for previous articles or browse the following articles to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.