ENGG1110 Problem Solving by Programming (2018-2019 Term 2) Project – Concentration (A Card Game)_____________________________________________________________________________________1. IntroductionConcentration, also known as “Match Match”2, is a simple cardgame emphasizing a good memory that most of us should haveplayed in our childhood. In this game, all 52 cards (jokers excluded)will be laid face down on a surface in orderly rows and columns. A group of players will take turnsto pick two cards at a time and flip the cards to check whether they are of the same rank or not. Ifthey are of the same rank, the two cards will be removed and kept by the player. If the cards arenot of the same rank, they are turned face down again, and play passes to the next player. Thegame ends when the last pair has been picked up. The player who got the most of the cards is thewinner. It is a game to practice one’s memory as good memory can help retrieve those flippedcards which match in rank.In this project, your task is to implement the Concentration game using C language. The programsupports two modes: 1. Player vs. Computer, and 2. Computer vs. Computer.In Mode 1, the program lets the player enter the coordinates of two cards via the console. Errorchecking should be implemented to make sure the entered coordinates are valid. Then two cardswill be flipped and the matching result is shown. After that, the computer will pick randomly twocards and check whether they match or not. The above process will repeat until all cards have beenflipped face up. At that time, the total number of successfully flipped cards by both players andthe winner, if any, will be displayed.Mode 2 is similar to Mode 1 except that two computer players, i.e. computer 1 and computer 2,will be used for the whole process. This is actually a simulation. Finally, the winner will also bedisplayed as is the case of mode 1.2. Simplified Rules of the GameTo ease your code design and implementation, we have simplified the rules of the game as follows:I. Two Players Only: you can always assume that there are only two players (whether humanor computer) playing this game though in reality the game can support more than two players.II. Matching Ranks Only: Some game rules require the matched pair to be in the same color(e.g. six of hearts ? = six of diamonds¨, queen of clubs § = queen of spades a) besides ofthe same rank. For simplicity, we won’t consider color matching but rank matching only.III. One Flip: The original game rules may reward the player who succeeds in matching a pairwith one more turn to flip cards and continue until hitting a mismatch. To make the controlflow simpler, this rewarding scheme is removed. After a player finishes flipping of two cards,no matter if they match or not, it will be the another player’s turn to flip cards. 1 Image source: https://s.hswstatic.com/gif/how-to-play-concentration-1.jpg.jpg 2 https://en.wikipedia.org/wiki/Concentration_(game)123. RequirementsYou are required to use the following techniques in this project:I. Structures in C to represent a card,II. Random number generator to construct moves from a computer playerImportant: Failure to apply both the above techniques will result in mark deduction.The desktop surface should be shown as a 4 by 13 rectangular array as follows. Note that the cardsare initially represented as “XXX” (card face down; value hidden).When the game reaches the end, it may look like this picture:All cards have been flipped face up, showing each card’s rank and suit. Note the following schemefor representing the rank and suit of each card in the above display:Rank Shown asAce A2 - 10 2 - 10Jack JQueen QKing KSuit Shown asClub § CDiamond ¨ DSpade a SHeart HOther detailed requirements on the display and the game logic will be covered in later sections.4. Detailed Requirements SpecificationYour program should perform the following tasks.I. Display the program menuYour program should print the following main menu for this game to the screen:****************************** Welcome to Concentration! ******************************Please choose a mode of the game:1. Human vs. Computer2. Computer vs. Computer0. QuitYour choice:The user will choose whether he or she wants to play with the computer or just sees thesimulation of the game between two computer players.3Important note:You may assume that the user will only enter a single integer but input validation againstvalid choices is still required here. Your program should keep looping to display this menuand prompt the user for input until a valid menu choice (i.e. 1 or 2 or 0) is entered.II. Human vs. Computer Mode (II-VI)If menu option 1 is chosen, the program should display the deck of cards and let the playerinput the coordinates of the first card and then the second card being flipped.****************************** Welcome to Concentration! ******************************Please choose a mode of the game:1. Human vs. Computer2. Computer vs. Computer0. QuitYour choice: 1XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXPlease input 1st card:III. The player should then input the coordinates.XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXPlease input 1st card: 0 1You chose 1st card (0, 1) and it is D 8Please input 2nd card: 2 2You chose 2nd card (2, 2) and it is D QThe program prompts for the row index (0-3) and column index (1-13) of the first card beingpicked. It echoes the input and reveals the selected card’s suit and rank. It does the same forthe second card being picked.Error checking should be done to prevent the following conditions:1. Invalid coordinatesEnsure that the input row and column indexes are within 0 - 3 and 1 - 13 respectively(special: we start from 1 instead of 0 for column). If it is not the case, the program shouldprompt the user to enter again. A screenshot of an invalid case is shown as follows:Please input 1st card: 0 18Row and column must be within 0 - 3 and 1 - 13Please input 1st card:Note: For simplicity, you may assume that the user always enters two integers (no nondigitcharacters or floating-point numbers). So, your validation is just to check the inputagainst the specified valid range of integer values for the coordinates.42. The chosen card must not have been flipped before.For example, in the following snapshot of the game, the two cards located at coordinates(1, 2) and (3, 4) have been flipped face up. They cannot be chosen anymore. If the humanplayer chooses either of them, the error message “The card must not be flipped already”should be displayed.XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX D 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX(Some output is skipped here for ease of discussion.)Please input 1st card: 1 2The card must not be flipped alreadyPlease input 1st card:3. The second card must not be the same as the firstIf the human player enters the same coordinates for both the first and second cards beingpicked, the program should show an error message “The second card cannot be the sameas first” and prompt for the input of the second card again.Please input 1st card: 0 12You chose 1st card (0,12) and it is H KPlease input second card: 0 12The second card cannot be the same as firstPlease input second card:Note: The computer player picks cards by generating a pair of random integers withinthe valid row and column bounds. If it encounters an already flipped card or the secondcard being same as the first, it will automatically drop the selection and generate a newchoice until it is valid. So, we won’t show all these error messages for a computer’s turn.IV. The result of the human player should be displayed. The screenshot below shows that if theplayer successfully removed two cards from the desktop, the face values of the removedcards will be kept displayed at their original positions till the end of the game.Please input 1st card: 1 2You chose 1st card (1, 2) and it is H 6Please input 2nd card: 3 4You chose 2nd card (3, 4) and it is D 6You got a matched pair!XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX D 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX(Recall from Section 2 that the player who successfully matched a pair will NOT be rewardedone more turn to flip cards in this project. So, it is now the computer player’s turn.)5V. The computer will then make its choice for a pair of cards to flip. The choice made by thecomputer can be purely random pick (the simplest form of implementation). You may alsotake on a challenge to implement a smart one (see the appendix; note: developing a smartalgorithm for this part is NOT a mandatory requirement of this project and does not countfor extra marks. But it is a good self-learning exercise to enhance your programming skills).Based on the last example, after the human player finishes his/her flip, the computer makesits selection of two cards on the desktop. The selected cards’ positions and face values willbe printed as shown in the screenshot below. But this time, the pair does not match in rank,and the cards remain face-down (shown as “XXX”).Please input 1st card: 1 2You chose 1st card (1, 2) and it is H 6Please input 2nd card: 3 4You chose 2nd card (3, 4) and it is D 6You got a matched pair!XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX D 6 XXX XXX XXX XXX XXX XXX XXX XXX XXXComputer chose 1st card (0, 2) and it is H JComputer chose 2nd card (0, 8) and it is C 2XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX D 6 XXX XXX XXX XXX XXX XXX XXX XXX XXXFlipped cards: 2; You: 2; Computer: 0;Please input 1st card:Now, both players have finished one turn each. The state of the game, mainly the statisticsof flipped cards (i.e. cards facing up) made by the human (You) and the machine (Computer),will be updated and shown accordingly. In this example, the human player got two cardsmatched. So the counts next to “Flipped cards” and “You” are both incremented by 2.The game continues with the human and machine players taking turns to flip pairs. Below isa later snapshot of the game in which the computer player successfully matched a pair. Theflipped card statistics is updated each time a matched pair is made.XXX XXX XXX XXX D 2 XXX XXX XXX XXX XXX XXX XXX XXXH Q H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX D Q XXX D J XXX XXX S 2 D A XXX XXX S A XXX XXXD 3 XXX XXX D 6 XXX C J S 3 XXX XXX XXX XXX XXX XXXComputer chose 1st card (0, 9) and it is C10Computer chose 2nd card (3, 2) and it is D10Computer got a matched pair!XXX XXX XXX XXX D 2 XXX XXX XXX C10 XXX XXX XXX XXXH Q H 6 XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX D Q XXX D J XXX XXX S 2 D A XXX XXX S A XXX XXXD 3 D10 XXX D 6 XXX C J S 3 XXX XXX XXX XXX XXX XXXFlipped cards: 14; You: 12; Computer: 2;Please input 1st card:6VI. Successive pick by the computer and human player will continue until all cards have beenflipped. At the end, the program will show a game over message telling the total number ofturns played (one turn refers to the flipping of two cards no matter if they match or not) andeither one of the following messages: “You win!” “Computer wins!” “A tie!”to indicate whether the human player or the computer has won the game, or it is a tie. Belowis a sample screenshot near the end of a game....(Prior output is skipped here for ease of discussion.)...Computer chose 1st card (0,13) and it is H KComputer chose 2nd card (1, 4) and it is D KComputer got a matched pair!S 7 D A D Q C 2 H Q S 8 D 9 S 2 C 6 C 3 H A S 9 H KD 7 S 5 代写ENGG1110作业、代做Programming留学生作业、代写C++程序语言作业、代做C++课程设计作业 代写DaS J D K C Q XXX D10 S 3 H J C 9 S 6 C 7 H 9D 6 D 3 D 5 S 4 D 4 XXX C 5 D J C K C J S K D 2 H 2H 4 C A C 4 S10 S A H10 H 6 H 3 H 5 C10 H 7 S Q C 8Flipped cards: 50; You: 28; Computer: 22;Please input 1st card: 2 6You chose 1st card (2, 6) and it is D 8Please input 2nd card: 1 6You chose 2nd card (1, 6) and it is H 8You got a matched pair!S 7 D A D Q C 2 H Q S 8 D 9 S 2 C 6 C 3 H A S 9 H KD 7 S 5 S J D K C Q H 8 D10 S 3 H J C 9 S 6 C 7 H 9D 6 D 3 D 5 S 4 D 4 D 8 C 5 D J C K C J S K D 2 H 2H 4 C A C 4 S10 S A H10 H 6 H 3 H 5 C10 H 7 S Q C 8Flipped cards: 52; You: 30; Computer: 22;*** End of Game ***429 turns playedYou win!Please choose a mode of the game:1. Human vs. Computer2. Computer vs. Computer0. QuitVII. The program then will return to the main menu.Note: the program does not end after a game finishes. It returns to the main menu to let thehuman player decide whether to play another game. The program terminates only when themenu option 0 is entered. During the course of a game (whether in mode 1 or mode 2), thereis no special input to end the game prematurely. You may press the “Abort” button in theCode::Blocks IDE, or press Ctrl + C to terminate the running process.VIII. Computer vs. Computer ModeIf menu option 2 is chosen, the program runs in a simulation mode. Two computer playerswill pick their choices of card pairs in turns successively like in Mode 1, but with all choicesautomatically generated (without any user attention).Final desktop configurationFinal game statisticsGame over message7Note: When running in Mode 2, we want to make it run faster. So, you should skip printingthe state of the desktop but only the choices made by each player in each turn. Only the initialand final state of the desktop will be displayed. Below is an example screenshot segmentshowing the very last part of a game run.****************************** Welcome to Concentration! ******************************Please choose a mode of the game:1. Human vs. Computer2. Computer vs. Computer0. QuitYour choice: 2XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXXXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXXComputer 1 chose 1st card (0, 2) and it is H JComputer 1 chose 2nd card (0, 8) and it is C 2Computer 2 chose 1st card (1, 1) and it is H QComputer 2 chose 2nd card (2, 9) and it is S 6Flipped cards: 0; Computer 1: 0; Computer 2: 0;...(Lengthy output is skipped here for ease of discussion.)...Computer 1 chose 1st card (1, 1) and it is H QComputer 1 chose 2nd card (3, 5) and it is C QComputer 1 got a matched pair!Computer 2 chose 1st card (0, 8) and it is C 2Computer 2 chose 2nd card (2,13) and it is D KFlipped cards: 46; Computer 1: 20; Computer 2: 26;Computer 1 chose 1st card (2,13) and it is D KComputer 1 chose 2nd card (0, 5) and it is D 2Computer 2 chose 1st card (0, 7) and it is H KComputer 2 chose 2nd card (2,13) and it is D KComputer 2 got a matched pair!Flipped cards: 48; Computer 1: 20; Computer 2: 28;Computer 1 chose 1st card (0, 8) and it is C 2Computer 1 chose 2nd card (3, 9) and it is H 3Computer 2 chose 1st card (0, 8) and it is C 2Computer 2 chose 2nd card (0, 5) and it is D 2Computer 2 got a matched pair!Flipped cards: 50; Computer 1: 20; Computer 2: 30;Computer 1 chose 1st card (3, 1) and it is D 3Computer 1 chose 2nd card (3, 9) and it is H 3Computer 1 got a matched pair!D 8 H J S10 C 7 D 2 C 6 H K C 2 C10 H 5 H 2 C K D 4H Q H 6 D 7 S 9 S K H 8 S 4 S 5 D 5 S 7 S Q H 9 S 8C 5 D Q C 3 D J C 8 H A S 2 D A S 6 C A S A D 9 D KD 3 D10 C 4 D 6 C Q C J S 3 H 4 H 3 C 9 S J H10 H 7Flipped cards: 52; Computer 1: 22; Computer 2: 30;*** End of Game ***319 turns played!Computer 2 wins!Please choose a mode of the game:1. Human vs. Computer2. Computer vs. Computer0. QuitYour choice:In this example, when Computer 1picks the last matching pair, no morecards can be chosen by Computer 2from the desktop. The game is over.The program should print the finaldesktop configuration, the final gamestatistics, and the end of gamemessage telling who has won.Final desktop configurationFinal game statisticsGame over messageInitial desktop configuration85. Academic Honesty and Declaration StatementAttention is drawn to University policy and regulations on honesty in academic work, and to thedisciplinary guidelines and procedures applicable to breaches of such policy and regulations.Details may be found at https://www.cuhk.edu.hk/policy/academichonesty/.Please put the following declaration statement as the comment in the beginning of your sourcecode (source file(s) with .c extension) and fill in your information./*** ENGG1110 Problem Solving by Programming** Course Project** I declare that the project here submitted is original* except for source material explicitly acknowledged,* and that the same or closely related material has not been* previously submitted for another course.* I also acknowledge that I am aware of University policy and* regulations on honesty in academic work, and of the disciplinary* guidelines and procedures applicable to breaches of such* policy and regulations, as contained in the website.** University Guideline on Academic Honesty:* https://www.cuhk.edu.hk/policy/academichonesty/** Student Name : * Student ID : * Class/Section : * Date : */6. Testing PlatformYour submission will be graded by using the Code::Blocks IDE on Windows. Please note thatthere may be some problems in opening a project on Windows if the project is created in otheroperating systems, such as MacOS and Linux. Therefore, make sure that your project is created ona Windows platform.7. SubmissionThe deadline of the project submission is Apr 15 (Mon) 23:59. Please follow the following stepsto submit your work.a. Compress your whole Code::Blocks project folder into a file in ZIP format named as:ENGG1110_.zip (e.g. ENGG1110G_1155012345.zip)b. Visit Blackboard for CUHK and log in with your OnePass (CWEM) password.c. Visit the page for ENGG1110 and go to Project / Project Submission.d. Upload and submit your file prepared in Step a.e. Download your submission from Blackboard to see if it can be extracted and then opened byCode::Blocks on Windows successfully.9Resubmissions are allowed. But only the latest one will be graded. 10% of the project marks willbe deducted for late submissions within one week, i.e., by Apr 22 (Mon) 23:59. Late submissionsmore than one week will not be graded.Reminder: Double-checking by step e is an important step that you can’t afford missing. We won’t(be able to) grade submissions that cannot be opened successfully on our systems. In any disputablecase, we stick to the built-in zip file extractor on Windows 10 as the reference for judgment. Pleasealso note that submissions in other archive formats like .rar or .7z will not be accepted, and requeststo resubmit and override a wrong/corrupted file after the hard deadline will not be entertained.8. Project Demo and PresentationThe project demo and presentation is scheduled on Apr 17 (Wed) in the lesson. It is conducted inEnglish. Each student will need to:1. Compile and execute the program on a lab computer using Code::Blocks on Windows.2. Explain the code and the program designThis part contributes 10% of the project marks. Marks for this part will only be given during theproject demo and presentation. A student who is absent on that day will get 0 marks for this part.Therefore, even if your project is incomplete or if you plan to submit the project late, you shouldstill come and try to get some marks.109. ScheduleTo help you with the development, we split the development process into the following stages.Week Date (Wed) Tasks10 Mar 20 Structure definition for cards Display the whole deck of cards Shuffling of cards using a random number generatorBy the end of this week, your program should be able to: Display the whole deck of cards as a rectangular array Shuffle the deck of cards and display them11 Mar 27 User input of coordinates Error checking for input Computer pick generationBy the end of this week, your program should be able to: Play through a complete mode 1 game Display the winner12 Apr 10 Mode 2 logic (computer vs. computer)By the end of this week, your program should be able to: Perform all functions of mode 1 and mode 213 Apr 15 Project submission (by 23:59 on Blackboard)Apr 17 Project Demo and Presentation (in class)10. Some Hints and RecommendationI. Your source code should be properly indented and formatted with consistent styles. They areimportant to make your program readable and easier to trace and debug.II. Effective use of functions can help modularize your program, saving a lot of redundant codein this project. For example, Mode 1 and Mode 2 are pretty similar except for the way we getthe choices (from the standard input stream vs. from a random number generator) and for theway we show the output (Mode 2 skipped printing the state of the desktop). Think about howto make good of functions for better code reuse. Good use of functions could also reduce thecomplexity or level of some deeply nested loops. 11Appendix – Optional Features (Self-Study)Revisiting Section 4 point V, apart from purely random pick, you may also take on an optionalchallenge to implement some artificial intelligence (AI) for the computer player to make smarterpick of cards. We recommend that you may attempt this advanced part only when you havefinished the baseline version using simply random pick.The kind of AI needed for this game is relatively simple; things as complex as machine learningare supposed not involved. The basic idea is to add some array for recording those cards that wereonce turned over (whether flipped by the human player or a machine). As we represent a card as aC structure, the positions and face values of the cards can be found by reading the array elements.When it is the computer’s turn to flip cards, instead of random pick, it tries to look up from thisarray for a matching pair. This array storage mimics the memory of a human being. Each machineplayer should have its own copy of this array. The size of this array denotes the memory power ofthe player, say using an array of 10 elements can only “memorize” the information of 10 cards(still facing down) on the desktop. You may control the “smartness” or “memory power” of eachmachine player by tuning its own array’s size.As you may also notice, one good strategy to use with Concentration is not to always turn over thecard you are sure of first. For example, if you know exactly where one Ace of Hearts is, but arenot 100% sure where another Ace is located, you will turn over the “uncertain card” first. Thisway if your guess goes wrong, you can then pick a random card and have a chance of getting amatch. A smart algorithm using the abovementioned array could also implement this strategy.Instead of picking a card that has been recorded in the array, the machine should pick an unknownone from the desktop for the first card. If its rank can match with any of the memorized cards (inthe array), then this is a successful move. Otherwise, the machine should try to flip a new unknownto maximize the chance of memorizing new cards by saving them in the array (until the array isalready full).One more reminder is that you should remember to update players’ arrays according to the latestchanges of the desktop. Say, if the current player’s array has stored some cards which have beenremoved from the desktop by the opponent player, then they should be also removed from thearray, freeing up storage space for new cards to be memorized.We, when assessing your work, can observe the AI by looking at the number of turns (in otherwords, the length of output in the console) required to reach the end of the game in Mode 2. Workwith AI implemented should demand much fewer turns to finish a game.Another possible experiment is to verify the hypothesis that a machine player with “better memory”(bigger array) is more likely to win over one with “poorer memory” (smaller array).- END -转自:http://www.7daixie.com/2019041550452158.html