首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >haskell minimax /嵌套条件及其位置

haskell minimax /嵌套条件及其位置
EN

Stack Overflow用户
提问于 2014-09-24 12:20:39
回答 1查看 1.3K关注 0票数 1

对于一个任务,我需要写一个Minimax函数在一个游戏树提供给这个函数(作为一个树的董事会,玫瑰板)和一个球员谁是。但是,我得到了这个关于输入‘\\’的解析错误的错误。可能是因为我嵌套了条件和where语句,但我不确定是否正确地做到了这一点,或者这是否可能(或者应该以不同的方式完成):

代码语言:javascript
运行
复制
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))

如果有人能帮我,这是非常感谢的!

向你问好,天夫。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-24 12:47:39

解决这个问题的最简单的方法可能是使用let而不是where

代码语言:javascript
运行
复制
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))

但是您也可以使用一个条件表达式:

代码语言:javascript
运行
复制
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))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26016766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档