Advertisement
Coriic

Untitled

Jun 7th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. buildTree:: Board->Color->Tree Board
  2. buildTree board color = Node board (Prelude.map (\board -> (buildTree board oppositeColor)) possibleBoards)
  3.     where
  4.         getListOfBoards _ _ [] = []
  5.         getListOfBoards (Board b) color (x:xs) =[addToBoard (Board b) x color] ++ (getListOfBoards (Board b) color xs)
  6.         oppositeColor = (negateColor color)
  7.         possibleCoordinates = possibleMoves board
  8.         possibleBoards = getListOfBoards board color possibleCoordinates
  9.  
  10. minmaxAlfa:: [Tree Board]->Color->Int->Int->Int->Int->Int
  11. minmaxAlfa [] color level maxLevel alfa beta = alfa
  12. minmaxAlfa (x:xs) color level maxLevel alfa beta
  13.     | (newAlfa>=beta) = beta
  14.     | otherwise  = minmaxAlfa xs color level maxLevel newAlfa beta
  15.     where
  16.         newAlfa = max alfa (exploreTree x color level maxLevel alfa beta)
  17.  
  18. minmaxBeta:: [Tree Board]->Color->Int->Int->Int->Int->Int
  19. minmaxBeta [] color level maxLevel alfa beta = beta
  20. minmaxBeta (x:xs) color level maxLevel alfa beta
  21.     | (alfa >= newBeta) = alfa
  22.     | otherwise = minmaxBeta xs color level maxLevel alfa newBeta
  23.     where
  24.         newBeta = min beta (exploreTree x color level maxLevel alfa beta)
  25.  
  26. exploreTree:: Tree Board->Color->Int->Int->Int->Int->Int
  27. exploreTree (Node node children) color level maxLevel alfa beta
  28.     | Prelude.null children = rateBoard node color
  29.     | level==maxLevel = minimum (rateBoards children color)
  30.     | level `mod` 2 == 0 = minmaxAlfa children color (level+1) maxLevel alfa beta
  31.     | otherwise = minmaxBeta children color (level+1) maxLevel alfa beta
  32.  
  33. minmax:: Tree Board->Color->Int->Int
  34. minmax (Node node children) color maxLevel = exploreTree (Node node children) color 0 maxLevel (-1000) 1000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement