2014-09-24 72 views
1

對於一項任務,我需要在提供給該函數的Gametree(作爲棋盤樹;玫瑰棋盤)和玩家轉身的情況下編寫Minimax函數。但是,我收到有關輸入'|'解析錯誤的錯誤。可能是因爲我嵌套條件並在報表,但我不知道如果我這樣做正確或者如果這甚至有可能(或應該以不同的方式來完成):haskell minimax /嵌套條件和wheres

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)) 

如果有人可以幫助我這是非常感激!

此致敬禮, Skyfe。

+1

你必須移動內部'哪裏在守衛之後。 – Zeta 2014-09-24 13:30:02

回答

1

解決這個問題的最簡單的方法可能是使用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)) 
+0

謝謝!這就像一個魅力。 – user2999349 2014-09-24 14:19:27