CSci 1301: Lab 4
Due: Wednesday, October 9th at 11:59pm by e-mail
What to submit
The lab is done in groups of 2 (preferred) or 3. If you did
all three previous labs with the same person, you may not work
with them on this lab. In the beginning of
each file please
write (in comments) the names of all group members.
At the end of the lab please send me and your group
partner(s) all your Racket files as e-mail
attachments. My e-mail is elenam at
morris.umn.edu. The subject of your e-mail must be "1301
Lab 4" followed by "Final" or "Not final", depending on whether this
is a final submission or you are still working on it. If you need to
finish it, make sure to set up a time with your group partner(s) to
finish the lab.
The lab general description
In this lab you will be building upon
the chessboard
example that we
started in class. Your task is to add the functionality as listed
below. Make sure to follow these requirements:
- All functions must have signatures. This includes functions that
we wrote in class.
- Non-image functions must have
check-expect (or check-within) tests. The number of tests
depends on what the function does, but three is usually the
minimum.
- All your structures must be well-documented.
- Use comments as needed to indicate what your program is doing and
why.
- Use constants and helper functions. Avoid code repetition.
Lab task: finishing the chess example (40 points)
You need to add the following functionality to the chess example:
- Add examples of using the chess coordinates structure.
These coordinates are also known
as algebraic
notation.
- Finish the image of a chess board by adding letters and numbers to
mark columns and rows, respectively.
-
Create a world that starts off with an empty chess board scene.
- Write two functions: one to convert from the chess coordinates
(i.e. a
chess-posn
structure) to
the position (i.e. a posn
structure) of the center of
the corresponding square on the chess board, and
another one to convert a position (i.e. a posn
) on the
chess board to chess coordinates. Try to avoid writing a
multi-case cond
, use the approach that was shown in
the starting file. Make sure to test your functions well using
check-expect.
- Step-by-step, add handling of key events to the world so that one
can add an object to a square by typing the chess
coordinates as keyboard keys. For example, if I press keys "a5", the
square a,5 is
marked with a circle. Use the functions that you wrote in the
previous step to convert the letters entered to positions in the
image. Use positions computed by these functions to add a circle to
the chess board. Test this part thoroughly before moving on to
the next one.
- Add a handler for clicking (i.e. mouse button down) on a square:
when a
square is clicked, it gets marked with a circle, and its
chess coordinates are displayed on the board. It's ok at this point
that this writing doesn't go away.
- Add a structure chess-piece that has the name of the chess piece,
its chess coordinates (make sure to use chess-posn stricture
inside the chess-piece), and an image that gets displayed for that
piece. You may just use its letter as its image (after
applying
text
function), for instance you may just
display "K" for a king. You also need a color (black or
white) in this structure.
- Write a function that, given a chess board scene and a chess piece
structure, adds the piece to the board at a given position.
Expand the key
event handler so that it
handles a 4-symbol input, where the first two symbols are the chess
coordinates, the next symbol indicates the color (b for balck, w for
white), and last symbol is the chess piece:
k for king, q for queen, r for rook, b for bishop, k for knight,
and p for pawn. The corresponding chess piece is added to the world
at a given square. For instance, entering a5wb
places
a white bishop on the square a5. Use the function that you wrote in
the previous question to add the chess piece to the chess
board.
That's it for now. You don't need to actually play the game, but we
might get back to it later and add more functionality.
CSci 1301
course web site.