[PRL] Pac-Man's Ghost Behavior Analyzed and Fixed
Doug Orleans
dougorleans at gmail.com
Sun Dec 5 13:49:06 EST 2010
On Sat, Dec 4, 2010 at 2:51 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> I could imagine a TYPED solution if RegionOfLocations is a class that specifies exactly four locations. If the four are specified in such a way that they can only represent a straight line, all the information is in the type.
Sorry, you lost me... Why four locations? Why a straight line?
I was thinking of something along these lines:
A Location is a pair of coordinates (x,y).
A Direction is a pair of deltas (dx,dy).
You can add a Location (x,y) and a Direction (dx,dy) to get a new
Location (x+dx,y+dy).
The chosen representation for both Location and Direction is to pack
the two 8-bit numbers into one 16-bit number. This works as long as
you unpack first and do two 8-bit additions, but the bug happened when
16-bit addition was used instead:
(38,47) + (0,-1) = (38,46)
#262F + #00FF = #272E = (39,46)
So the implementation of addition broke its contract. Which I guess
isn't all that interesting.
--Doug
More information about the PRL
mailing list