packages feed

ansi-terminal-game 1.4.0.0 → 1.5.0.0

raw patch · 6 files changed

+58/−29 lines, 6 filesdep ~randomdep ~timers-tickPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: random, timers-tick

API changes (from Hackage documentation)

- Terminal.Game: class () => Random a
- Terminal.Game: creaStaticAnimation :: Plane -> Animation
- Terminal.Game: getFrames :: Timed a -> [(Integer, a)]
- Terminal.Game: getRandomList :: Random a => (a, a) -> StdGen -> [a]
+ Terminal.Game: class UniformRange a
+ Terminal.Game: pickRandom :: [a] -> StdGen -> (a, StdGen)
- Terminal.Game: data () => Color
+ Terminal.Game: data Color
- Terminal.Game: data () => ColorIntensity
+ Terminal.Game: data ColorIntensity
- Terminal.Game: data () => Hyphenator
+ Terminal.Game: data Hyphenator
- Terminal.Game: data () => StdGen
+ Terminal.Game: data StdGen
- Terminal.Game: data () => Timed a
+ Terminal.Game: data Timed a
- Terminal.Game: getRandom :: Random a => (a, a) -> StdGen -> (a, StdGen)
+ Terminal.Game: getRandom :: UniformRange a => (a, a) -> StdGen -> (a, StdGen)

Files

CHANGES view
@@ -1,3 +1,20 @@+1.5.0.0+-------++- `timers-tick` has released a new version: all timers function (creaTimer,+  creaBoolTimer, creaTimerLoop, creaBoolTimerLoop, creaAnimation,+  creaLoopAnimation, ticks) are slightly more robust now (will `error`+  on nonsenical arguments, e.g. frame duration <1).+  This should not impact any of your current projects, it just makes+  catching bugs easier.+- Removed `getFrames` from Animation interface.+- Updated `Random` interface to fit the new `random`. This is a breaking+  change but it should be easy to fix by updating your `Random` constraints+  to `UniformRange`+- Removed `getRandomList` from Random interface.+- Added `pickRandom` to Random interface.+- Removed unuseful `creaStaticAnimation` from Animation interface.+ 1.4.0.0 ------- 
ansi-terminal-game.cabal view
@@ -1,5 +1,5 @@ name:                ansi-terminal-game-version:             1.4.0.0+version:             1.5.0.0 synopsis:            sdl-like functions for terminal applications, based on                      ansi-terminal description:         Library which aims to replicate standard 2d game@@ -59,11 +59,11 @@                        mintty == 0.1.*,                        mtl == 2.2.*,                        QuickCheck >= 2.13 && < 2.15,-                       random >= 1.1 && < 1.3,+                       random >= 1.2 && < 1.3,                        split == 0.2.*,                        terminal-size == 0.3.*,                        unidecode >= 0.1.0 && < 0.2,-                       timers-tick > 0.4.2 && < 0.5+                       timers-tick > 0.5 && < 0.6   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall@@ -95,7 +95,8 @@                        Terminal.Game.Utils,                        Terminal.Game.Plane,                        Terminal.Game.PlaneSpec-                       Terminal.Game.Random+                       Terminal.Game.Random,+                       Terminal.Game.RandomSpec   build-depends:       base == 4.*,                        ansi-terminal == 0.11.*,                        array == 0.5.*,@@ -106,11 +107,11 @@                        linebreak == 1.1.*,                        mtl == 2.2.*,                        QuickCheck >= 2.13 && < 2.15,-                       random >= 1.1 && < 1.3,+                       random >= 1.2 && < 1.3,                        split == 0.2.*,                        terminal-size == 0.3.*,                        unidecode >= 0.1.0 && < 0.2,-                       timers-tick > 0.4.2 && < 0.5+                       timers-tick > 0.5 && < 0.6                        -- the above plus hspec                        , hspec   type:                exitcode-stdio-1.0
src/Terminal/Game.hs view
@@ -39,6 +39,7 @@ -- todo (da sm) hot reload for game (see IHP web app) [suggestion] -- todo (da sm) sound with sox -- todo (da sm) add tick counter+-- todo eccezioni con maybe o lanciando l’eccezione?   module Terminal.Game ( -- * Running@@ -66,17 +67,16 @@                        Animation,                        creaAnimation,                        creaLoopAnimation,-                       creaStaticAnimation,                         -- *** T/A interface                        tick, ticks, reset, lapse,-                       fetchFrame, isExpired, getFrames,+                       fetchFrame, isExpired,                         -- ** Random numbers                        StdGen,                        getStdGen, mkStdGen,-                       getRandom, getRandomList,-                       Random,+                       getRandom, pickRandom,+                       UniformRange,                         -- * Drawing                        -- | To get to the gist of drawing, check the
src/Terminal/Game/Animation.hs view
@@ -31,8 +31,3 @@ -- | Creates a looped 'Animation'. creaLoopAnimation :: [(Integer, Plane)] -> Animation creaLoopAnimation ips = creaTimedRes AlwaysLoop ips---- | Wraps a 'Plane' into an 'Animation'.-creaStaticAnimation :: Plane -> Animation-creaStaticAnimation p = creaTimedRes (Times 1 Elapse) [(1, p)]-
src/Terminal/Game/Random.hs view
@@ -1,24 +1,20 @@ module Terminal.Game.Random ( R.StdGen,-                              Random,+                              R.UniformRange,                               R.getStdGen,                               R.mkStdGen,                               getRandom,-                              getRandomList )+                              pickRandom )             where  import System.Random as R  --- getRandom :: (Ord a, Show a) => (a, a) -> StdGen -> (a, StdGen)--- getRandom bs@(l, h) sg---         | l > h     = error $ "getRandom: lowBound > highBoud, " ++ show bs---         | otherwise = randomR _ _---- | Simple pseudo-random generator.-getRandom :: Random a => (a, a) -> StdGen -> (a, StdGen)-getRandom bs sg = randomR bs sg---- | Returns an infinite list of random values.-getRandomList :: Random a => (a, a) -> StdGen -> [a]-getRandomList bs sg = randomRs bs sg+-- | Simple, pure pseudo-random generator.+getRandom :: UniformRange a => (a, a) -> StdGen -> (a, StdGen)+getRandom bs sg = uniformR bs sg +-- | Picks at random from list.+pickRandom :: [a] -> StdGen -> (a, StdGen)+pickRandom as sg = let l = length as+                       (a, sg') = getRandom (0, l-1) sg+                   in (as !! a, sg')
+ test/Terminal/Game/RandomSpec.hs view
@@ -0,0 +1,20 @@+module Terminal.Game.RandomSpec where++import Test.Hspec+import Test.Hspec.QuickCheck+import Terminal.Game.Random+++spec :: Spec+spec = do++  describe "pickRandom" $ do+    prop "picks items at random from a list" $+      \i -> let g = mkStdGen i+            in fst (pickRandom ['a', 'b'] g) /= 'c'+    prop "does not exclude any item" $+      \i -> let g = mkStdGen i+                rf tg = pickRandom [1,2] tg+                rs = iterate (\(_, lg') -> rf lg')  (rf g)+                ts = take 100 rs+            in sum (map fst ts) /= length ts