
What do we think of this, folks? http://prog21.dadgum.com/23.html (And the rest in the series, obviously.) To me, it seems that this plan would *work*... but it wouldn't be very eligant. You'd have the code to respond to user input and move PacMan in one place, the code for collision detection in other place, the code that decides what to *do* about a collision somewhere else, the code for drawing the animations in yet another place... If you wanted to change one game element, you'd have to make changes scattered all over the place. The whole thing seems messy, non-modular and non-composible to my ears. Thoughts, people?

Hi,
What do we think of this, folks?
http://prog21.dadgum.com/23.html
(And the rest in the series, obviously.)
To me, it seems that this plan would *work*... but it wouldn't be very > eligant. You'd have the code to respond to user input and move PacMan > in one place, the code for collision detection in other place, the code that decides what to *do* about a collision somewhere else, the code for drawing the animations in yet another place... If you wanted to change one game element, you'd have to make changes scattered all over the place. The whole thing seems messy, non-modular and non-composible to my ears.
Thoughts, people?
Functional Reactive Programming (FRP) tends to, in principle, work pretty well for this kind of application. At least it allows for code that is very modular in many ways, includig when it comes to the game state. See e.g. the paper "The Yampa Arcade" or the Haskell game Frag which uses FRP for the game logic: http://www.haskell.org/haskellwiki/Frag The page you referred to didn't seem to consider FRP? Don't know if FRP would address all of your concerns. But as to collisions, we can observe that this involves two or more entities and is, from the perspective of each entity, something external. Thus I don't think it's unreasonable that code handling collision detection is done "somewhere else", meaning outside the code describing the game entities themselves. As to how to respond to collisions, that can be a great deal trickier, and may involve devising suitable interfaces to allow the proper interaction of a set of object to be computed, e.g. in a physical simulation, the masses and velocities of the involved objects must be known. There was an interesting article about building a "Physics Engine" in Haskell in issue 12 of the monad reader that touched on physical collision detection and response: http://www.haskell.org/sitewiki/images/f/f0/TMR-Issue12.pdf For a game like PacMan, I should think collision response is fairly straightforward, though! Best, /Henrik -- Henrik Nilsson School of Computer Science The University of Nottingham nhn@cs.nott.ac.uk This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

Henrik Nilsson wrote:
Hi,
Thoughts, people?
Functional Reactive Programming (FRP) tends to, in principle, work pretty well for this kind of application.
So I keep hearing. Unfortunately, discovering what FRP actually *means* is more or less impossible. I can't find a precise definition of the term anywhere. There are a small handful of libraries which claim to "implement it", and their documentation generally isn't especially helpful. Too many trees for me to actually see the wood - i.e., what it's doing and why that's helpful.
The page you referred to didn't seem to consider FRP?
There's a tiny footnote at the end muttering something about "next I need to figure out how FRP fits into the picture", but that's it.
Don't know if FRP would address all of your concerns.
The guy has written a number of posts on the topic, and one of his criticisms is that "FRP is supposed to 'fix' this, but every FRP demo is bouncing balls or asteroids or something equally trivial". I don't know if he wrote that before Frag - isn't that FRP?
But as to collisions, we can observe that this involves two or more entities and is, from the perspective of each entity, something external. Thus I don't think it's unreasonable that code handling collision detection is done "somewhere else", meaning outside the code describing the game entities themselves.
A reasonably argument...
As to how to respond to collisions, that can be a great deal trickier.
Is that not always the way? ;-)

On 2008 Dec 17, at 16:39, Andrew Coppin wrote:
So I keep hearing. Unfortunately, discovering what FRP actually *means* is more or less impossible. I can't find a precise definition of the term anywhere. There are a small handful
That would be because it's still very much an open area of research and nobody's quite sure what it covers. The one-line answer would be "pure transformations of data structures based on passed-in events" --- but that's so general it describes most Haskell programs. One additional part is that it's also a function of time... but time can be just one of the events, or a separate factor. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

In the last "episode" you talk about an entity's update being a function like:
input_state -> (output_state, [event])
for some suitably defined types of input state, output state, and event. Connecting together functions with types like this is exactly what Reactive does well. You have an event stream representing the behavior of the user during the course of the game, and you use that to construct other values representing the *behavior* of the game. The key difference is that instead of the game's behavior being a set of functions from input to output, it is functions from one behavior to another, eventually culminating in something like
-- "user input", "clock tick"; output a new display list at each clock tick game :: Event UserInput -> Event () -> Reactive [RenderCommand]
In fact, I think your analysis in the first message is somewhat right
on; this exercise is somewhat like "writing a novel without using the
letter 'e'". The benefits you get from a pure language are not
necessarily "lack of effects", but rather, "explicitly mentioning
where effects happen".
That said, I'm curious where you are going with it. I'd love to see
the game running & take a look at your code!
-- ryan
On Tue, Dec 16, 2008 at 12:43 PM, Andrew Coppin
What do we think of this, folks?
http://prog21.dadgum.com/23.html
(And the rest in the series, obviously.)
To me, it seems that this plan would *work*... but it wouldn't be very eligant. You'd have the code to respond to user input and move PacMan in one place, the code for collision detection in other place, the code that decides what to *do* about a collision somewhere else, the code for drawing the animations in yet another place... If you wanted to change one game element, you'd have to make changes scattered all over the place. The whole thing seems messy, non-modular and non-composible to my ears.
Thoughts, people?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Oops, misread a bit. I thought this was your series of posts, Andrew!
But other than that, my points stand :)
-- ryan
On Wed, Dec 17, 2008 at 12:13 AM, Ryan Ingram
In the last "episode" you talk about an entity's update being a function like:
input_state -> (output_state, [event])
for some suitably defined types of input state, output state, and event.
Connecting together functions with types like this is exactly what Reactive does well. You have an event stream representing the behavior of the user during the course of the game, and you use that to construct other values representing the *behavior* of the game. The key difference is that instead of the game's behavior being a set of functions from input to output, it is functions from one behavior to another, eventually culminating in something like
-- "user input", "clock tick"; output a new display list at each clock tick game :: Event UserInput -> Event () -> Reactive [RenderCommand]
In fact, I think your analysis in the first message is somewhat right on; this exercise is somewhat like "writing a novel without using the letter 'e'". The benefits you get from a pure language are not necessarily "lack of effects", but rather, "explicitly mentioning where effects happen".
That said, I'm curious where you are going with it. I'd love to see the game running & take a look at your code!
-- ryan
On Tue, Dec 16, 2008 at 12:43 PM, Andrew Coppin
wrote: What do we think of this, folks?
http://prog21.dadgum.com/23.html
(And the rest in the series, obviously.)
To me, it seems that this plan would *work*... but it wouldn't be very eligant. You'd have the code to respond to user input and move PacMan in one place, the code for collision detection in other place, the code that decides what to *do* about a collision somewhere else, the code for drawing the animations in yet another place... If you wanted to change one game element, you'd have to make changes scattered all over the place. The whole thing seems messy, non-modular and non-composible to my ears.
Thoughts, people?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Ryan Ingram wrote:
Oops, misread a bit. I thought this was your series of posts, Andrew! But other than that, my points stand :)
Don't you just *hate* it when you reply, and then later realise you missed some small but important detail? ;-) As for your actual content... I will have to meditate deeply on this to comprehend if/why it's helpful here. (As with all good ideas!)
On Wed, Dec 17, 2008 at 12:13 AM, Ryan Ingram
wrote: In the last "episode" you talk about an entity's update being a function like:
input_state -> (output_state, [event])
for some suitably defined types of input state, output state, and event.
Connecting together functions with types like this is exactly what Reactive does well. You have an event stream representing the behavior of the user during the course of the game, and you use that to construct other values representing the *behavior* of the game. The key difference is that instead of the game's behavior being a set of functions from input to output, it is functions from one behavior to another, eventually culminating in something like
-- "user input", "clock tick"; output a new display list at each clock tick game :: Event UserInput -> Event () -> Reactive [RenderCommand]
In fact, I think your analysis in the first message is somewhat right on; this exercise is somewhat like "writing a novel without using the letter 'e'". The benefits you get from a pure language are not necessarily "lack of effects", but rather, "explicitly mentioning where effects happen".
That said, I'm curious where you are going with it. I'd love to see the game running & take a look at your code!
-- ryan
participants (4)
-
Andrew Coppin
-
Brandon S. Allbery KF8NH
-
Henrik Nilsson
-
Ryan Ingram