对于一个任务,我需要写一个Minimax函数在一个游戏树提供给这个函数(作为一个树的董事会,玫瑰板)和一个球员谁是。但是,我得到了这个关于输入‘\\’的解析错误的错误。可能是因为我嵌套了条件和where语句,但我不确定是否正确地做到了这一点,或者这是否可能(或者应该以不同的方式完成):
minimax :: Player -> Rose Board -> Rose Int --Rose Int = Int :> [Rose Ints]
minimax p rb = minimax' rb p
where minimax' (b :> [rbs]) p0 | null rbs = result
where result | p0 == p = 1
| otherwise = -1
| otherwise = 0 :> (minimax' rbs (nextPlayer p0))如果有人能帮我,这是非常感谢的!
向你问好,天夫。
发布于 2014-09-24 12:47:39
解决这个问题的最简单的方法可能是使用let而不是where。
minimax :: Player -> Rose Board -> Rose Int --Rose Int = Int :> [Rose Ints]
minimax p rb = minimax' rb p
where minimax' (b :> [rbs]) p0 | null rbs = let result | p0 == p = 1
| otherwise = -1
in result
| otherwise = 0 :> (minimax' rbs (nextPlayer p0))但是您也可以使用一个条件表达式:
minimax :: Player -> Rose Board -> Rose Int --Rose Int = Int :> [Rose Ints]
minimax p rb = minimax' rb p
where minimax' (b :> [rbs]) p0 | null rbs = if p0 == p then 1 else -1
| otherwise = 0 :> (minimax' rbs (nextPlayer p0))https://stackoverflow.com/questions/26016766
复制相似问题