module Hs2048.Tile
( Tile
, empty
, parse
, rank
, render
, score
) where
type Tile = Maybe Int
empty :: Tile
empty :: Tile
empty = Tile
forall a. Maybe a
Nothing
parse :: String -> Tile
parse :: String -> Tile
parse String
"-" = Tile
forall a. Maybe a
Nothing
parse String
s = Int -> Tile
forall a. a -> Maybe a
Just (String -> Int
forall a. Read a => String -> a
read String
s)
rank :: Tile -> Int
rank :: Tile -> Int
rank Tile
Nothing = Int
0
rank (Just Int
n) = Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (Double -> Double -> Double
forall a. Floating a => a -> a -> a
logBase Double
b Double
n')
where
b :: Double
b = Double
2 :: Double
n' :: Double
n' = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
render :: Tile -> String
render :: Tile -> String
render Tile
Nothing = String
"-"
render (Just Int
n) = Int -> String
forall a. Show a => a -> String
show Int
n
score :: Tile -> Int
score :: Tile -> Int
score Tile
Nothing = Int
0
score t :: Tile
t@(Just Int
n) = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Tile -> Int
rank Tile
t Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)