我必须在Haskell中实现蒙特卡罗树搜索。我定义了这样的数据类型:
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
我还使用随机数生成器实现了一个Zipper(我听说我需要一个):
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)
我的问题是如何实现此MCTS的扩展功能。因为是懒惰的评价我也认为我可以生成整棵树。在我看来,该功能应如下所示:
expand :: (s -> [(a, s)]) -- The generator
-> s -- first state
-> Tree s a -- The result tree
expand gen t =