CS 2420-20 Homework 24
Due: Tuesday, April 24th, 2012 9:10am
Start with field.zip, which implements a game simulation
using Racket message passing.
The game simulation is just like the C version, except for one case: When a player
tries to move to a position where a second player is standing, if the second player
is involved in a contest, then the moving player is “bumped” and does not move.
In the C version, the moving player instead waits until the contest is over,
at which point it might have a chance to steal from or pass to the second player.
Fix the message-passing simulation to match the C simulation.
Here’s one possible strategy:
- In addition to the players and contests lists of serve,
keep a delays list. The lists contains requests that have been received, but that
couldn’t be answered, yet. The new delays list will need to be
passed around just like the players and contests list.
- In handle-player, instead of replying with (bump) when
an adjacent player is busy, add a record to delays. The record
should keep the request and the requesting player; do not reply to the request.
Also, remove the requesting player from players.
- At the start of serve, before accepting any new requests,
check whether an item in delays has a move that would hit a player
that is now in players. In that case, a contest for the hit player
must have completed, so call handle-player on the delayed
request — removing the request from delays and adding the requesting player
back into players.
Last update: Monday, April 16th, 2012mflatt@cs.utah.edu |