Implement more general tree composition

This commit is contained in:
2022-06-11 17:07:58 +01:00
parent de71c61409
commit 6cd1d6c130
3 changed files with 39 additions and 12 deletions
+3 -3
View File
@@ -36,7 +36,7 @@ import RandomHelp
--import qualified Data.IntMap.Strict as IM --import qualified Data.IntMap.Strict as IM
initialAnoTree :: Tree [Annotation] initialAnoTree :: Tree [Annotation]
initialAnoTree = padSucWithDoors $ treeFromPost initialAnoTree = padSucWithDoors $ treePost
[[AnoApplyInt 110 startRoom] [[AnoApplyInt 110 startRoom]
, [PassthroughLockKeyLists 2 keyCardRunPastRand itemRooms] , [PassthroughLockKeyLists 2 keyCardRunPastRand itemRooms]
, [SpecificRoom $ warningRooms 777777] , [SpecificRoom $ warningRooms 777777]
@@ -94,8 +94,8 @@ initialAnoTree = padSucWithDoors $ treeFromPost
-- ,[TreasureAno [addArmour autoCrit,addArmour autoCrit] [launcher]] -- ,[TreasureAno [addArmour autoCrit,addArmour autoCrit] [launcher]]
-- ,[Corridor] -- ,[Corridor]
,[SpecificRoom $ randomFourCornerRoom [] >>= rToOnward "randomFourCornerRoom" . pure . cleatOnward ] ,[SpecificRoom $ randomFourCornerRoom [] >>= rToOnward "randomFourCornerRoom" . pure . cleatOnward ]
] ,[SpecificRoom $ telRoomLev 1 >>= rToOnward "telRoomLev" . pure . cleatOnward]
[SpecificRoom $ telRoomLev 1 >>= rToOnward "telRoomLev" . pure . cleatOnward] ]
{- | A test level tree. -} {- | A test level tree. -}
initialRoomTree :: State StdGen (Tree (Room -> Maybe ([String],Room), Tree Room)) initialRoomTree :: State StdGen (Tree (Room -> Maybe ([String],Room), Tree Room))
+25 -1
View File
@@ -15,10 +15,11 @@ module Dodge.Tree.Compose
, shiftChildren , shiftChildren
, attachTree , attachTree
, composeTreeRand , composeTreeRand
, composeAndLog
-- , compTree -- , compTree
) where ) where
import Dodge.Data import Dodge.Data
--import Dodge.Tree.Compose.Data import Dodge.Tree.Compose.Data
--import Dodge.RoomCluster.Data --import Dodge.RoomCluster.Data
import TreeHelp import TreeHelp
--import Dodge.Base --import Dodge.Base
@@ -156,3 +157,26 @@ shiftChildren (Node (ts,x) ts') = Node x (ts ++ map shiftChildren ts')
--attachChildren t = moveToChildren . foldr mAttachToNode t' --attachChildren t = moveToChildren . foldr mAttachToNode t'
-- where -- where
-- t' = fmap (\(x,y) -> (x,y,[])) t -- t' = fmap (\(x,y) -> (x,y,[])) t
logMB :: MetaBranch a -> Tree String
logMB (MBranch str _ mt) = root ++.~ (str ++ ":") $ logMT mt
logMT :: MetaTree a -> Tree String
logMT mt = case mt of
MTree str _ branches -> Node ("M:"++str) $ map logMB branches
BTree str _ branches -> Node str $ map logMT branches
composeAndSubLog :: MetaTree a -> IO (Tree a)
composeAndSubLog mt = case mt of
mt@MTree{} -> composeAndLog mt
bt -> do
branches <- mapM composeAndSubLog $ _btBranches bt
return $ Node (_btValue bt) branches
composeAndLog :: MetaTree a -> IO (Tree a)
composeAndLog mt = case mt of
mt@MTree{} -> do
putStrLn $ drawTree $ logMT mt
rt <- composeAndLog $ _mtTree mt
branches <- mapM (\mb -> (_mbAttach mb,) <$> composeAndSubLog (_mbTree mb)) $ _mtBranches mt
return $ attachList rt $ map pure branches
+11 -8
View File
@@ -3,19 +3,22 @@
module Dodge.Tree.Compose.Data where module Dodge.Tree.Compose.Data where
import Data.Tree import Data.Tree
import Control.Lens import Control.Lens
data ComposingNode a
= SplitDown {_unCompose :: a} data MetaBranch a
-- | useAll {_unCompose :: a} = MBranch {_mbLabel :: String, _mbAttach :: a -> Maybe a, _mbTree :: MetaTree a}
| UseSome {_composeIndices :: [Int], _unCompose :: a}
| UseNone {_unCompose :: a} data MetaTree a
-- | useLabel {_composeIndex :: Int, _unCompose :: a} -- defaults to using no children = MTree {_mtLabel :: String , _mtTree :: MetaTree a , _mtBranches :: [MetaBranch a] }
type CompTree a = Tree (Tree a) | BTree {_btLabel :: String , _btValue :: a , _btBranches :: [MetaTree a] }
--type CompTree a = Tree (Tree a)
type LabTree a = (a -> Maybe ([String],a),Tree a) type LabTree a = (a -> Maybe ([String],a),Tree a)
type LabCompTree a = Tree (LabTree a) type LabCompTree a = Tree (LabTree a)
data TreeSubLabelling = TreeSubLabelling data TreeSubLabelling = TreeSubLabelling
{ _topLabel :: String { _topLabel :: String
, _subLabels :: Maybe (Tree TreeSubLabelling) , _subLabels :: Maybe (Tree TreeSubLabelling)
} }
makeLenses ''ComposingNode
makeLenses ''TreeSubLabelling makeLenses ''TreeSubLabelling
makeLenses ''MetaTree
makeLenses ''MetaBranch