Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buildTree:: Board->Color->Tree Board
- buildTree board color = Node board (Prelude.map (\board -> (buildTree board oppositeColor)) possibleBoards)
- where
- getListOfBoards _ _ [] = []
- getListOfBoards (Board b) color (x:xs) =[addToBoard (Board b) x color] ++ (getListOfBoards (Board b) color xs)
- oppositeColor = (negateColor color)
- possibleCoordinates = possibleMoves board
- possibleBoards = getListOfBoards board color possibleCoordinates
- minmaxAlfa:: [Tree Board]->Color->Int->Int->Int->Int->Int
- minmaxAlfa [] color level maxLevel alfa beta = alfa
- minmaxAlfa (x:xs) color level maxLevel alfa beta
- | (newAlfa>=beta) = beta
- | otherwise = minmaxAlfa xs color level maxLevel newAlfa beta
- where
- newAlfa = max alfa (exploreTree x color level maxLevel alfa beta)
- minmaxBeta:: [Tree Board]->Color->Int->Int->Int->Int->Int
- minmaxBeta [] color level maxLevel alfa beta = beta
- minmaxBeta (x:xs) color level maxLevel alfa beta
- | (alfa >= newBeta) = alfa
- | otherwise = minmaxBeta xs color level maxLevel alfa newBeta
- where
- newBeta = min beta (exploreTree x color level maxLevel alfa beta)
- exploreTree:: Tree Board->Color->Int->Int->Int->Int->Int
- exploreTree (Node node children) color level maxLevel alfa beta
- | Prelude.null children = rateBoard node color
- | level==maxLevel = minimum (rateBoards children color)
- | level `mod` 2 == 0 = minmaxAlfa children color (level+1) maxLevel alfa beta
- | otherwise = minmaxBeta children color (level+1) maxLevel alfa beta
- minmax:: Tree Board->Color->Int->Int
- 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