From cf4bda4d1c9a5e3e57c0b2682c7647d811a31740 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 12 Nov 2016 15:11:59 +0100 Subject: probabilistic focus --- src/Main.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 3b7b3f5..54ec08a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -53,6 +53,8 @@ import Sequence.Contact.Tests import Sequence.Utils import Sequence.Formula +import Numeric.Probability.Game.Event (EventM, makeEventProb, enact) + import Text.Layout.Table import Text.Read (readMaybe) @@ -82,6 +84,7 @@ main = do , helpCommand "help" , cmd "entities" listEntities "List all entities" , cmd "tip" focusTip "Focus the entity at the top of the queue" + , cmd "ptip" pFocusTip "Focus a random entity" , cmd "focus" setFocus "Focus a specific entity" , cmd "blur" blur "Focus no entity" , cmd "remove" remove "Remove the focused entity from the queue" @@ -213,9 +216,21 @@ listFactions = use inhabitedFactions >>= mapM_ (shellPutStrLn . view faction') listEntities = use (gEntities . to Map.keys) >>= mapM_ (shellPutStrLn <=< toName) -- Automatic focus -focusTip, blur :: Sh GameState () +focusTip, blur, pFocusTip :: Sh GameState () focusTip = gFocus <~ preuse tip blur = gFocus .= Nothing +pFocusTip = do + round <- use gRound + let + eWeight :: Maybe SeqVal -> Int + eWeight sVal + | preview (_Just . seqRound . _Wrapped) sVal == Just round + , (preview (_Just . seqVal . _Just) -> Just n) <- sVal = n + | otherwise = 0 + entities <- map (over _2 . view $ eSeqVal . to eWeight) . Map.toList <$> use gEntities + case entities of + [] -> gFocus .= Nothing + _ -> gFocus <~ Just <$> liftIO (enact $ makeEventProb entities) -- Manual focus setFocus :: Completable EntityIdentifier -> Sh GameState () -- cgit v1.2.3