调试Python、Python代做、代写Python设计

COMPSCI 105 S1 - Assignment 01 Introduction Blackjack, also known as twenty-one, is a comparing card game. It can be played with one deck of 52 cards. The objective of the game is to reach a final score higher than the dealer without exceeding 21; or Let the dealer draw additional cards until their hand exceeds 21. We are going to implement this game in this assignment using Python. Warning DO NOT SUBMIT SOMEONE ELSES WORK:  The work done on this assignment must be your own work. Think carefully about any problems you come across, and try to solve them yourself before you ask anyone for help.  Under no circumstances should you take or pay for an electronic copy of someone else’s work. This will be penalized heavily.  Under no circumstances should you give a copy of your work to someone else  The Computer Science department uses copy detection tools on the files you submit. If you copy from someone else, or allow someone else to copy from you, this copying will be detected and disciplinary action will be taken.  To ensure you are not identified as cheating you should follow these points: o Always do individual assignments by yourself. o Never give another person your code. o Never put your code in a public place (e.g., forum, your web site). o Never leave your computer unattended. You are responsible for the security of your account. o Ensure you always remove your USB flash drive from the computer before you log off. Your name, UPI and other notes  All files should also include your name and ID in a comment at the beginning of the file.  All your files should be able to be compiled without requiring any editing.  All your files should include good layout structure What you are to do Download the template from Canvas. The program is incomplete. Your assignment is divided into several stages for ease of completion. Please complete the assignment in order of the stages. Section 1: PokerCard Class (3 marks) Blackjack is played with one or more standard 52-card decks, with each denomination assigned a point value. The cards 2 through 10 are worth their face value. Kings, queens, and jacks are each worth 10, and aces may be used as either 1 or 11. However, the value is eleven only at this stage. Consider the PokerCard class given below: class PokerCard: def __init__(self, item): self.card = item self.value = self.__evaluate(item) def __evaluate(self, item): #complete this COMPSCI 105 Assignment ONE Computer Science COMPSCI 105 S1 - Assignment 01 2 Complete the __evaluate method which takes a String as a parameter and evaluates the value of a card. We use a two-character string to represent a card. For example: &"2S&" means &"Two of Spades&". We have &"A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K&" for values and &"S, H, C, D&" for the suits. For example: the following code: card1 = PokerCard(2S) card2 = PokerCard(JC) card3 = PokerCard(AH) print (card1.value, card2.value, card3.value, sep=, ) prints: 2, 10, 11 Section 2: __str__(self) of class PokerCard (2 marks) Next, complete the __str__(self) method in the PokerCard class. The __str__ method returns a two-character string to represent a card. For example: the following code: card1 = PokerCard(2S) card2 = PokerCard(JC) card3 = PokerCard(AH) print (card1, card2, card3, sep=, ) prints: 2S, JC, AH Section 3: Deck Class (5 marks) The class &"Deck&" is defined for the initial deck of 52 cards. A stack ADT is used to store 52 poker cards. Consider the Deck class given as below: Complete the constructor __init__ of the Deck class to create a deck with 52 cards. For example, the following code: Gdeck = Deck() print(Gdeck.cards.size()) print(Gdeck.cards.pop()) prints: 52 KD Section 4: __str__(self) of class Deck (5 marks) Next, complete the __str__(self) method in the Deck class. The __str__ method returns a string to represent the deck. You should print all 52 cards by 4 rows and each row should contain 13 cards. For example, the following code: Gdeck = Deck() print(Gdeck) class Deck: def __init__(self): self.cards = Stack() cardlist = [AS, AH, AC, AD, 2S, 2H, 2C, 2D, 3S, 3H, 3C, 3D, 4S, 4H, 4C, 4D, 5S, 5H, 5C, 5D, 6S, 6H, 6C, 6D, 7S, 7H,7C, 7D, 8S, 8H, 8C, 8D, 9S, 9H, 9C, 9D, TS, TH, TC, TD, JS, JH, JC, JD, QS, QH, QC, QD, KS, KH, KC, KD] for i in range(52): #complete this COMPSCI 105 S1 - Assignment 01 3 prints: AS AH AC AD 2S 2H 2C 2D 3S 3H 3C 3D 4S 4H 4C 4D 5S 5H 5C 5D 6S 6H 6C 6D 7S 7H 7C 7D 8S 8H 8C 8D 9S 9H 9C 9D TS TH TC TD JS JH JC JD QS QH QC QD KS KH KC KD Section 5: ShuffleONE(self, no) of class Deck (5 marks) Shuffling is a procedure used to randomize a deck of playing cards to provide an element of chance in card games. We are going to implement a number of methods to simulate the card shuffling. Complete the shuffleONE(self, no) method in the Deck class. The shuffleONE(self, no) takes an integer as a parameter and performs a shuffling of the playing cards. At the beginning, we have the initialized Deck as below: We pop out a number (no) of cards and push them into an empty stack s1. Then we pop out the remaining cards and push them into another stack s2. For example, shuffleONE(12) is called, s1 and s2 contain the following cards: Hence, we pop out one card from s1 and push it back into Deck. We next pop out one card from s2 and push it back into Deck. Repeat these two steps until either s1 or s2 is empty. Finally, we pop out the remaining cards from either s1 or s2 and push them into Deck one by one. The result is shown as below: Section 6: ShuffleTWO(self, no) of class Deck (5 marks) Next, complete the shuffleTWO(self, no) method. The shuffleTWO(self, no) takes an integer as a parameter and performs a shuffling of the playing cards. At the beginning, we have the initialized Deck as below: We pop out a number (no) of cards and insert (en-queue) them into an empty queue q1. We pop out the remaining cards and push them into another stack s2. For example, shuffleTWO(12) is called, q1 and s2 contain the following cards: Hence, we remove (de-queue) one card from q1 and push it back into Deck. We next pop out one card from s2 and push it back into Deck. Repeat these two steps until either q1 or s2 is empty. Finally, we remove/pop out the remaining cards from either q1 or s2 and push them into Deck one by one. The result is shown as below: Section 7: ShuffleTHREE(self, no) of class Deck (5 marks) Deck: [KD AS调试Python作业、Python实验作业代做、代写留学生Python课程设计 KC AH ...... JH 3C JS 3D 4S 4H ...... TC TD] q1: [JS JH JC QS QH QC QD KS KH KC KD] #12 cards s2: [TD ...... AS] #40 cards Deck: [AS ...... KD] Deck: [JS AS JH AH ...... KC 3C KD 3D 4S 4H ...... TC TD] s1: [KD KC KH KS QD QC QH QS JC JH JS] #12 cards s2: [TD TC TH ...... AD AC AH AS] #40 cards Deck: [AS ...... KD] COMPSCI 105 S1 - Assignment 01 4 Next, complete the shuffleTHREE(self, no) method. The shuffleTHREE(self, no) takes an integer as a parameter and performs a shuffling of the playing cards. At the beginning, we have the initialized Deck as below. We pop out a number (no) of cards and insert (en-queue) them into an empty queue q1. We pop out the remaining cards and insert them into another queue q2. For example, shuffleTHREE(12) is called, q1 and q2 contain the following cards: Hence, we remove (de-queue) one card from q1 and push it back into Deck. We next remove one card from q2 and push it back into Deck. Repeat these two steps until either q1 or q2 is empty. Finally, we remove the remaining cards from either q1 or q2 and push them into Deck one by one. The result is shown as below: Simplified OR Advanced Version Note: The last two sections have been structured into two options. You can choose the simplified version (i.e. section 1, 2, 3… 7, 8 and 9) or choose the advanced version (1, 2, 3 … 7, 10 and 11). If you complete the simplified version, the maximum mark you can get is 45/50. If you complete the advanced version, the maximum mark you can get is 50/50. Section 8: Player Class (Simplified Version) (5 marks) Consider the Player class given as below: Complete the points_eval(self) method. This is a simplified version. Points should be evaluated based on the cards in the player and we always treat Ace as 11 in this section. We use a Stack to store poker cards owned by the player. You should also complete the __str__(self) method. The __str__ method returns a string representation of the cards owned by the player. For example, the following code fragment: Gdeck = Deck() P1 = Player() P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) print(P1) print(P1.points_eval()) class Player: def __init__(self): self.cards = Stack() def points_eval(self): #complete this def __str__(self): #complete this Deck: [KD TD KC TC ...... JH 8H JS 8S 7D 7C ...... AH AS] q1: [JS JH JC QS QH QC QD KS KH KC KD] #12 cards q2: [AS ...... TD] #40 cards Deck: [AS ...... KD] COMPSCI 105 S1 - Assignment 01 5 prints [KD, KC] 20 Section 9: main (5 marks) Consider the following code fragment: Two cards will be popped out from the Deck and push into the Player. The player can choose whether to play with one additional card or stop. The game will end automatically if the total points are greater than 21. &"GAME OVER!&" should be displayed then. Note: this is a simplified version. We always treat Ace as 11. For example: the above code fragment prints: [6S, QS] 16 Do you want one more card? (y/n) y [6S, QS, AD] 27 GAME OVER! Section 10: Player Class (*Advanced) (10 marks) Complete the points_eval(self) method. This is an advanced version. Points should be evaluated based on the cards in the player. Note: Ace can be counted as 11 or 1 in this section. We will always choose the better one that makes the final points become closer to 21 but not bigger than 21. You should also complete the __str__(self) method. The __str__ method returns a string representation of the cards owned by the player. For example, the following code fragment: Gdeck = Deck() Gdeck.shuffleTHREE(12) P1 = Player() P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) print(P1) print(P1.points_eval()) prints [AS, AH, AC, AD] 14 Section 11: main (*Advanced) (5 marks) endgame = False Gdeck = Deck() Gdeck.shuffleONE(35) Gdeck.shuffleTWO(29) Gdeck.shuffleTHREE(39) P1 = Player() P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) print(P1) print(P1.points_eval()) while (endgame == False): #complete the while loop COMPSCI 105 S1 - Assignment 01 6 Consider the following code fragment: Two cards will be popped out from the Deck and push into the Player. The player can choose whether to play with one additional card or stop. The game will end automatically if the total points are greater than 21. &"GAME OVER!&" should be displayed then. This is an advanced version. Ace can be counted as 11 or 1. We will always choose the better one that makes the final points become closer to 21 but not bigger than 21. Submission You may electronically submit your assignment through the Web Dropbox (https://adb.auckland.ac.nz/) at any time from the first submission date up until the final date. You can make more than one submission. However, every submission that you make replaces your previous submission. Submit ALL your files in every submission. Only your very latest submission will be marked. Please double check that you have included all the files required to run your program. No style. and completeness marks will be awarded if your program does not compile and run. You are to electronically submit ONE single file: A1.py Note: We have arranged questions and test cases for A1 in CodeRunner2. You are welcome to use them for testing purpose only. We won’t transfer any marks from CodeRunner2 to Canvas. You must submit your program (either simplified version or advanced version) to our assignment web dropbox before the due date. Marking Details Section 0: Style. and Completeness 5 marks Section 1: PokerCard Class 3 marks Section 2: : __str__(self) of class PokerCard 2 marks Section 3: Deck Class 5 marks Section 4: __str__(self) of class Deck 5 marks Section 5: ShuffleONE(self, no) of class Deck 5 marks Section 6: ShuffleTWO(self, no) of class Deck 5 marks Section 7: ShuffleTHREE(self, no) of class Deck 5 marks Total 35 marks Simplified Version Advanced Version Section 8: Player Class (5 marks) Section 10: Player Class (10marks) Section 9: main (5 marks) Section 11: main (5 marks) Total = 45 marks Total = 50 marks endgame = False Gdeck = Deck() Gdeck.shuffleTHREE(12) P1 = Player() P1.cards.push(Gdeck.cards.pop()) P1.cards.push(Gdeck.cards.pop()) print(P1) print(P1.points_eval()) while (endgame == False): #complete the while loop & 转自:http://ass.3daixie.com/2018060769869992.html

你可能感兴趣的:(调试Python、Python代做、代写Python设计)