Assignment 1 - Lecture notes 3 PDF

Title Assignment 1 - Lecture notes 3
Course Key Concepts in Computer Science
Institution University of Windsor
Pages 5
File Size 339.5 KB
File Type PDF
Total Downloads 103
Total Views 158

Summary

Assignments...


Description

(COMP-1400 Winter 2020) Assignment #1 (Due End of Friday, January 31, 2020)

OBJECTIVE: Through three to four assignments, we will learn how to apply the concepts learned in this course to develop a game (i.e., a simple, and text-based version of the Mastermind game) using programming language C. In the first assignment, we are going to kick off the first step of developing the game. How? Yes, first write informal pseudocode for the game and then convert it to a flowchart. We will also prepare the skeleton of the C program for the game, and then in the following assignments, we will gradually complete the program step by step, based on what we learn in class. Part A: Brief introduction to the Mastermind game:

Mastermind Game From Wikipedia (https://en.wikipedia.org/wiki/Mastermind_(board_game)) Mastermind or Master Mind is a code-breaking game for two players. The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. The game is played using: • a decoding board, with a shield at one end covering a row of four large holes, and twelve (or ten, or eight, or six) additional rows containing four large holes next to a set of four small holes; • code pegs of six different colors (or more; see Variations below), with round heads, which will be placed in the large holes on the board; and • key pegs, some colored black, some white, which are flat-headed and smaller than the code pegs; they will be placed in the small holes on the board. One player becomes the codemaker, the other the codebreaker. The codemaker chooses a pattern of four code pegs. In this version, we assume that duplicates and blanks are not. The chosen pattern is placed in the four holes covered by the shield, visible to the codemaker but not to the codebreaker. The codebreaker tries to guess the pattern, in both order and color, within eight to twelve turns. Each guess is made by placing a row of code pegs on the decoding board. Codebreaker can use 1

duplication for each set of guess. Once placed, the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row with the guess. A black key peg is placed for each code peg from the guess which is correct in both color and position. A white key peg indicates the existence of a correct color code peg placed in the wrong position. However, there is no relation between the order of black and white key pegs and the order of the guessed pattern. If there are duplicate colors in the guess, only the left most of them, will be considered by the codemaker to provide feedback. Once feedback is provided, another guess is made; guesses and feedback continue to alternate until either the codebreaker guesses correctly, or twelve (or ten, or eight) incorrect guesses are made. For instance, on the picture above, codemaker has selected blue, green, black and red. The first guess by the codebreaker is white, blue, yellow, and green. Therefore, the feedback includes only two white pegs, which means there are only two right colors (blue and green) but incorrect locations. After the second guess, blue, yellow, red and black, the feedback includes one black (for the blue one) and two white pegs (for the red and black ones). (* You can install the game app on your device and play with it to have some FUN and learn its simple logic and rules. *) In the simple, text-version of Mastermind game that we are going to develop, instead of colors we simply use digits 1 to 9. Therefore, codemaker (Computer) will randomly selects four unique, nonduplicated, digits and then codebreaker will start guessing the four digits. If the codebreaker guesses the correct code in less then or equal to ten guesses, s/he wins and otherwise loses. Then, the codebreaker has the opportunity to play again or just exit from the game. In each step of the game, proper message should be provided by the codemake (computer) to the codebreaker. For instance, at the beginning there would be a welcome message, followed by asking the codebreaker to guess the code. After each guess, an accurate feedback should be shown to the codebreaker. If codebreaker wins/loses, proper message showed be shown to the codebreaker as well. You can get some ideas from the sample execution of the program on page 4 of this document. Part B: Pseudocode:

(40 marks)

Using the above game rules, write the pseudocode (formal or informal) for the Mastermind game. As a hint, we start it as follows, and you should complete it: 1. 2. 3. 4. 5.

Start Show a Welcome message to the player. Generate a random code. … Complete the next steps … . . . X. Ask the player if they want to play again or not a. If yes, go to step 3 b. If no, show a Goodbye message and end the program X+1. End

Part C: Flowchart

(40 marks)

Using the pseudocode you wrote in the previous part, draw a flowchart for the Mastermind game. You can use any flowchart software, like Raptor, or simply draw it on any software with graphical capabilities, like Word, Excel, PowerPoint, Paintbrush, etc. 2

Part D: C program

(20 marks)

Based on the flowchart and pseudocode you’ve designed on the previous step, now we are going to provide the skeleton of the C program for the Mastermind game. Your task in this part is to just start writing a C program with the following parts: • Include required standard libraries • Show a welcome message to the player • Write COMMENTS for the major steps of the code based on the flowchart you have prepared. Like in any programming language, in C programs you can add comments on any part of your code. Comments are not executable but will help the reader to understand the code. Note that you don’t have to write any actual code that we haven’t learned yet in this assignment. Hint: There are two ways to have comments inside a C program: 1. In-line comment: type // and then write the comment. The rest of the line after // will be considered as comments and not the actual program code Example: #include

// C Standard Library for input/output functions

2. Multi-line comment: type /* and start writing your comment on one or more lines. At the end, finish the comments by typing */ Example: /* This program implements the Mastermind game, in which a player can play … … */

a. Save the file in the format of a C source file as Mastermind.c in your working directory, i.e., /home/yourUserName/winter2020/comp1400. b. As you are already in the working directory as completing UNIX Exercise, you can now compile the C program with the following command to produce an executable. gcc -Wall Mastermind.c -o Mastermind c. You can run the executable file with the following command. ./Mastermind To give you a clear idea, below you can see a sample execution of the Mastermind program that you would have at the end of this semester. Of course, by keeping the essential functionalities of the game, you are free to have different styles of outputs for the game. However, remember that this is a text-version of the game and programs with graphical user interface won’t be graded, as we have no GUI coverage in this course. You can include a separate graphical version of the program in your final submission if you want to.

3

4

Submission Instruction: You have to submit your solutions as A SINGLE ZIP FILE into Blackboard before the deadline. The zip file name is your student id (for instance if your id is 1234567, then the zip file name would be 1234567.zip) that includes one or two pdf files for non-programming questions, and one c file (a text file with extension c) for c programs. PLEASE DO NOT submit any other types of files, such as compiled files, files associated with specific software, etc. Therefore, for assignment 1 your zip file should contain the following files: - One pdf file for the pseudocode (part B) - One pdf file for the flowchart (Part C) (Answer to this part can be inside the first pdf file as well) - One text file, named "Mastermind.c", which should be a simple text file, containing your c program. Submission of other file types will make problems for grading your assignments and you will lose partial or complete mark. Cheers

5...


Similar Free PDFs