CS 2135 (C04) Homework 2: Lists

Due: January 30 (Friday) at 11:59pm via turnin (assignment name hwk2).

Assignment Goals

To make sure you can

The Assignment

You are developing an adventure game and need to manage the various characters in the game. The game has three kinds of characters:

In addition, each character contains a picture of itself. The section on images after the exercise list provides pictures (feel free to use your own instead) and explains how to work with images in DrScheme.

Exercises

  1. Develop data definitions (with examples) for characters and lists of characters. Include in your examples:

  2. Write the template for programs over a list of characters.

  3. Write a program all-knights-alive? that consumes a list of characters and returns a boolean indicating whether all of the knights have at least one life.

  4. Write a program subst-color that takes two colors (from the image package) and a list of colors and returns a list of colors. In the returned list, all occurrences of the first color in the input list are replaced with the second color.

  5. Write a program show-characters that consumes a list of characters and returns a list of images. The returned list contains an image for each of the characters in the input list. Trolls should be shown holding the object they seek if they have that object. Wizards are shown with different color robes based on their strength (purple for strength 3, red for strength 2, and white for strength 1). Invisible wizards should not appear in the output list.

    To get the color of the wizard's robe, use the expression (list-ref (image->color-list wizard) 6000), where "wizard" is the name of the wiard picture (the 6000 assumes that you did not resize the wizard picture). On my machine, the wizard's robe was in (make-color 132 97 181).

  6. Write a program show-trolls that behaves like show-characters, but displays only the trolls. Use your existing show-characters function in your solution (call it, don't duplicate the code).

  7. Write a program destroy-phone-trolls that consumes a list of characters and returns a list of the same characters minus the trolls that are looking for cell phones.

  8. Write a program cast-spell that consumes a spell and a list of characters and returns a list of the characters with the spell applied to each one.

  9. Write a program wanton-wizardry that consumes a list of characters and casts all the spells from all the wizards in the list on all the characters in the list (returning a list of characters).

  10. Write a program make-vane-wizard that consumes a wizard and produces a wizard. The returned wizard has the same power and visibility as the original wizard, and a spell that replaces the character's picture with a picture of the original wizard (leaving all other information about the character intact).


Working with Images

See the notes on Images. The following images may be useful for this assignment:

wizard gif knight gif troll gif key gif cellphone gif

To add an image to your file within DrScheme, select the "Insert Image" option under the "Special" menu and choose the image file. You may find it cleaner to give all of the images names (using define) at the top of the file, then refer to those names in your actual code.


What to Turn In

Turn in a single file hwk2.ss (or hwk2.scm) containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.


Guidelines


Back to the Assignments page