<#51645#>Exercise 39.2.1<#51645#>
Develop the program <#69226#><#51647#>make-city<#51647#><#69226#>. It manages a collection of traffic
lights. The program should provide four services:
- adding a traffic light with a label (string);
- removing a traffic light by label;
- switching the state of a traffic light with some given label; and
- resetting a traffic light to red with some given label.
<#51650#>Hint:<#51650#> The first two services are provided directly; the last two are
implemented by the simulated traffic lights.
After the development of the program is completed, develop a graphical user
interface.~ Solution<#69227#><#69227#>
<#51656#>Exercise 39.2.2<#51656#>
Develop <#69228#><#51658#>make-master<#51658#><#69228#>. The program consumes nothing, creates an
instance of the color-guessing game of section~#seccolorstate#51659>, and
produces the <#69229#><#51660#>master-check<#51660#><#69229#> function as the only result. After the
player has guessed the answer, the function should simply respond with
``game over.'' A typical dialog would proceed as follows:
<#51665#>;SPMgt;<#51665#> <#51666#>(define<#51666#> <#51667#>master1<#51667#> <#51668#>(make-master))<#51668#>
<#51669#>;SPMgt;<#51669#> <#51670#>(master-check<#51670#> <#51671#>'<#51671#><#51672#>red<#51672#> <#51673#>'<#51673#><#51674#>red)<#51674#>
<#51675#>'<#51675#><#51676#>NothingCorrect<#51676#>
<#51677#>;SPMgt;<#51677#> <#51678#>(master-check<#51678#> <#51679#>'<#51679#><#51680#>black<#51680#> <#51681#>'<#51681#><#51682#>pink)<#51682#>
<#51683#>'<#51683#><#51684#>OneColorOccurs<#51684#>
<#51685#>...<#51685#>
Compare this with the first dialog in section~#seccolorstate#51689>.
Add a service to <#69230#><#51690#>make-master<#51690#><#69230#> that reveals the hidden colors. That
way a player who is tired of playing the game can find out the
answer.~ Solution<#69231#><#69231#>
<#51696#>Exercise 39.2.3<#51696#>
Develop <#69232#><#51698#>make-hangman<#51698#><#69232#>. The program consumes a list of words,
creates a hangman game using the list, and produces the
<#69233#><#51699#>hangman-guess<#51699#><#69233#> function as a result. A player would use the dialog
as follows:
<#51704#>;SPMgt;<#51704#> <#51705#>(define<#51705#> <#51706#>hangman-easy<#51706#> <#51707#>(make-hangman<#51707#> <#51708#>(list<#51708#> <#51709#>'<#51709#><#51710#>a<#51710#> <#51711#>'<#51711#><#51712#>an<#51712#> <#51713#>'<#51713#><#51714#>and<#51714#> <#51715#>'<#51715#><#51716#>able<#51716#> <#51717#>'<#51717#><#51718#>adler)))<#51718#>
<#51719#>;SPMgt;<#51719#> <#51720#>(define<#51720#> <#51721#>hangman-difficult<#51721#> <#51722#>(make-hangman<#51722#> <#51723#>(list<#51723#> <#51724#>'<#51724#><#51725#>ardvark<#51725#> <#51726#>...)))<#51726#>
<#51727#>;SPMgt;<#51727#> <#51728#>(hangman-easy<#51728#> <#51729#>'<#51729#><#51730#>a)<#51730#>
<#51731#>``You<#51731#> <#51732#>won''<#51732#>
<#51733#>;SPMgt;<#51733#> <#51734#>(hangman-difficult<#51734#> <#51735#>'<#51735#><#51736#>a)<#51736#>
<#51737#>(list<#51737#> <#51738#>'<#51738#><#51739#>head<#51739#> <#51740#>(list<#51740#> <#51741#>'<#51741#><#51742#>_<#51742#> <#51743#>'<#51743#><#51744#>_<#51744#> <#51745#>'<#51745#><#51746#>_<#51746#> <#51747#>'<#51747#><#51748#>_<#51748#> <#51749#>'<#51749#><#51750#>_<#51750#> <#51751#>'<#51751#><#51752#>_<#51752#><#51753#>))<#51753#>
<#51754#>;SPMgt;<#51754#> <#51755#>...<#51755#>
Compare this with the first dialog in section~#seccountstate#51759>.
Add a service to <#69234#><#51760#>make-master<#51760#><#69234#> that reveals the chosen word.
An optional extension is to equip the program with a graphical user
interface and a graphical view of the stick figure. Reuse existing
solutions as much as possible.~ Solution<#69235#><#69235#>
<#51766#>Exercise 39.2.4<#51766#>
Develop <#69236#><#51768#>make-player<#51768#><#69236#>. The program abstracts over the functions of
section~#secexplorestate#51769>. Using the program, we can create several
players that wander through the campus:
<#51774#>(define<#51774#> <#51775#>player1<#51775#> <#51776#>(make-player<#51776#> <#51777#>'<#51777#><#51778#>BioEngineering))<#51778#>
<#51779#>(define<#51779#> <#51780#>player2<#51780#> <#51781#>(make-player<#51781#> <#51782#>'<#51782#><#51783#>MuddBuilding))<#51783#>
<#51784#>...<#51784#>
The argument to <#69237#><#51788#>make-player<#51788#><#69237#> specifies the initial position of the
player.
Each instance should be able to produce
- a picture of the current surroundings;
- a list of the available building connections; and
- a move from one place to another through an available connection.
<#51791#>Extension<#51791#>:\ Two players may be in the same building at the same time,
but they cannot interact. Extend the game so that two players in the same
building can interact in some form.~ Solution<#69238#><#69238#>
<#51797#>Exercise 39.2.5<#51797#>
Develop the program <#69239#><#51799#>moving-pictures<#51799#><#69239#>. It consumes a position and a
picture, that is, a list of shapes as defined in
sections~#secmovecircle#51800>, and~#secmoveshape#51801>,
and~#secmovefig#51802>. (Also see~#secabsmoving#51803> for functions on
moving pictures.) It supports two services. First, it can place the shape
at a specific position. Second, it can reset the picture to the initially
given position.~ Solution<#69240#><#69240#>