CSE 142 Homework #5:
Quiddich!  

The pumpkins you designed last time created quite a stir.   The wizards have one final challenge for you, to determine if your magic has reached the skill they hope you will achieve before the Winter Solstice Holiday: a game of quiddich.  Or more precisely,  a Quiddich training program.  A human player will control one Seeker; the computer will control the other.  Grab your broomstick and ride!

DEADLINES AND DELIVERABLES

When?

What?

Who?

Monday, November 27, 10:00pm (electronically)

The starter code, modified only with the “beginning changes

 Team decaration statement (part of the electronic turn-in)

Each and every student, whether or not you plan to work in a team.

Wednesday, November 29, in lecture

Turn-in receipt (from beginning changes, highlighted as described in the instructions)

Each and every student, whether or not you plan to work in a team.

Monday, December 4, 10:00pm (electronically)

Final version of the program

One per team (either team member can turn in)

Wednesday, December 6, in lecture

Final receipt and any remaining hardcopy materials, such as the screen snapshot and final report.

One per team (either team member can turn in.  Both names need to be on each item)

 

SummaryGetting startedFiles - Quiddich and the sample programFiguring out the programEnhancing and completing the programMinimum requirementsInternal requirements  Finalizing the projectImplementation Hints Turn in -- Grading - Partners


The major new programming feature is this homework is structs, and arrays of structs.

There are two new features to the way this project will be done.  One is that you may work with a partner, as part of a two-person team., You need to pick the partner and tell us who that is almost immediately.  The other new thing is that you will have to demonstrate your program to a TA


A summary of what you have to do for this project follows. All parts are required and will affect your course grade.

  1. Make certain small improvements (“beginning changes”) to the skeleton to show that you understand the original program and GP142.
  2. Implement and turn in your program
  3. Turn in a “screen shot” of your program in operation, showing off as many of your features as you can in a single picture.
  4. Write a short "final report" describing the outcome of your efforts

As with Homework #4, we'll encourage creativity, but there will still be specific requirements to fulfill.


GETTING STARTED

Read through all of the instructions carefully before beginning.

Find a partner to work with. 

Download and unpack the archive as usual (see below). As with HW4, the archive contains files named Gp142.c, Gp142.h, and GP142lib.h. You must not change these files (you won’t be able to turn in modified versions of them). (Macintosh users: you must download the four files below and read and follow the Macintosh instructions for making a GP142 CodeWarrior 5 project.).  The archive also contains the skeleton or starter .c file (hw5_orig.c).

Reminder: programs using GP142 cannot be compiled and linked as simply as the programs we have done up to this point. You cannot run the programs by creating a "default project workspace."  Click on the .dsw file to bring up an already-created project.  If you use the supplied .dsw file exclusively, things will be simpler. If you find the need to create your own workspace, you need to know that it is of type "Win32 application" (not "console" as in previous projects), and you have to include Gp142.c in the project as well as your own main program).  There are MSVC tips that might help if you insist on doing it yourself.

Try building and running the skeleton program.  Compare its behavior to that of the sample executable program.

QUIDDICH AND THE SAMPLE PROGRAM

The basic goal in Quiddich is to catch the Snitch.  The Snitch is a small gold ball.  Whichever team recovers the Snitch first, (usually) wins the game.  Each team, therefore, has a Seeker whose goal it is to catch the Snitch.  Each team also has a pair of Bashers, who are trying to knock the Seeker off her/his broom.  (We did mention that Quiddich is played in the air, didn’t we?  No?  Well, it is.)

Your task is to create a Quiddich training program.  A human player will control one Seeker; the computer will control the other.  Each team can also have 0, 1 or 2 Bashers flying about trying to bash the other team’s Seeker.  

Take a few moments right now and try playing the sample executable.  You will first be prompted for the number of Bashers for each team.  Enter a number in the given range and press OK.  You should now see the game window.  There is a black screen, with 2 or more broomsticks hovering near the edges.  You control the white broom (Seeker).  The enemy Seeker is the red broom.  If you are playing with Bashers, they will appear as Green (your team) or Purple (the other team) brooms.  Press the r key to begin the game.  (Hint: r stands for run.)

You control your broom’s velocity with the 2 (down), 4 (left), 6 (right) and 8 (up) buttons.  If you press 4, you will increase your velocity towards the left side of the screen.  Note that controlling your velocity is not the same is controlling your position.  Once you press 4, you will continue moving until you press 6.  The same holds true for 2 and 8.  You can even press a direction key multiple times to start moving really fast.  One last wrinkle: Whenever you hit the edge of the board, you will bounce off!

Your goal is to catch the Snitch, which is the small yellow ball that starts at the top of the game board.  The Snitch moves in a straight line for a while, then teleports to a random location.  It stays in that location for a short time then begins moving in a straight line.  You catch the Snitch if the tip of your broom ever touches the Snitch (it is possible to fly so fast that the tip of your broom jumps over the Snitch).  You need to catch the Snitch before the computer Seeker (red) does.

In the meantime, the purple Bashers will try to knock you off your broom.  If a Basher gets too close to you, your broom will appear at the center of the game board, and you will be stunned.  (Strategy hint: if you are careening about madly, consider getting bashed to reset your movement.)  You will remain stunned for a couple of moments, after which you can resume playing.  The game ends when one player (white or red) catches the Snitch.

FILES

Users of MSVC 5 or 6 will need one of the following two items:

·        Self-extracting archive for MSVC 6

·        Self-extracting archive for MSVC 5

Mac, Linux, and all others will need the raw source files:

·        hw5_orig.c

·        gp142.c

·        gp142.h

·        gp142lib.h

There are special instructions for building GP142 programs for Mac and X-Windows users.

FIGURING OUT THE PROGRAM

The skeleton you are given as a starter is called hw5_orig.c  It can do much less than the demo.  Build the project and try to figure out everything it can do, both by playing with it and by looking at the code. 

One exercise is intended to help you understand the program.

Beginning changes, highlighted.  Modify the starter program so that is behaves just as it did originally, with the following change:  First note where the ball is drawn on the screen when the original starter code runs.  Then modify the program to make the ball appear higher on the screen, about halfway between the center point and the top of the screen (and in same x position as before).

After making these changes, and no others, turn in the program.  Then, on the turn-in receipt, highlight all the changes that you made.  Use a highlighting pen, or circle the areas modified with a thick, dark, pen mark.

Minimum Requirements for the final program

Now that you’ve seen our version of Quiddich, it’s time for you to design your own.  Your program should resemble the sample, but need not mimic it in every way.  More specifically, your submission must do the following:

1.      Allow the player to select the number of Bashers for each team.

2.      Display each type of player (Seeker and Basher) distinctly.

3.      The Snitch must obey the following constraints:

·        Every animation tick there is a small chance that the Snitch will teleport (move to) a random location.

·        If the Snitch teleports, it will be stunned (unable to move) for 5 – 15 ticks.

·        If the Snitch does not teleport, it will continue moving in a straight line.

4.      The player must be able to control her/his broom’s velocity.  The player must not be allowed to control her/his position directly.  The player can have a velocity of at most 25 along any axis (in the sample, each time you press a movement key, your velocity increases by 5).

5.      The computer Seeker should always move towards the Snitch.

6.      Every Basher should always move towards their target.

7.      All computer-controlled objects can have a velocity of at most 5 along any axis.  For example, the Snitch might be moving at velocity –5 on the vertical axis, and at 0 along the horizontal axis (i.e., the Snitch is falling).

8.      When a Seeker comes into contact with the Snitch, the game is over.

9.      When a Basher comes into contact with its target, the following occur:

·        The target is moved to the center of the game board, where it is stunned for 10 – 20 ticks.  It’s a good idea to set the target’s velocity to 0 as well.

·        The Basher remains where it is, and is stunned for 15 – 25 ticks.

·        Feel free to make the bashing more dramatic.  Instead of immediately moving to the center of the game board, you could have the victim fall for 10 ticks.

10.  You must decide how to deal with the following:

·        What happens when an object tries to move off the game board?  Does it stop moving?  Does it bounce?  Does it come out the other side (ala Pacman)?

·        How does a Seeker catch the Snitch?  Possibilities include (but are not limited to): the tip of the broom touches the Snitch, any part of the broom touches the Snitch, while sufficiently close to the Snitch the player presses the letter c (for catch) on the keyboard.

How does a Basher clobber a Seeker?  This related to the previous point.  You need to decide how to determine if a Basher is close enough to a Seeker to knock her/him of the broom.

ENHANCING AND COMPLETING THE PROGRAM

For full credit, you must add some other features..  These might include:

·        New player commands (e.g., stop)

·        A maximum number of ‘lives’ for the Seekers.  Every time a Seeker is bashed, he/she/it loses a life.

·        Multiple players (one uses 2, 4, 6, 8,while the other uses w, a, s, z)

·        Etc.

Your final report should list the features which you chose to add (beyond the required features).

Finalizing the Project

Screenshot.  Once your program is finished, run it as if you were going to demo it to your TA.  Get the screen to show as many interesting features as you can.  Then, take a screen snapshot (screen capture), print this, and turn it in

Finally, write a short final report with two short sections:

            1. Briefly list the features of your program, as actually implemented.  This might be exactly the same as the planned enhancements.  Be sure to mention any features that would not be obvious to a user running your program for the first time.

            2. Briefly mention any problems you know of: things that don’t work, cases where the program blows up, etc.  This applies to the required features as well as to any additional ones.

This report should be on a separate piece of paper, either word processed or handwritten very legibly.  Be sure your name, section, and ID are on it.

All pages that are turned in with the receipt should be stapled to the back of the receipt.

Internal and structural requirements

1. You must use arrays of structs to manage the multiple objects (players, the snitch, etc).  Even if you figure out a way to avoid using arrays, don't – that would lead to major loss of points.  

2. GP142 has two versions of most functions: one with XY in the name, that takes points as two (x,y) values, and one with P in the name that takes points as a GP142_point struct (for example, GP142_rectangleYX, which has six parameters, and GP142_rectangleP, which has four).  For homework 5, use the P versions in preference to the XY versions as much as possible.  You can use an occasional XY version if it would obviously be inconvenient not to.  Use a highlighter pen to mark these places on the hardcopy receipt of your final program.

3. As always, you must follow previously discussed style guidelines, including no global variables (the temptation to use them in this assignment may become very great!  Resist the temptation.)

This time you have much more freedom about how your program is structured, that is, how it is broken into functions. The skeleton program already has many functions. You can change these any way you like, but... not all ways are equally good, and you might get graded down for poor choices. Likewise, anything new that you add should follow the guidelines for style and structure that we have talked about throughout the course.

Implementation Hints

Here's a hint about the requirement for using structs (and arrays of structs) for the objects.  Note that every movable object in the game has several properties in common: They all have a position.  They all have a velocity.  They can all be stunned (rendered immobile) for a variable number of ticks.  Determine what sort of data structure can hold multiple complex values.  You will need to defend your choice.

The starter code we gave you causes a circle to teleport around on the screen.  This demonstrates two important concepts: the random-number generator, and animation.  

A random-number generator is a function that returns a different value every time it is called.  The caller has no way of knowing what value will be returned by the random-number generator, except that it will be at least some minimum value and at most some maximum value.  You are only responsible for using this function, not understanding it.  

Animation is handled using a periodic event.  Roughly 10 to 20 times a second, GP142 will produce a “periodic event.”  The event, also called a tick (like a clock), is no different from any other event (e.g., a mouse event) except that it produces no information.  By writing code to handle the tick, you can create the illusion of movement.

Programs that contain arrays and pointers can often be hard to debug.  The most common source of problems are arrays referenced out of bounds, and pointer that don't point where you think they do.  Being "defensive" in your programming (e.g., checking array subscripts) can help.  There is a tool that can help, too: the MSVC debugger (most C++ environments provide such a facility, too).  With the debugger, you can stop the program in mid-execution to examine the values of variables.  We have some debugger information you can read, and there is also an on-line video tutorial. 

Turn In

When you are finished, use the part A turn-in or the  part B turn-in (as appropriate) to give us your modified program. Reminder: You will not be able to turn in the Gp142 files, so don't modify them.

Face-to-Face Grading

Grading will be done face-to-face with your TA during the last week of classes.  You will make an appointment to meet the TA for this event.  We'll have more information later about where and when this will be done.  Both partners must be present at the scheduled appointment or the project will not be graded.  Both partners will be expected to understand all of the code and be able to answer questions about it. Grading will be done from the code that you have turned in, as compiled by us in Release configuration.

Working with a Partner

You are encouraged to find a partner and work as a two-person team.  Working in teams is common in upper-level computer science and engineering classes.  It is also the typical pattern in the workplace.  You are not absolutely required to work with a partner, however.  Whether you do or don't, the requirements of the assignment remain the same, and the grading standards will be the same.

Whether or not you plan to work with a partner, you must fill out and turn in a partner declaration statement.  Each and every student must do this:

After the partner declaration is turned in, you can't change your mind later.  You can't declare you are going to work alone, and then later decide to join up with a partner; or the reverse.

Because of the Thanksgiving holiday, you won't have a chance to talk to people in quiz section.  Use the lecture and the bulletin board to make contact.  Exchange names, sections numbers, phone numbers, and e-mail addresses.

 

This is not a project that you can begin 48 hours before the deadline and hope to finish satisfactorily on time. Get started now.

And don't forget to have fun!