-- -- Generate decent inform messages from smells, evidence and robbed banks -- module CopInform where import Logging import CR import Syntax import KnowledgeBase import Graph import Utils import Data.List import Data.Maybe import Debug.Trace informMessage = do kb <- getKB let g = kb_footMap kb -- robber is on foot w = kb_worldCount kb -- current world here = kb_ownLoc kb msmell = kb_smell kb evidents = kb_evidences kb robbed = kb_robbedbanks kb -- build a single inform message let mkInf (cnode,cert) = Inform (kb_robberName kb) (locOfNode cnode) Robber (w) -- where he is now cert -- information from robbed banks let robcerts_raw = map (\(Bank n _ (Just t)) -> nodesAndCertainty g n (truncate (fromIntegral (w - t) / 2.0)) ) robbed let robcerts = flatten robcerts_raw -- information from smells that we have right now! let smellcerts = flatten $ case msmell of Nothing -> [] Just (Smell s) -> map (\ (_,h) -> nodesAndCertainty g h 2{- assume -}) here -- information from evidences let evcerts = flatten $ map (\(KBEvidence n t) -> nodesAndCertainty g n (truncate (fromIntegral (w-t)/2.0)) ) evidents -- a set of nodes we think the robber is in, based on bank robberies let robinfos = map mkInf robcerts smellinfos = map mkInf smellcerts evinfos = map mkInf evcerts return $ InformMsg (robinfos ++ smellinfos ++ evinfos) flatten :: [Maybe ([GNode],Certainty)] -> [(GNode,Certainty)] flatten [] = [] flatten (Nothing:rest) = flatten rest flatten (Just (gs,c):rest) = let x = zip gs (repeat c) in x `seq` x ++ flatten rest ------------------------------------------------------------------------ -- -- Calculates nodes the robber could be in the certainties associated -- with it. -- -- 1. For a smell provide the distance to the smell and *your* location -- 2. For a bank robbery provide the time since the bank robbery and *its* -- location -- 3. For evidence provide the difference between current time and its time -- and *its* location -- -- nodesAndCertainty :: Graph -> GNode -> Int -> Maybe ([GNode], Certainty) nodesAndCertainty graph node dist | dist <= maxCertaintyDist = Just (nodesWithin graph node dist, scale (maxCertainty - certaintyFactor *dist)) | otherwise = Nothing scale n | n < minCertainty = minCertainty | n > maxCertainty = maxCertainty | otherwise = n maxCertaintyDist = 10 maxCertainty = 100 minCertainty = (-100) certaintyFactor = (maxCertainty - minCertainty) `div` maxCertaintyDist {- -- constant informMessage = do kb <- getKB return $ InformMsg [Inform (kb_robberName kb) (locOfNode $ kb_robberStart kb) Robber (kb_worldCount kb) (50) ] -}