ghc-dup: e597980331e9b01ce2eb333006ccf8bbc4afcc7d
1: import Game
2:
3: import Data.List
4: import Data.Function
5:
6: data GameTree = Node State [(Int, GameTree)] deriving (Show)
7:
8: allgames :: Player -> GameTree
9: allgames player =
10: genTree (initialState player)
11:
12: genTree :: State -> GameTree
13: genTree s = Node s [ (m, genTree s) | m <- [1..6], Just s <- return (applyMove s m)]
14:
15: value :: State -> Int
16: value s = getScore PlayerA s - getScore PlayerB s
17:
18: miniMax :: Int -> GameTree -> Int
19: miniMax 0 (Node s _) = value s
20: miniMax _ (Node s []) = value s
21: miniMax n (Node s ts) = select [ miniMax (n-1) t | (m,t) <- ts ]
22: where select = if getPlayer s == PlayerA then maximum else minimum
23:
24: decide :: Int -> GameTree -> Int
25: decide n (Node s ts) = fst $ select (compare `on` snd) [ (m, - (miniMax n t)) | (m,t) <- ts ]
26: where select = if getPlayer s == PlayerA then maximumBy else minimumBy
27:
28: main = do
29: simulateGame2 (\s -> decide 7 (genTree s))
Generated by git2html.