[reactive] First draft of reactive-tetris

Thomas Davie tom.davie at gmail.com
Tue Nov 18 03:30:50 EST 2008


On 17 Nov 2008, at 21:53, Creighton Hogg wrote:

> Hey Reactive,
> Since I have no hosting space I'm actually going to include the  
> implementation as an attachment all in one file.  It's not very long  
> anyway, so it should be alright.
>
> A few caveats:
>
> This code is still _really_ ugly, but it does work as far as I've  
> tested
> There is no game over, you need to quit manually
> There is no score or level adjustment yet.  I need to add that when  
> I have more time, i.e. after this week
>
> That being said, my first real reactive program was surprisingly  
> simple once I got comfortable with the semantics.  The actual  
> reactive code isn't that complicated, but it did take a pretty big  
> shift in thinking from writing explicit game loops.
>
> I've included a good bit of comments so it hopefully it isn't too  
> hard to follow, but if there are any questions about why I did  
> something a particular way (the answer may be 'I'm dumb') please e- 
> mail me or find me on #haskell.

Wow, that's rather nice, unfortunately I can't run it at the moment,  
because I've run into the GLUT problems so many people have.  I'm  
wondering though about your definition of randomBehavior.

randomBehavior :: (Random a) => Double -> Behavior a
randomBehavior s = fmap (fst . random . mkStdGen . round . (+s)) time

I don't know the theory behind pseudo random number generators well  
enough to be sure, but I have a feeling that while this may be good  
enough for a game, it's probably not good enough for anything the  
relies on the numbers it generates being totally unpredictable.  The  
reason I say that is that as far as I understand it, the guarentee  
we're given with a pseudo random number generator is that given an  
output number, the next output number is impossible to predict.  I  
don't think we're given any guarantee that given a monotonically  
increasing seed, the output of the generator will look particularly  
different, or be unpredictable.

Unfortunately, I don't think that I can come up with a better way to  
define the behavior though.  It would be possible to define an Event  
at a certain interval that splits the random seed at each occurrence,  
but I can't do better than that.

Bob


More information about the Reactive mailing list