diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-11-12 15:11:59 +0100 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-11-12 15:11:59 +0100 |
commit | cf4bda4d1c9a5e3e57c0b2682c7647d811a31740 (patch) | |
tree | 097ec5c1f6ab241310b65c84866d331416feb509 /src | |
parent | 0b448ae4be1718af7221a051e3be55347820ebc3 (diff) | |
download | 2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar 2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.gz 2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.bz2 2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.xz 2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.zip |
probabilistic focus
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 17 |
1 files changed, 16 insertions, 1 deletions
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 | |||
53 | import Sequence.Utils | 53 | import Sequence.Utils |
54 | import Sequence.Formula | 54 | import Sequence.Formula |
55 | 55 | ||
56 | import Numeric.Probability.Game.Event (EventM, makeEventProb, enact) | ||
57 | |||
56 | import Text.Layout.Table | 58 | import Text.Layout.Table |
57 | 59 | ||
58 | import Text.Read (readMaybe) | 60 | import Text.Read (readMaybe) |
@@ -82,6 +84,7 @@ main = do | |||
82 | , helpCommand "help" | 84 | , helpCommand "help" |
83 | , cmd "entities" listEntities "List all entities" | 85 | , cmd "entities" listEntities "List all entities" |
84 | , cmd "tip" focusTip "Focus the entity at the top of the queue" | 86 | , cmd "tip" focusTip "Focus the entity at the top of the queue" |
87 | , cmd "ptip" pFocusTip "Focus a random entity" | ||
85 | , cmd "focus" setFocus "Focus a specific entity" | 88 | , cmd "focus" setFocus "Focus a specific entity" |
86 | , cmd "blur" blur "Focus no entity" | 89 | , cmd "blur" blur "Focus no entity" |
87 | , cmd "remove" remove "Remove the focused entity from the queue" | 90 | , cmd "remove" remove "Remove the focused entity from the queue" |
@@ -213,9 +216,21 @@ listFactions = use inhabitedFactions >>= mapM_ (shellPutStrLn . view faction') | |||
213 | listEntities = use (gEntities . to Map.keys) >>= mapM_ (shellPutStrLn <=< toName) | 216 | listEntities = use (gEntities . to Map.keys) >>= mapM_ (shellPutStrLn <=< toName) |
214 | 217 | ||
215 | -- Automatic focus | 218 | -- Automatic focus |
216 | focusTip, blur :: Sh GameState () | 219 | focusTip, blur, pFocusTip :: Sh GameState () |
217 | focusTip = gFocus <~ preuse tip | 220 | focusTip = gFocus <~ preuse tip |
218 | blur = gFocus .= Nothing | 221 | blur = gFocus .= Nothing |
222 | pFocusTip = do | ||
223 | round <- use gRound | ||
224 | let | ||
225 | eWeight :: Maybe SeqVal -> Int | ||
226 | eWeight sVal | ||
227 | | preview (_Just . seqRound . _Wrapped) sVal == Just round | ||
228 | , (preview (_Just . seqVal . _Just) -> Just n) <- sVal = n | ||
229 | | otherwise = 0 | ||
230 | entities <- map (over _2 . view $ eSeqVal . to eWeight) . Map.toList <$> use gEntities | ||
231 | case entities of | ||
232 | [] -> gFocus .= Nothing | ||
233 | _ -> gFocus <~ Just <$> liftIO (enact $ makeEventProb entities) | ||
219 | 234 | ||
220 | -- Manual focus | 235 | -- Manual focus |
221 | setFocus :: Completable EntityIdentifier -> Sh GameState () | 236 | setFocus :: Completable EntityIdentifier -> Sh GameState () |