Move toward diagnosing state update leak

This commit is contained in:
2021-08-18 11:53:14 +02:00
parent cfb27d4a76
commit a6f08aef16
9 changed files with 81 additions and 91 deletions
+16 -21
View File
@@ -15,6 +15,7 @@ import qualified Data.IntMap.Strict as IM
import System.Random
import Control.Lens
import Control.Monad.Reader
import Data.Monoid
composeInternalAIs
:: [World -> Creature -> Creature]
@@ -25,36 +26,30 @@ composeInternalAIs fs w c = foldr ($ w) c fs
impulsiveAIR
:: (Creature -> Reader World Creature)
-> World
-> (World -> World, StdGen)
-> Creature
-> ((World -> World, StdGen) , Maybe Creature)
impulsiveAIR impf w (f,g) = followImpulses w (f,g') . ($ w) . runReader . impf
where
(g',_) = split g
-> World
-> (Endo World , Maybe Creature)
impulsiveAIR impf cr w = followImpulses w . ($ w) . runReader $ impf cr
impulsiveAI
:: (World -> Creature -> Creature) -- ^ Internal AI update, should determine impulses
-> World
-> (World -> World,StdGen)
-> Creature
-> ((World -> World,StdGen), Maybe Creature)
impulsiveAI impF w (f,g) = followImpulses w (f,g) . impF w
--impulsiveAI
-- :: (World -> Creature -> Creature) -- ^ Internal AI update, should determine impulses
-- -> World
-- -> (World -> World,StdGen)
-- -> Creature
-- -> ((World -> World,StdGen), Maybe Creature)
--impulsiveAI impF w (f,g) = followImpulses w (f,g) . impF w
-- needs cleanup
followImpulses
:: World
-> (World -> World,StdGen)
-> Creature
-> ((World -> World,StdGen), Maybe Creature)
followImpulses w (f,g) cr
= (\(f''' ,cr') -> ((f''',g'),Just cr'))
-> (Endo World, Maybe Creature)
followImpulses w cr
= (\(f''' ,cr') -> (Endo f''',Just cr'))
$ foldr
(\imp (f' , cr') -> let (f'', cr'') = followImpulse cr' w imp in (f'' . f', cr''))
(f, cr)
(\imp (f , cr') -> let (f'', cr'') = followImpulse cr' w imp in (f'' . f , cr''))
(id, cr)
(_crImpulse $ _crActionPlan cr)
where
g' = snd $ genWord8 g
followImpulse
:: Creature