Python data structures and algorithms-kitty fishing (using queues)

Source: Internet
Author: User

According to the "Aha" in the ideas to achieve this problem, but with the result is not the same, I myself with a card to try, found that my results like a little, maybe I understand the deviation.

#Kitten Fishing#calculate the number of each card on the table#Use the Defaultdict class and set the default type to int, which is the default value of 0#cardcounts = defaultdict (int)#but Deque has a corresponding method.defHenhenhaahaa (): fromCollectionsImportdeque hen= Deque ()#Hen's handHaa = Deque ()#Haa's HandTable = Deque ()#the cards on the table        #Hand ligation Initialization     forCardinch[2,4,1,2,5,6]: Hen.append (card) forCardinch[3,1,3,5,6,4]: Haa.append (card)#when two people's hands are not for snacks, the game continues    #If someone is playing the same card as a card on the table    #It takes two cards and all the cards in the middle to take them away.    #no more than two cards on the table.    #as long as the number of target cards is calculated, this can be retrieved        #Refresh the cards on the table (play cards, draw cards)    defrefreshtable (person, card): Table.append (Card)ifTable.count (Card) >=2:             whileTable.count (Card) >0:person.append (Table.pop ()) whileLen (hen)!=0 andLen (haa)! =0:#print "tab:", List (table)i = Hen.popleft ()#hen the cards first#print "Hen put", IRefreshtable (hen, i)#Hen Action#print "hen:", List (hen)        #print "tab:", List (table)j = Haa.popleft ()#Haa after the card#print "Haa put", JRefreshtable (Haa, J)#haa Action#print "Haa:", List (HAA)#print "tab:", List (table)#print "Next Turn"                            ifLen (hen)! =0:Print "Hen Win"        Print "Hen:", List (hen)Else:        Print "Haa Win"        Print "Haa:", List (HAA)Print "Ontables"    Print "Tab:", List (table)if __name__=="__main__": Henhenhaahaa ()#the results of my own hands-on simulation are not the same as in the book .    #I don't think I have a problem with my own answer.    #The result of a single-step simulation is the same.

Python data structures and algorithms-kitty fishing (using queues)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.