Bliv is the national game of the imaginary republic of Blivetia. It is played by two teams of seven players each, and involves moving an inflated ball up and down a sandy playing field with paddles.
A team scores five points (a casmot) for hitting the ball across the opposing team's goal line, four points (a riasa) if the ball crosses the opposing team's goal line while still in contact with an offensive player's paddle, and two points (a zor-patandi) if the opposing team hits or pushes the ball backwards across its own goal line. The referees can impose a one-point penalty (flagrat) against a team for certain egregious fouls.
As a game of bliv proceeds, the scorekeepers conventionally maintain a list of each team's scoring events, rather than maintaining a running point total for each team. So, near the end of a game, the scoreboard might look like this:
| Corgu Raiders | Varzi Dark Wolves |
|---|---|
| casmot | casmot |
| casmot | riasa |
| casmot | flagrat |
| riasa | casmot |
| casmot | riasa |
| zor-patandi | casmot |
| flagrat | |
| casmot | |
| flagrat |
At the end of the game, the final score for each team is computed by adding together the points for the events on the list: 5 for each casmot, 4 for each riasa, 2 for each zor-patandi, and -1 for each flagrat. If the scoring lists above are final, they show a game in which the Corgu Raiders have defeated the Varzi Dark Wolves, 29-22.
The exercise is to develop three Scheme procedures. The first,
points, should take as its argument any of the four scoring
events (each represented in Scheme by a symbol), and return the number of
points awarded for it:
> (points 'riasa)
4
The second procedure, point-total, should take a list of
scoring events and return the corresponding point total:
> (point-total (list 'casmot 'riasa 'flagrat 'casmot 'riasa 'casmot))
22
The third procedure, winner, should take two lists as
arguments, each list having as its first element a symbol identifying the
team and as its remaining elements the scoring events for that team in the
course of a game. It should return the symbol identifying the winner of
the game, or the symbol tie if the final scores are equal.
> (winner (list 'Corgu-Raiders 'casmot 'casmot 'casmot 'riasa
'casmot 'zor-patandi 'flagrat 'casmot 'flagrat)
(list 'Varzi-Dark-Wolves 'casmot 'riasa 'flagrat 'casmot
'riasa 'casmot))
Corgu-Raiders
``Developing'' a procedure involves writing out a comprehensive collection of sample calls that indicate how the procedure should deal with any valid arguments that it receives; drawing up a specification for the procedure that tells what arguments it expects, what results it delivers, what preconditions must be met for it to work correctly, and what postconditions are guaranteed to be satisfied when the procedure has finished its work; writing and documenting the procedure definition; and executing and checking the sample calls to make sure that they work as described.
The on-line document ``Submitting solutions by e-mail'' describes how to prepare and submit your work.
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~stone/courses/scheme/exercises/bliv-scoring.xhtml
created August 31, 2001
last revised September 5, 2001