所有延续教程我能看到的是在固定长度的延长体(即数据结构具有已知的一些项目,因为它正在走过情结延续
我实现深度优先搜索Negamax(HTTP:// EN .wikipedia.org /维基/ Negamax),并在代码的工作,我想使用continuation
重写代码我的代码如下所示
let naiveDFS driver depth game side =
List.map (fun x ->
//- negamax depth-1 childnode opposite side
(x, -(snd (driver (depth-1) (update game x) -side))))
(game.AvailableMoves.Force())
|> List.maxBy snd
let onPlay game = match game.Turn with
| Black -> -1
| White -> 1
///naive depth first search using depth limiter
let DepthFirstSearch (depth:int) (eval:Evaluator<_>) (game:GameState) : (Move * Score) =
let myTurn = onPlay game
let rec searcher depth game side =
match depth with
//terminal Node
| x when x = 0 || (isTerminal game) -> let movescore = (eval ((),game)) |> fst
(((-1,-1),(-1,-1)),(movescore * side))
//the max of the child moves, each child move gets mapped to
//it's associated score
| _ -> naiveDFS searcher depth game side
其中更新来更新游戏状态有带一个给定的移动,eval评估游戏状态和r会产生一个增量值(当前未使用)用于增量评估,isTerminal会评估该位置是否为结束位置。
问题是我必须注册未知数量的动作(每个剩余的list.map迭代)才能继续,而实际上我无法想象这样做的有效方式。
因为这是一个指数算法,我显然希望保持这种尽可能高效(虽然我的大脑好痛试图弄清楚这是我们的,所以我想要的答案不是一个有效率的多)
谢谢