Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da217b5196 |
@@ -6,3 +6,4 @@
|
|||||||
*.hi
|
*.hi
|
||||||
*.o
|
*.o
|
||||||
*.prof
|
*.prof
|
||||||
|
*.hp
|
||||||
|
|||||||
+6
-3
@@ -7,6 +7,8 @@ module AI.Rulebased (
|
|||||||
mkAIEnv, testds, simplify
|
mkAIEnv, testds, simplify
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Parallel.Strategies
|
||||||
|
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.List
|
import Data.List
|
||||||
@@ -163,6 +165,7 @@ compareGuess (c1, ops1) (c2, ops2)
|
|||||||
distributions :: Guess -> (Int, Int, Int, Int) -> [Distribution]
|
distributions :: Guess -> (Int, Int, Int, Int) -> [Distribution]
|
||||||
distributions guess nos =
|
distributions guess nos =
|
||||||
helper (sortBy compareGuess $ M.toList guess) nos
|
helper (sortBy compareGuess $ M.toList guess) nos
|
||||||
|
`using` parList rdeepseq
|
||||||
where helper [] _ = []
|
where helper [] _ = []
|
||||||
helper ((c, hs):[]) ns = map fst (distr c hs ns)
|
helper ((c, hs):[]) ns = map fst (distr c hs ns)
|
||||||
helper ((c, hs):gs) ns =
|
helper ((c, hs):gs) ns =
|
||||||
@@ -246,9 +249,9 @@ chooseStatistic = do
|
|||||||
2 -> 2
|
2 -> 2
|
||||||
3 -> 3
|
3 -> 3
|
||||||
-- simulate only partially
|
-- simulate only partially
|
||||||
4 -> 2
|
4 -> 3
|
||||||
5 -> 1
|
5 -> 2
|
||||||
6 -> 1
|
6 -> 2
|
||||||
7 -> 1
|
7 -> 1
|
||||||
8 -> 1
|
8 -> 1
|
||||||
9 -> 1
|
9 -> 1
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module Card where
|
|||||||
import Data.List
|
import Data.List
|
||||||
import System.Random (newStdGen)
|
import System.Random (newStdGen)
|
||||||
import Utils
|
import Utils
|
||||||
|
import Control.DeepSeq
|
||||||
|
|
||||||
class Countable a b where
|
class Countable a b where
|
||||||
count :: a -> b
|
count :: a -> b
|
||||||
@@ -57,6 +58,9 @@ instance Countable Card Int where
|
|||||||
instance Countable [Card] Int where
|
instance Countable [Card] Int where
|
||||||
count = sum . map count
|
count = sum . map count
|
||||||
|
|
||||||
|
instance NFData Card where
|
||||||
|
rnf (Card t c) = t `seq` c `seq` ()
|
||||||
|
|
||||||
equals :: Colour -> Maybe Colour -> Bool
|
equals :: Colour -> Maybe Colour -> Bool
|
||||||
equals col (Just x) = col == x
|
equals col (Just x) = col == x
|
||||||
equals col Nothing = True
|
equals col Nothing = True
|
||||||
|
|||||||
@@ -13,7 +13,23 @@ import AI.Human
|
|||||||
import AI.Rulebased
|
import AI.Rulebased
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn "Hello World"
|
main = testAI 10
|
||||||
|
|
||||||
|
testAI :: Int -> IO ()
|
||||||
|
testAI n = do
|
||||||
|
let acs = repeat runAI
|
||||||
|
vals <- sequence (take n acs)
|
||||||
|
putStrLn $ "average won points " ++ show (fromIntegral (sum vals) / fromIntegral n)
|
||||||
|
|
||||||
|
runAI :: IO Int
|
||||||
|
runAI = do
|
||||||
|
env <- shuffledEnv
|
||||||
|
let ps = piles env
|
||||||
|
cs = handCards Hand3 ps
|
||||||
|
trs = filter (isTrump Spades) cs
|
||||||
|
if length trs >= 5 && any ((==32) . getID) cs
|
||||||
|
then fst <$> evalStateT (turn Hand1) env
|
||||||
|
else runAI
|
||||||
|
|
||||||
env :: SkatEnv
|
env :: SkatEnv
|
||||||
env = SkatEnv piles Nothing Spades playersExamp
|
env = SkatEnv piles Nothing Spades playersExamp
|
||||||
@@ -50,8 +66,3 @@ env2 = SkatEnv piles Nothing Spades playersExamp
|
|||||||
h3 = map (putAt Hand3) hand3
|
h3 = map (putAt Hand3) hand3
|
||||||
piles = Piles (h1 ++ h2 ++ h3) [] []
|
piles = Piles (h1 ++ h2 ++ h3) [] []
|
||||||
|
|
||||||
testAI :: Int -> IO ()
|
|
||||||
testAI n = do
|
|
||||||
let acs = repeat (shuffledEnv >>= evalStateT (turnGeneric playOpen 10 Hand1) )
|
|
||||||
vals <- sequence (take n acs)
|
|
||||||
putStrLn $ "average won points " ++ show (fromIntegral (sum (map fst vals)) / fromIntegral n)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user