The examples prepared for MOOC are simple in thinking. In order to include knowledge points, some verbose functions are used, which may not be the most concise. But they are very easy to use. The main programs of many tractors and landlords are estimated to be so complete. Later, they can be modified into interface version when they have time. They are packaged and played by themselves, plus difficulty level, plus upgrade rules
No nonsense, go straight to the code:
def main(): person=generate_person() pockers=generate_pocker() person_pockers=random_pocker(person,pockers) print_pocker(person_pockers) def generate_person(): (a,b,c,d)=([],[],[],[]) return a,b,c,d def generate_pocker(): pocker=['♣','♦','♥','♠'] # Grass, diamonds, hearts, spades point=['A','2','3','4','5','6','7','8','9','10','J','Q','K'] # Number of cards pockers=[[pocker[i],point[j]] for i in range(len(pocker)) for j in range(len(point))] # List derivation generates 52 cards return pockers def random_pocker(person,pockers): import random random.shuffle(pockers) #Shuffle the cards sep_person=[i for i in map(lambda x:x,filter(lambda x:x%4==0,range(len(pockers))))] #Each round of card grabbing corresponds to the first player index [person[j].append(pockers[j+k]) for k in sep_person for j in range(4)] #win the medal return person def print_pocker(person_pockers): for i in range(len(person_pockers)): print("The {} person: {}".format(i,person_pockers[i])) if __name__=="__main__": main()
The effect is as follows:
The 0 person: [['♠', 'J'], ['♣', '3'], ['♥', '10'], ['♠', '5'], ['♠', '9'], ['♣', 'K'], ['♦', 'K'], ['♥', '8'], ['♦', '5'], ['♠', '4'], ['♦', 'A'], ['♥', '3'], ['♣', '5']] The 1 person: [['♣', '10'], ['♥', 'K'], ['♣', '6'], ['♦', '3'], ['♦', '9'], ['♠', 'Q'], ['♥', 'A'], ['♣', '4'], ['♠', '6'], ['♣', '2'], ['♦', 'Q'], ['♥', '6'], ['♠', '10']] The 2 person: [['♥', 'Q'], ['♦', '7'], ['♥', '4'], ['♦', 'J'], ['♠', '2'], ['♥', '7'], ['♥', '9'], ['♦', '6'], ['♣', 'A'], ['♠', '7'], ['♠', '3'], ['♣', '8'], ['♥', 'J']] The 3 person: [['♦', '10'], ['♣', 'Q'], ['♠', 'K'], ['♠', '8'], ['♠', 'A'], ['♦', '8'], ['♣', 'J'], ['♦', '2'], ['♥', '2'], ['♣', '7'], ['♥', '5'], ['♦', '4'], ['♣', '9']]