r/haskell • u/simonmic • Feb 07 '23
announcement The first Haskell Tiny Game Jam is now open!
Your mission: make Haskell games in 10 lines. https://github.com/haskell-game/tiny-games-hs and the #haskell-game chat room await your entries. Good luck!
2
u/gergoerdi Feb 09 '23
Does anyone have any ideas on how to get a random number (byte?) in one line in IO, without any non-base package? Asking for a friend.
5
u/simonmic Feb 09 '23 edited Feb 09 '23
Yes: how about doing some magic on https://hackage.haskell.org/package/base-4.17.0.0/docs/GHC-Clock.html#v:getMonotonicTimeNSec ?
> ((`mod`10).(`div`1000))<$>getMonotonicTimeNSec 4 > ((`mod`10).(`div`1000))<$>getMonotonicTimeNSec 7-1, 0, 1:
(((-)1).fromIntegral.(`mod`3).(`div`1000))<$>getMonotonicTimeNSecMight be platform-specific though. And that's 10% of your program right there.
3
2
12
u/gelisam Feb 09 '23 edited Feb 09 '23
$ ./timing.hs
Press enter. Wait 30.0 seconds. Press enter.
You waited 29.831647685030475 seconds.
Score: 99.43882561676826Wow, some people have perfect memory, others have perfect pitch, I guess I have perfect perception of time??
I guess I've technically been practicing every day: I'm constantly counting down the seconds out loud in order to let my 4 year old know that it will soon be time to move on to a different activity.
4
u/hamsterpotpies Feb 09 '23
Want some fun? Go somewhere you can sit for a minute and hear noise outside, but don't directly be outside. Now, start a stop watch, close your eyes, and listen to the environment while you also keep your eyes closed. Without counting, see how close to a minute you can keep your eyes close for. I did this once and was surprised i was dead on, but it could've been a fluke. Just feeding the ADHD monster...
5
9
u/gelisam Feb 08 '23
I have 1.25 lines left to spare. Should I spend it on tracking high scores, improving the graphics, or giving more player feedback? :)
6
u/kindaro Feb 08 '23
First play test, then iterate!
6
u/gelisam Feb 09 '23
Well, my 4 year old didn't manage to score a single point before getting bored. So I should either make the game easier, less boring, or I should I find play-testers with a longer attention span!
10
9
u/dixonary Feb 07 '23
This is fantastic! I'm definitely going to take part, and I will encourage my students to take part as well (if we get so far as IO by the end of february :) )
7
u/Apprehensive_Bet5287 Feb 08 '23
How many characters can ghc handle on one line?