data Memo a = Memo
{ mauto :: a
, mdest :: [Int]
, mfree :: Bool
}
-- | Step in simulation
v'
where
v { nodes = nodes' }
-- fold go with future memo
(memo',nodes') = bimap intmap intmap $ IntMap.foldrWithKey go mempty $ nodes v
where
IntMap.fromDistinctAscList . zip [0..]
-- simulate atom and apply f
(m : ms , a' : as)
where
-- memoization for this node
Memo
{ mauto = w
, mdest = dest
, mfree = free
}
f (adjacents v i) a
-- new atom
n -- move in
| d : _ <- dest , mfree (memo' IntMap.! d) = void -- move out
| otherwise = w
-- move in
Map.elems $ Map.filterWithKey (\dir c -> move c == Just (opposite dir)) ns
Map.fromList $ (,) <*> (node v . flip (shift v 1) i) <$> total
-- chain of destinations
d : mdest (memo' IntMap.! d)
| otherwise = []
-- is this node free?
False
| length ins > 1 = False -- stall
| Just (_,d) <- floyd $ i : dest = False -- i == d -- floyd $ cycle [0,1] => Just (2,1) , so (i /= d) when reciprocal
| otherwise = all (mfree . (memo' IntMap.!)) $ take 1 dest -- dest is free
-- come = catMaybes $ f <$> total
-- where
-- f dir
-- | n <- node v $ shift v 1 dir i , Just d <- move n , dir == opposite d = Just n
-- | otherwise = Nothing