I have to implement a Monte Carlo Tree Search in Haskell. I defined a data type like this:
data Tree s a = TreeNode {
rGame :: s, -- state
rPlayed :: a, -- action
visit :: Int, -- number of visits
score :: Float,
left :: Tree s a,
right :: Tree s a} | TreeNil deriving Show
I also implemented a Zipper with a random number generator(I heard that I need one):
data Crumb s a = LeftCrumb s a (Tree s a) | RightCrumb s a (Tree s a) deriving Show
type Treecrumbs s a = [Crumb s a]
data Zipper s a = Zipper (Tree s a) (Treecrumbs s a) (StdGen)
My question is how can I implement the expand function for this MCTS. Because is lazy evaluation I also think I can generate the whole tree. In my opinion the function should look like this:
expand :: (s -> [(a, s)]) -- The generator
-> s -- first state
-> Tree s a -- The result tree
expand gen t =