From de8052cef8a9f749cdb2312a4f5ae5f5a44cf1b8 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 6 Oct 2019 12:50:29 -0400 Subject: Allow eating edible items Add menu support to the prompt system, and an "Eat" command that prompts for an item to eat and eats the item the character specifies, restoring an amount of hitpoints configurable via the item raw type. --- src/Xanthous/Util.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Xanthous/Util.hs') diff --git a/src/Xanthous/Util.hs b/src/Xanthous/Util.hs index d90cf5b03d3d..3a7c10ace18e 100644 --- a/src/Xanthous/Util.hs +++ b/src/Xanthous/Util.hs @@ -24,6 +24,7 @@ module Xanthous.Util , uniq -- ** Bag sequence algorithms , takeWhileInclusive + , smallestNotIn ) where import Xanthous.Prelude hiding (foldr) @@ -194,3 +195,12 @@ uniq = uniqOf folded takeWhileInclusive :: (a -> Bool) -> [a] -> [a] takeWhileInclusive _ [] = [] takeWhileInclusive p (x:xs) = x : if p x then takeWhileInclusive p xs else [] + +-- | Returns the smallest value not in a list +smallestNotIn :: (Ord a, Bounded a, Enum a) => [a] -> a +smallestNotIn xs = case uniq $ sort xs of + [] -> minBound + xs'@(x : _) + | x > minBound -> minBound + | otherwise + -> snd . headEx . filter (uncurry (/=)) $ zip (xs' ++ [minBound]) [minBound..] -- cgit 1.4.1