As usual with my graphical stuff, you'll need the legacy (1.2) versions of SDL to compile this. And the font path may vary; adjust it for your system.
Showing posts with label games. Show all posts
Showing posts with label games. Show all posts
Tuesday, June 18, 2019
2048
It's been a while without any new posts here; I've been focused on projects where JavaScript or C are more suitable than Haskell (for me, anyway). But I did dust off GHC this weekend to write this no-frills clone of Gabriele Cirulli's popular '2048' puzzle game. It didn't come out quite as concise as I had hoped - maybe I'm a bit rusty? :)
Sunday, August 10, 2014
nibbles
Remember this game? It came bundled with QBasic, back in the good old MS-DOS days...
The game's many subsequent clones often called it Snake instead.
Tuesday, July 31, 2012
dart outs
For those who like to play X01 Games.
Update: with an unexpected application to Project Euler #109!
Update: with an unexpected application to Project Euler #109!
import Control.Applicative (liftA2)
import Data.List (sort, nub, sortBy, maximum)
import Data.Ord (comparing)
import System.Environment (getArgs)
data Dart n = Single n | Double n | Triple n | Bull | None deriving Show
main = mapM_ print . out . read . head =<< getArgs
out n = check . sort' . map (map dart) $ sortBy (comparing maximum) sums
where
check ns = if null ns then [None] else head ns
sort' = sortBy (comparing $ sum . map ease)
sums = nub $ filter ((== n) . sum) combos
---------------------------------------------------------------------------
combos = concat $ zipWith combosOf [1..3] $ repeat segments
segments = concat $ replicate 3 $ sort $ 50 : liftA2 (*) [1..3] [1..20]
dart n
| n == 50 = Bull
| n `elem` s = Single n
| n `elem` d = Double (n `div` 2)
| n `elem` t = Triple (n `div` 3)
where
[s,d,t] = liftA2 (map . (*)) [1..3] [[1..20]]
ease (Single _) = 1
ease (Bull) = 2
ease (Double _) = 3
ease (Triple _) = 4
combosOf 0 _ = [[]]
combosOf _ [] = []
combosOf k (x:xs) = map (x:) (combosOf (k-1) xs) ++ combosOf k xs
Subscribe to:
Posts (Atom)