You are developing an adventure game and need to manage the various characters in the game. The game has three kinds of characters:
Develop data definitions (with examples) for characters and lists of characters. Include in your examples:
a wizard whose spell gives one more life to the character if it is a knight (and otherwise leaves the character alone).
a wizard whose spell flips the picture of the character upside
down. For this, the image-package functions that convert between
images and color-lists will be helpful, as will the built-in Scheme
function reverse
, which reverses a list.
Write the template for programs over a list of characters.
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.
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.
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)
.
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).
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.
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.
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).
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).
See the notes on Images. The following images may be useful for this assignment:
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.
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.
Recall the Laws of Homework and the academic honesty policy when preparing your solutions.
Use map and filter whenever appropriate in your solutions. Solutions that match the structure of map and filter but don't use them will lose some points.
Follow the templates! We teach them to you because they help you organize your programs. Programs that don't follow the templates will lose points, so follow the templates (programs that use map and filter are obviously excepted from this rule).
Aim for reuse where possible! If a program you write for one part is useful for another part, reuse it.