2014-09-24 3 views
1

과제를 위해 Gametree에 Minimax 함수를 써야합니다 (보드 트리 보드, 로즈 보드)와 그것을 돌리는 플레이어입니다. 그러나 입력 '|'구문 분석 오류에 대한이 오류가 나타납니다. 나는 조건 곳에 문을 중첩하지만 난이 제대로 있는지 확실하지 않습니다 또는이도 가능한 경우 (또는 다른 방식으로 수행해야합니다) 아마 때문에 누군가가 나를 도울 수 있다면haskell minimax/nested conditions and 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

답변

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