Rock, Paper, Scissors (30 points)
For the first part of this project, you will be implementing the game of Rock, Paper, Scissors. For those unfamiliar with the rules, typically the game is played with two people who use hand gestures to represent a rock (closed fist), paper (an open hand), or scissor (a vee made with your fingers.) Each person displays their choice at the same time and the winner is determined by (winner in bold):
Scissors cuts paper, paper covers rock, rock breaks scissors
Your job is to write a program where a human can play against the computer in a best-of-5 tournament. The first to win three games wins the match. Have the human player enter their choice, and then have the computer randomly pick its choice. If the two match, the game is a tie and doesn’t count. Otherwise you will add one to the score of the winner. After the match is over, you should ask the user if they would like to play again.
Welcome to Rock, Paper, Scissors
Would you like to play? yes
What is your choice? scissors
The computer chooses rock. You lose this game!
The score is now you: 0 computer: 1
- Generating random numbers in C is a two-step part. First, we need to seed the random number generator onceper program. The idiom to do this is:
- When we need random numbers, we can use the rand() function. It returns an unsigned integer between 0 and RAND_MAX. We can use modulus to reduce it to the range we need:
int value = rand() % (high – low + 1) + low;
Image Transformations (70 points)
A Bitmap Image File (typical extension: .bmp) is a container format for a big array of pixels. There are a variety of ways that BMP files can encode image data, but we will focus on one particular form and write a program that performs two simple image transformations: Inverting the image and Converting a color image to grayscale.
Inverting an image means to take each pixel (a “picture element” – basically one discrete colored point in a larger image) and produce the “opposite” color, which we will define as being the bitwise-NOT of each pixel’s color value.
Converting a color image to grayscale is precisely what it says, we will take the various colors of the image and replace them by differing intensities of the color gray.
We will be assuming Windows Bitmap files whose contents are 24-bit RGB color. This means that each pixel is represented by a 24-bit number, split into three 8-bit parts. The first part is the intensity of the color blue, the second is the intensity of the color green, and the third is the intensity of the color red, each expressed as an integer value from 0-255. (Yes, that’d actually make it BGR and not RGB, but BMP is just weird that way…)
Part 1: Why learn and use C? (25 points)
To start off this assignment, please look into the history of C, the influence it has had on other languages, and some examples of what the language is used for today and then answer the question “Why learn and use C?”. Your answer should be at least 1 paragraph.
There is no “correct” answer to this question. I think that it is an important question to reflect on though when learning any new programming language so that is why I have included it as part of this assignment.
Part 2: Defining the Problem and your Approach Towards Finding a Solution (75 points)
The following is very much a real-world example (though scaled down so that it will be possible for you to complete the assignment in the time that is left in this semester) of a problem that you could solve using C.
Given a small database of person accounts (a sqllite3 database – which is written in C itself – that will be provided to you shortly), determine which set of accounts in that database are authorized to access a resource and should therefore be sent to the appropriate destination “system” based on the roles associated with those accounts.
The database will contain person records, roles, resources (i.e. and by resource I mean something that requires a person to have a specific role in order to access it), a mapping of the roles to people, and a mapping of the roles to resources. This should be all of the information that you need in order to programmatically make the determination about which accounts are authorized. I will post an ERD detailing this prior to lab on 11/16.
Each destination “system” that I mentioned will just be a location in local memory (again, for the sake of keeping the scale manageable). When writing to these locations (and I will post more details about the what and how of this piece soon), you will need to allocate memory, write to it, and have a way to maintain it. You should not need these specific implementation details to to come up with a preliminary solution design though.
Designing a Solution
For this part of the assignment, you should not be programming anything. Instead, you should make sure that you understand the functional details of this assignment.
It should also be an opportunity for you to examine your approach to problem solving. The number one reason that I’ve seen students (and even professionals) fail to complete an assignment or task is because they did not understand what the problem was asking and the steps they needed to take in order to solve the problem. If you take the time to document and think about your design and approach, I do not think that you will find yourself in a place where you are unable to complete this assignment.
For this part of the assignment, how you present your design is up to you. A couple of options are to create a process flow diagram or to create a specification document of some kind, such as a scaled down version of a software requirements specification (SRS) document (some things that normally go into an SRS document, just aren’t applicable or aren’t worth spending too much time on because of the limited scale of this assignment. I will post some examples of some documentation that I’ve done to solve problems similar to this one.
Part 3: Writing Pseudo-code (75 points)
Once you have your preliminary design, you should then start to think about specifics of your implementation. Rather than jumping right in and writing C code though, you should first take the intermediate step of writing pseudo-code. I will expect you to turn this in.
When you move on from part 3 to part 4, do not worry about going back and updating your pseudo-code if you find that you’ve deviated from it in your actual code. The pseudo-code is just a stepping stone to help you write the actual code, so I don’t think it is necessary or useful to update it once it is done unless you find that you need to do a massive overhaul of your code and once again use the pseudo-code as your stepping stone.
Part 4: Implementing the Solution (100 points)
I am purposefully holding off on writing anything here. I will post more details here over the weekend. I really strongly recommend that you do these parts in order (at least parts 2-5), so you should not need these details until you’ve completed parts 2 and 3.